Skip to content

Commit

Permalink
Merge pull request #45 from InteropIO/G4E-7129-Store-favorites-as-app…
Browse files Browse the repository at this point in the history
…-preferences

G4E-7129 - favourites are stored in the prefs
  • Loading branch information
galin-iliev authored Jun 11, 2024
2 parents 9736181 + b60868a commit 2d964ab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
25 changes: 6 additions & 19 deletions js/favorites.js
Original file line number Diff line number Diff line change
@@ -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);
}

Expand All @@ -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) {
Expand All @@ -41,7 +28,7 @@ function addFavoriteApp(appName) {

newApps.push(appName);
favoriteApps.next(newApps);
localStorage.setItem('favorite-apps', JSON.stringify(newApps));
setSetting({ favoriteApps: newApps });
updateFavoriteApps();
}

Expand All @@ -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 };
13 changes: 7 additions & 6 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -47,6 +47,7 @@ async function init() {
await glueModule.getPrefs();
await glueModule.getNotificationsConfiguration();
await glueModule.trackNotificationsConfigurationChange();
favoritesModule.init();

finishLoading();

Expand Down Expand Up @@ -172,7 +173,7 @@ function printApps() {
});

q('#search-results').innerHTML = newResultsHTML || noApplicationsHTML;
updateFavoriteApps();
favoritesModule.updateFavoriteApps();
});
}

Expand Down Expand Up @@ -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 {
Expand All @@ -290,7 +291,7 @@ function printLayouts() {
}

function printFavoriteApps() {
favoriteApps
favoritesModule.favoriteApps
.pipe(rxjs.operators.combineLatest(allApplicationsObs))
.subscribe(([favApps, allApps]) => {
let favAppsHtml = ``;
Expand Down
1 change: 1 addition & 0 deletions js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let settings = {
toolbarAppRows: '8',
showHiddenApps: false,
vertical: true,
favoriteApps: [],
};
const toolbarWidth = {
vertical: 200,
Expand Down

0 comments on commit 2d964ab

Please sign in to comment.