From b60868a196cd7f4cf5a16f8e330b716552310492 Mon Sep 17 00:00:00 2001 From: Georgi Davidkov Date: Fri, 10 May 2024 15:00:54 +0300 Subject: [PATCH] G4E-7129 - favourites are stored in the prefs --- js/favorites.js | 25 ++++++------------------- js/index.js | 13 +++++++------ js/settings.js | 1 + 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/js/favorites.js b/js/favorites.js index 0ec257a..0cc7a1a 100644 --- a/js/favorites.js +++ b/js/favorites.js @@ -1,16 +1,9 @@ -const favoriteApps = new rxjs.BehaviorSubject([]); +import { getSetting, setSetting } from "./settings.js"; -init(); +const favoriteApps = new rxjs.BehaviorSubject([]); function init() { - let storageData = localStorage.getItem('favorite-apps'); - - if (storageData === null) { - localStorage.setItem('favorite-apps', '[]'); - } - - let savedFavApps = JSON.parse(localStorage.getItem('favorite-apps')); - + const savedFavApps = getSetting('favoriteApps'); favoriteApps.next(savedFavApps); } @@ -26,12 +19,6 @@ function updateFavoriteApps() { appElement.classList.remove('fav-app'); } }); - // favoriteApps.subscribe(([favApps, allApps]) => { - // document.querySelectorAll('#search-results>li').forEach((appElement) => { - // // console.log(appElement); - // // let appName = appElement.getAttribute('app-name'); - // }); - // }); } function addFavoriteApp(appName) { @@ -41,7 +28,7 @@ function addFavoriteApp(appName) { newApps.push(appName); favoriteApps.next(newApps); - localStorage.setItem('favorite-apps', JSON.stringify(newApps)); + setSetting({ favoriteApps: newApps }); updateFavoriteApps(); } @@ -54,8 +41,8 @@ function removeFavoriteApp(appName) { (checkedAppName) => checkedAppName !== appName ); favoriteApps.next(currentApps); - localStorage.setItem('favorite-apps', JSON.stringify(currentApps)); + setSetting({ favoriteApps: currentApps }); updateFavoriteApps(); } -export { favoriteApps, addFavoriteApp, removeFavoriteApp, updateFavoriteApps }; +export { init, favoriteApps, addFavoriteApp, removeFavoriteApp, updateFavoriteApps }; diff --git a/js/index.js b/js/index.js index f552505..8a70609 100644 --- a/js/index.js +++ b/js/index.js @@ -11,7 +11,7 @@ import { noFavoriteAppsHTML, getItemHTMLTemplate, } from './applications.js'; -import { favoriteApps, updateFavoriteApps } from './favorites.js'; +import * as favoritesModule from './favorites.js'; import { filteredLayouts, layoutHTMLTemplate, @@ -47,6 +47,7 @@ async function init() { await glueModule.getPrefs(); await glueModule.getNotificationsConfiguration(); await glueModule.trackNotificationsConfigurationChange(); + favoritesModule.init(); finishLoading(); @@ -172,7 +173,7 @@ function printApps() { }); q('#search-results').innerHTML = newResultsHTML || noApplicationsHTML; - updateFavoriteApps(); + favoritesModule.updateFavoriteApps(); }); } @@ -263,9 +264,9 @@ function printRunningApps() { if (runningApps.length > 0) { runningApps.forEach( (runningApp) => - (newRunningAppsHTML += applicationHTMLTemplate(runningApp, { - favoriteBtn: false, - })) + (newRunningAppsHTML += applicationHTMLTemplate(runningApp, { + favoriteBtn: false, + })) ); q('#running-apps').innerHTML = newRunningAppsHTML; } else { @@ -290,7 +291,7 @@ function printLayouts() { } function printFavoriteApps() { - favoriteApps + favoritesModule.favoriteApps .pipe(rxjs.operators.combineLatest(allApplicationsObs)) .subscribe(([favApps, allApps]) => { let favAppsHtml = ``; diff --git a/js/settings.js b/js/settings.js index 0a54209..398007f 100644 --- a/js/settings.js +++ b/js/settings.js @@ -10,6 +10,7 @@ let settings = { toolbarAppRows: '8', showHiddenApps: false, vertical: true, + favoriteApps: [], }; const toolbarWidth = { vertical: 200,