From 077077dffe793196ccca1cbc91c466755d75688e Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 28 Jul 2025 15:11:45 +0300 Subject: [PATCH] feat(calendar): unify calendar name input and calendar search input fields --- public/index.html | 22 ++++++-------- public/script.js | 74 ++++++++++++++++++++++++++++++++--------------- public/styles.css | 1 - src/app.js | 2 +- 4 files changed, 61 insertions(+), 38 deletions(-) diff --git a/public/index.html b/public/index.html index 720649d..34f4717 100644 --- a/public/index.html +++ b/public/index.html @@ -13,23 +13,19 @@
- + + +

Calendar Collection Name

-

Find Existing Calendar

- - + +
-
- - -

Merge Calendars

-
- +
diff --git a/public/script.js b/public/script.js index b4bd429..e358673 100644 --- a/public/script.js +++ b/public/script.js @@ -60,44 +60,70 @@ function extractCalendarName(input) { // Event listener for the search button if (searchBtn) { searchBtn.addEventListener('click', searchCalendar); - - // Also search when pressing Enter in the search field - if (calendarSearch) { - calendarSearch.addEventListener('keypress', function(e) { - if (e.key === 'Enter') { - searchCalendar(); - } - }); - } } -// Function to search for a calendar +// Event listener for the unified input field +const linkGroupNameInput = document.getElementById('link-group-name'); +if (linkGroupNameInput) { + // Search when pressing Enter + linkGroupNameInput.addEventListener('keypress', function(e) { + if (e.key === 'Enter') { + e.preventDefault(); // Prevent form submission + searchCalendar(); + } + }); + + // Clear status when user starts typing + linkGroupNameInput.addEventListener('input', function() { + // Clear search results when user modifies the input + if (searchResult) { + searchResult.innerHTML = ''; + } + // Reset editing state when input changes significantly + if (isEditing && this.value.trim() !== currentCalendarName) { + isEditing = false; + currentCalendarName = ''; + } + }); +} + +// Function to search for a calendar using the unified input function searchCalendar() { - let calendarName = calendarSearch.value.trim(); + let calendarName = document.getElementById('link-group-name').value.trim(); if (!calendarName) { - searchResult.innerHTML = '
Please enter a calendar name
'; + searchResult.innerHTML = '
Please enter a collection name
'; return; } // Extract just the calendar name if a URL was entered calendarName = extractCalendarName(calendarName); + // Update the input field with the extracted name + document.getElementById('link-group-name').value = calendarName; + searchResult.innerHTML = '
Loading...
'; // Check if calendar exists fetch(`/calendar-config/${calendarName}`) .then(response => response.json()) .then(data => { + const statusElement = document.getElementById('collection-status'); if (data.exists) { - searchResult.innerHTML = `
Calendar found!
`; + // Clear search result + searchResult.innerHTML = ''; loadCalendarConfig(data.config, calendarName); - } else { - searchResult.innerHTML = `
Calendar not found
`; + } else { + // Clear search result for new collections + searchResult.innerHTML = ''; + // Reset to creation mode + isEditing = false; + currentCalendarName = ''; } }) .catch(error => { console.error('Error searching for calendar:', error); - searchResult.innerHTML = `
Error searching for calendar
`; + searchResult.innerHTML = `
Error checking collection
`; + document.getElementById('collection-status').innerHTML = ''; }); } @@ -213,27 +239,29 @@ form.addEventListener('submit', (event) => { }) .then((data) => { mergedUrl = data.url; - + // Hide the info text when showing results if (resultInfo) { resultInfo.style.display = 'none'; } - + + const statusElement = document.getElementById('collection-status'); + if (isEditing) { - result.innerHTML = `Updated calendar URL: ${data.url}`; - + result.innerHTML = `Collection updated successfully!
URL: ${data.url}`; + // Update the search result if (searchResult) { searchResult.innerHTML = `
Calendar updated successfully!
`; } - + // Reset editing state isEditing = false; currentCalendarName = ''; } else { - result.innerHTML = `Merged calendar URL: ${data.url}`; + result.innerHTML = `New collection created!
URL: ${data.url}`; } - + console.log('Operation completed successfully!'); }) .catch((error) => { diff --git a/public/styles.css b/public/styles.css index 80d6637..4c6747f 100644 --- a/public/styles.css +++ b/public/styles.css @@ -33,7 +33,6 @@ .input-group { display: grid; gap: 1rem; - margin-bottom: 1.5rem; } /* Calendar Entry Styling */ diff --git a/src/app.js b/src/app.js index 003e498..2e6cabf 100644 --- a/src/app.js +++ b/src/app.js @@ -1,6 +1,6 @@ import server from './server.js'; -const port = process.env.NODE_PORT || 3012; +const port = process.env.NODE_PORT || 3013; server.listen(port, () => { console.log(`Server started on port ${port}`); });