From 40ffb35efd917d6527dcebeb4687d536fb2a2797 Mon Sep 17 00:00:00 2001 From: ItsKaa <31796925+ItsKaa@users.noreply.github.com> Date: Mon, 27 Jan 2025 19:49:13 +0100 Subject: [PATCH 1/2] Remove duplicates from recently added by grouping on metadata id and using the primary rom. --- frontend/src/stores/roms.ts | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/frontend/src/stores/roms.ts b/frontend/src/stores/roms.ts index fc8436b56..fa8b0f477 100644 --- a/frontend/src/stores/roms.ts +++ b/frontend/src/stores/roms.ts @@ -41,6 +41,23 @@ export default defineStore("roms", { }, actions: { + _getGroupedRoms(roms: SimpleRom[]): SimpleRom[] { + // Group roms by external id. + return Object.values( + groupBy( + roms, + (game) => + // If external id is null, generate a random id so that the roms are not grouped + game.igdb_id || game.moby_id || nanoid(), + ), + ) + .map((games) => { + // Find the index of the game where the 'rom_user' property has 'is_main_sibling' set to true. + return ( + games.find((game) => game.rom_user?.is_main_sibling) || games[0] + ); + }); + }, _reorder() { // Sort roms by comparator string this.allRoms = uniqBy(this.allRoms, "id").sort((a, b) => { @@ -57,20 +74,7 @@ export default defineStore("roms", { } // Group roms by external id - this._grouped = Object.values( - groupBy( - this.allRoms, - (game) => - // If external id is null, generate a random id so that the roms are not grouped - game.igdb_id || game.moby_id || nanoid(), - ), - ) - .map((games) => { - // Find the index of the game where the 'rom_user' property has 'is_main_sibling' set to true. - return ( - games.find((game) => game.rom_user?.is_main_sibling) || games[0] - ); - }) + this._grouped = this._getGroupedRoms(this.allRoms) .sort((a, b) => { return a.sort_comparator.localeCompare(b.sort_comparator); }); @@ -82,7 +86,10 @@ export default defineStore("roms", { this.currentRom = rom; }, setRecentRoms(roms: SimpleRom[]) { - this.recentRoms = roms; + // Set the recent roms. + // Group by external ID to only display a single entry per sibling, + // and sorted on rom ID in descending order. + this.recentRoms = this._getGroupedRoms(roms).sort((a, b) => b.id - a.id); }, setContinuePlayedRoms(roms: SimpleRom[]) { this.continuePlayingRoms = roms; From 65cdb91f2e6c08f62e4b00511832e3d9aae07140 Mon Sep 17 00:00:00 2001 From: ItsKaa <31796925+ItsKaa@users.noreply.github.com> Date: Mon, 27 Jan 2025 23:16:41 +0100 Subject: [PATCH 2/2] Only group Recently Added when option is enabled. --- frontend/src/stores/roms.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/frontend/src/stores/roms.ts b/frontend/src/stores/roms.ts index fa8b0f477..c5312b437 100644 --- a/frontend/src/stores/roms.ts +++ b/frontend/src/stores/roms.ts @@ -41,6 +41,11 @@ export default defineStore("roms", { }, actions: { + _shouldGroupRoms(): boolean { + return isNull(localStorage.getItem("settings.groupRoms")) + ? true + : localStorage.getItem("settings.groupRoms") === "true"; + }, _getGroupedRoms(roms: SimpleRom[]): SimpleRom[] { // Group roms by external id. return Object.values( @@ -65,10 +70,7 @@ export default defineStore("roms", { }); // Check if roms should be grouped - const groupRoms = isNull(localStorage.getItem("settings.groupRoms")) - ? true - : localStorage.getItem("settings.groupRoms") === "true"; - if (!groupRoms) { + if (!this._shouldGroupRoms()) { this._grouped = this.allRoms; return; } @@ -86,10 +88,15 @@ export default defineStore("roms", { this.currentRom = rom; }, setRecentRoms(roms: SimpleRom[]) { - // Set the recent roms. - // Group by external ID to only display a single entry per sibling, - // and sorted on rom ID in descending order. - this.recentRoms = this._getGroupedRoms(roms).sort((a, b) => b.id - a.id); + if (this._shouldGroupRoms()) { + // Group by external ID to only display a single entry per sibling, + // and sorted on rom ID in descending order. + this.recentRoms = this._getGroupedRoms(roms).sort( + (a, b) => b.id - a.id + ); + } else { + this.recentRoms = roms; + } }, setContinuePlayedRoms(roms: SimpleRom[]) { this.continuePlayingRoms = roms;