Skip to content

Commit 99ac4f1

Browse files
committed
Implement manual save functionality across app settings, replacing auto-save with dedicated save buttons. Add unsaved changes detection and user confirmation before navigation. Update UI elements and event listeners for improved user experience.
1 parent 3c63f49 commit 99ac4f1

File tree

3 files changed

+329
-95
lines changed

3 files changed

+329
-95
lines changed

frontend/static/js/apps.js

Lines changed: 4 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -213,97 +213,15 @@ const appsModule = {
213213
});
214214
},
215215

216-
// Add auto-save listeners to form elements
216+
// Add change listeners to form elements (auto-save removed - now using manual save)
217217
addFormChangeListeners: function(form) {
218218
if (!form) return;
219219

220220
const appType = form.getAttribute('data-app-type');
221-
console.log(`[Apps] Adding auto-save listeners for ${appType}`);
221+
console.log(`[Apps] Skipping auto-save listeners for ${appType} - now using manual save`);
222222

223-
// Immediate auto-save function
224-
const autoSave = () => {
225-
this.autoSaveSettings(appType, form);
226-
};
227-
228-
// Add listeners to all form inputs, selects, and textareas
229-
const formElements = form.querySelectorAll('input, select, textarea');
230-
formElements.forEach(element => {
231-
// Skip buttons and test-related elements
232-
if (element.type === 'button' ||
233-
element.type === 'submit' ||
234-
element.tagName.toLowerCase() === 'button' ||
235-
element.classList.contains('test-connection-btn') ||
236-
element.id && element.id.includes('test-')) {
237-
return;
238-
}
239-
240-
// Remove any existing listeners to avoid duplicates
241-
element.removeEventListener('change', autoSave);
242-
element.removeEventListener('input', autoSave);
243-
244-
// Add auto-save listeners
245-
element.addEventListener('change', autoSave);
246-
247-
// For text and number inputs, also listen for input events
248-
if (element.type === 'text' || element.type === 'number' || element.tagName.toLowerCase() === 'textarea') {
249-
element.addEventListener('input', autoSave);
250-
}
251-
252-
console.log(`[Apps] Added auto-save listener to ${element.tagName} with id: ${element.id || 'no-id'}`);
253-
});
254-
255-
// Also observe for added/removed instances
256-
try {
257-
if (this.observer) {
258-
this.observer.disconnect();
259-
}
260-
261-
this.observer = new MutationObserver((mutations) => {
262-
let shouldAutoSave = false;
263-
264-
mutations.forEach(mutation => {
265-
if (mutation.type === 'childList' &&
266-
(mutation.addedNodes.length > 0 || mutation.removedNodes.length > 0)) {
267-
268-
// Check if the changes are test-related elements that we should ignore
269-
let isTestRelated = false;
270-
271-
[...mutation.addedNodes, ...mutation.removedNodes].forEach(node => {
272-
if (node.nodeType === Node.ELEMENT_NODE) {
273-
if (node.classList && (
274-
node.classList.contains('connection-message') ||
275-
node.classList.contains('test-status') ||
276-
node.classList.contains('test-result') ||
277-
node.classList.contains('auto-save-indicator')
278-
)) {
279-
isTestRelated = true;
280-
}
281-
if (node.id && (node.id.includes('-status-') || node.id.includes('save-indicator'))) {
282-
isTestRelated = true;
283-
}
284-
}
285-
});
286-
287-
if (!isTestRelated) {
288-
shouldAutoSave = true;
289-
}
290-
}
291-
});
292-
293-
if (shouldAutoSave) {
294-
console.log('[Apps] Instance structure changed - triggering auto-save');
295-
autoSave();
296-
}
297-
});
298-
299-
// Start observing instances container for changes
300-
const instancesContainers = form.querySelectorAll('.instances-container');
301-
instancesContainers.forEach(container => {
302-
this.observer.observe(container, { childList: true, subtree: true });
303-
});
304-
} catch (error) {
305-
console.error('[Apps] Error setting up MutationObserver:', error);
306-
}
223+
// Auto-save has been removed - apps now use manual save buttons
224+
// No longer adding change listeners or mutation observers for auto-save functionality
307225
},
308226

309227
// Auto-save settings silently in background

frontend/static/js/new-main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,15 @@ let huntarrUI = {
477477
}
478478
}
479479

480+
// Check for unsaved App instance changes if leaving Apps section
481+
const appSections = ['apps'];
482+
if (appSections.includes(this.currentSection) && window.SettingsForms && typeof window.SettingsForms.checkUnsavedChanges === 'function') {
483+
if (!window.SettingsForms.checkUnsavedChanges()) {
484+
console.log(`[huntarrUI] Navigation cancelled due to unsaved App changes`);
485+
return; // User chose to stay and save changes
486+
}
487+
}
488+
480489
console.log(`[huntarrUI] User switching from ${this.currentSection} to ${section}, refreshing page...`);
481490
// Store the target section in localStorage so we can navigate to it after refresh
482491
localStorage.setItem('huntarr-target-section', section);

0 commit comments

Comments
 (0)