From eef2f32e14634246ecf3a5d93813294123bbc310 Mon Sep 17 00:00:00 2001 From: redxef Date: Tue, 21 Jan 2025 22:51:25 +0100 Subject: [PATCH] fix: navigating to the config pages allways loads, not only on the first attempt. --- .../Pages/lispPlayground.js | 37 ++++++++-------- .../Pages/smartCollections.js | 43 +++++++++---------- .../Pages/smartPlaylists.js | 41 +++++++++--------- 3 files changed, 61 insertions(+), 60 deletions(-) diff --git a/Jellyfin.Plugin.SmartPlaylist/Pages/lispPlayground.js b/Jellyfin.Plugin.SmartPlaylist/Pages/lispPlayground.js index 65b2c93..8b3d4f3 100644 --- a/Jellyfin.Plugin.SmartPlaylist/Pages/lispPlayground.js +++ b/Jellyfin.Plugin.SmartPlaylist/Pages/lispPlayground.js @@ -21,23 +21,26 @@ function initial_load() { Dashboard.hideLoadingMsg(); } -document.querySelector('#LispPlaygroundConfigPage') - .addEventListener('viewshow', function() { - initial_load(); +export default function (view, params) { + view.addEventListener('viewshow', function() { + initial_load(null); }); + view.addEventListener('viewhide', function (_e) {}); + view.addEventListener('viewdestroy', function (_e) {}); -document.querySelector('#LispPlaygroundConfigPage') - .addEventListener('pageshow', function() { - initial_load(); - }); - -document.querySelector('#LispPlaygroundConfigForm') - .addEventListener('submit', function (e) { - e.preventDefault(); - Dashboard.showLoadingMsg(); - const editProgram = document.querySelector('#LispPlaygroundEditProgram'); - ApiClient.runLispProgram(editProgram.value).then(function (r) { - fillForm(r); - Dashboard.hideLoadingMsg(); + document.querySelector('#LispPlaygroundConfigPage') + .addEventListener('pageshow', function() { + initial_load(); }); - }); + + document.querySelector('#LispPlaygroundConfigForm') + .addEventListener('submit', function (e) { + e.preventDefault(); + Dashboard.showLoadingMsg(); + const editProgram = document.querySelector('#LispPlaygroundEditProgram'); + ApiClient.runLispProgram(editProgram.value).then(function (r) { + fillForm(r); + Dashboard.hideLoadingMsg(); + }); + }); +} diff --git a/Jellyfin.Plugin.SmartPlaylist/Pages/smartCollections.js b/Jellyfin.Plugin.SmartPlaylist/Pages/smartCollections.js index db0ec34..cedb9a6 100644 --- a/Jellyfin.Plugin.SmartPlaylist/Pages/smartCollections.js +++ b/Jellyfin.Plugin.SmartPlaylist/Pages/smartCollections.js @@ -88,29 +88,28 @@ function initial_load(selectedId) { Dashboard.hideLoadingMsg(); }); } -document.querySelector('#SmartCollectionConfigPage') - .addEventListener('viewshow', function() { + +export default function (view, params) { + view.addEventListener('viewshow', function() { initial_load(null); }); + view.addEventListener('viewhide', function (_e) {}); + view.addEventListener('viewdestroy', function (_e) {}); -document.querySelector('#SmartCollectionConfigPage') - .addEventListener('pageshow', function() { - initial_load(null); - }); - -document.querySelector('#SmartcollectionSelection') - .addEventListener('change', function() { - const selection = document.querySelector('#SmartcollectionSelection'); - fillForm(COLLECTIONS[selection.selectedIndex]); - }); - -document.querySelector('#SmartCollectionConfigForm') - .addEventListener('submit', function (e) { - Dashboard.showLoadingMsg(); - const selection = document.querySelector('#SmartcollectionSelection'); - const selectedId = COLLECTIONS[selection.selectedIndex].Id; - ApiClient.setSmartCollection(jsonFromForm(COLLECTIONS[selection.selectedIndex].CollectionId)).then(function () { - initial_load(selectedId); + document.querySelector('#SmartcollectionSelection') + .addEventListener('change', function() { + const selection = document.querySelector('#SmartcollectionSelection'); + fillForm(COLLECTIONS[selection.selectedIndex]); }); - e.preventDefault(); - }); + + document.querySelector('#SmartCollectionConfigForm') + .addEventListener('submit', function (e) { + Dashboard.showLoadingMsg(); + const selection = document.querySelector('#SmartcollectionSelection'); + const selectedId = COLLECTIONS[selection.selectedIndex].Id; + ApiClient.setSmartCollection(jsonFromForm(COLLECTIONS[selection.selectedIndex].CollectionId)).then(function () { + initial_load(selectedId); + }); + e.preventDefault(); + }); +} diff --git a/Jellyfin.Plugin.SmartPlaylist/Pages/smartPlaylists.js b/Jellyfin.Plugin.SmartPlaylist/Pages/smartPlaylists.js index 0eda8ed..888cbf9 100644 --- a/Jellyfin.Plugin.SmartPlaylist/Pages/smartPlaylists.js +++ b/Jellyfin.Plugin.SmartPlaylist/Pages/smartPlaylists.js @@ -116,28 +116,27 @@ function initial_load(selectedId) { }); } -document.querySelector('#SmartPlaylistConfigPage') - .addEventListener('viewshow', function() { - initial_load(null); - }); -document.querySelector('#SmartPlaylistConfigPage') - .addEventListener('pageshow', function() { +export default function (view, params) { + view.addEventListener('viewshow', function() { initial_load(null); }); + view.addEventListener('viewhide', function (_e) {}); + view.addEventListener('viewdestroy', function (_e) {}); -document.querySelector('#SmartplaylistSelection') - .addEventListener('change', function() { - const selection = document.querySelector('#SmartplaylistSelection'); - fillForm(PLAYLISTS[selection.selectedIndex], USERS); - }); - -document.querySelector('#SmartPlaylistConfigForm') - .addEventListener('submit', function (e) { - Dashboard.showLoadingMsg(); - const selection = document.querySelector('#SmartplaylistSelection'); - const selectedId = PLAYLISTS[selection.selectedIndex].Id; - ApiClient.setSmartPlaylist(jsonFromForm()).then(function () { - initial_load(selectedId); + document.querySelector('#SmartplaylistSelection') + .addEventListener('change', function() { + const selection = document.querySelector('#SmartplaylistSelection'); + fillForm(PLAYLISTS[selection.selectedIndex], USERS); }); - e.preventDefault(); - }); + + document.querySelector('#SmartPlaylistConfigForm') + .addEventListener('submit', function (e) { + Dashboard.showLoadingMsg(); + const selection = document.querySelector('#SmartplaylistSelection'); + const selectedId = PLAYLISTS[selection.selectedIndex].Id; + ApiClient.setSmartPlaylist(jsonFromForm()).then(function () { + initial_load(selectedId); + }); + e.preventDefault(); + }); +}