This commit is contained in:
Greg Shuflin 2025-02-02 02:11:13 -08:00
parent 47de37d6cb
commit 2250088353
2 changed files with 52 additions and 6 deletions

View File

@ -19,16 +19,25 @@ const addFeedButton = document.getElementById('addFeedButton');
const cancelButton = document.getElementById('cancelAddFeed'); const cancelButton = document.getElementById('cancelAddFeed');
const confirmButton = document.getElementById('confirmAddFeed'); const confirmButton = document.getElementById('confirmAddFeed');
const addFeedForm = document.getElementById('addFeedForm'); const addFeedForm = document.getElementById('addFeedForm');
const errorMessage = document.getElementById('feedErrorMessage');
function showModal() { function showModal() {
modal.classList.add('show'); modal.classList.add('show');
errorMessage.style.display = 'none';
addFeedForm.reset();
} }
function hideModal() { function hideModal() {
modal.classList.remove('show'); modal.classList.remove('show');
errorMessage.style.display = 'none';
addFeedForm.reset(); addFeedForm.reset();
} }
function showError(message) {
errorMessage.textContent = message;
errorMessage.style.display = 'block';
}
addFeedButton.addEventListener('click', showModal); addFeedButton.addEventListener('click', showModal);
cancelButton.addEventListener('click', hideModal); cancelButton.addEventListener('click', hideModal);
@ -40,12 +49,43 @@ modal.addEventListener('click', (e) => {
}); });
confirmButton.addEventListener('click', async () => { confirmButton.addEventListener('click', async () => {
const feedUrl = document.getElementById('feedUrl').value; const name = document.getElementById('feedName').value.trim();
if (!feedUrl) { const url = document.getElementById('feedUrl').value.trim();
if (!name || !url) {
showError('Please fill in all fields');
return; return;
} }
// TODO: Add API endpoint integration here try {
console.log('Feed URL to add:', feedUrl); const response = await fetch('/feeds', {
hideModal(); method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ name, url }),
});
if (response.ok) {
hideModal();
// TODO: Update the feed list in the UI
// For now, we'll just reload the page
window.location.reload();
} else {
const errorText = await response.text();
switch (response.status) {
case 409:
showError('You already have this feed added');
break;
case 422:
showError('Invalid feed URL. Please make sure it starts with http:// or https://');
break;
default:
showError('Failed to add feed. Please try again.');
}
}
} catch (error) {
console.error('Add feed failed:', error);
showError('An error occurred. Please try again.');
}
}); });

View File

@ -22,11 +22,17 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form id="addFeedForm"> <form id="addFeedForm">
<div class="form-group">
<label for="feedName">Feed Name</label>
<input type="text" id="feedName" name="name" required
placeholder="My Blog Feed">
</div>
<div class="form-group"> <div class="form-group">
<label for="feedUrl">Feed URL</label> <label for="feedUrl">Feed URL</label>
<input type="url" id="feedUrl" name="feedUrl" required <input type="url" id="feedUrl" name="url" required
placeholder="https://example.com/feed.xml"> placeholder="https://example.com/feed.xml">
</div> </div>
<div class="error-message" id="feedErrorMessage" style="display: none; color: red; margin-bottom: 10px;"></div>
</form> </form>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">