Skip to content

Commit

Permalink
added sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
cophilot committed Oct 26, 2024
1 parent 025b447 commit b97afe0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/FavoriteGameSection/FavoriteGameSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function FavoriteGameSection() {
const games = getSortedGameNames();

const setFavoriteGames = (favoriteGames: string[]) => {
favoriteGames.sort();
setFavoriteGamesInternal(favoriteGames);
LocalStorageService.setFavoriteGames(favoriteGames);
};
Expand Down
5 changes: 4 additions & 1 deletion src/utils/LocalStorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export default class LocalStorageService {
if (favoriteGames === null) {
return [];
}
return JSON.parse(favoriteGames);
const arr: string[] = JSON.parse(favoriteGames);
// sort the array to make sure the order is consistent
arr.sort();
return arr;
}

static setFavoriteGames(favoriteGames: string[]) {
Expand Down

0 comments on commit b97afe0

Please sign in to comment.