From 467ea29ec26e650ff194c3635500d5c05d02ca6c Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Mon, 3 Jun 2024 16:43:49 +0100 Subject: [PATCH] fix: removing all indices from flexsearch index --- src/main/workers/repacks.worker.ts | 4 ++++ src/renderer/src/components/sidebar/sidebar.tsx | 8 +++----- src/renderer/src/declaration.d.ts | 3 ++- src/renderer/src/features/library-slice.ts | 4 ++-- src/renderer/src/helpers.ts | 4 ++-- src/renderer/src/pages/downloads/downloads.tsx | 12 +++++------- src/types/index.ts | 8 ++++++-- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/main/workers/repacks.worker.ts b/src/main/workers/repacks.worker.ts index b781367e..f2604d8f 100644 --- a/src/main/workers/repacks.worker.ts +++ b/src/main/workers/repacks.worker.ts @@ -7,6 +7,10 @@ const repacksIndex = new flexSearch.Index(); const state: { repacks: GameRepack[] } = { repacks: [] }; export const setRepacks = (repacks: GameRepack[]) => { + for (let i = 0; i < state.repacks.length; i++) { + repacksIndex.remove(i); + } + state.repacks = repacks; for (let i = 0; i < repacks.length; i++) { diff --git a/src/renderer/src/components/sidebar/sidebar.tsx b/src/renderer/src/components/sidebar/sidebar.tsx index 45b8d254..2a38b9c9 100644 --- a/src/renderer/src/components/sidebar/sidebar.tsx +++ b/src/renderer/src/components/sidebar/sidebar.tsx @@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { useLocation, useNavigate } from "react-router-dom"; -import type { Game } from "@types"; +import type { LibraryGame } from "@types"; import { TextField } from "@renderer/components"; import { useDownload, useLibrary } from "@renderer/hooks"; @@ -25,9 +25,7 @@ export function Sidebar() { const { library, updateLibrary } = useLibrary(); const navigate = useNavigate(); - const [filteredLibrary, setFilteredLibrary] = useState< - Omit[] - >([]); + const [filteredLibrary, setFilteredLibrary] = useState([]); const [isResizing, setIsResizing] = useState(false); const [sidebarWidth, setSidebarWidth] = useState( @@ -101,7 +99,7 @@ export function Sidebar() { }; }, [isResizing]); - const getGameTitle = (game: Omit) => { + const getGameTitle = (game: LibraryGame) => { if (game.status === "paused") return t("paused", { title: game.title }); if (lastPacket?.game.id === game.id) { diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index 203e22d7..5d5bf0ec 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -2,6 +2,7 @@ import type { AppUpdaterEvents, CatalogueEntry, Game, + LibraryGame, GameRepack, GameShop, HowLongToBeatCategory, @@ -58,7 +59,7 @@ declare global { shop: GameShop, executablePath: string | null ) => Promise; - getLibrary: () => Promise[]>; + getLibrary: () => Promise; openGameInstaller: (gameId: number) => Promise; openGame: (gameId: number, executablePath: string) => Promise; closeGame: (gameId: number) => Promise; diff --git a/src/renderer/src/features/library-slice.ts b/src/renderer/src/features/library-slice.ts index 46ebb9d0..6c95aa79 100644 --- a/src/renderer/src/features/library-slice.ts +++ b/src/renderer/src/features/library-slice.ts @@ -1,10 +1,10 @@ import { createSlice } from "@reduxjs/toolkit"; import type { PayloadAction } from "@reduxjs/toolkit"; -import type { Game } from "@types"; +import type { LibraryGame } from "@types"; export interface LibraryState { - value: Omit[]; + value: LibraryGame[]; } const initialState: LibraryState = { diff --git a/src/renderer/src/helpers.ts b/src/renderer/src/helpers.ts index 975940b9..9d5a4700 100644 --- a/src/renderer/src/helpers.ts +++ b/src/renderer/src/helpers.ts @@ -1,4 +1,4 @@ -import type { CatalogueEntry } from "@types"; +import type { GameShop } from "@types"; export const steamUrlBuilder = { library: (objectID: string) => @@ -34,7 +34,7 @@ export const getSteamLanguage = (language: string) => { }; export const buildGameDetailsPath = ( - game: Pick, + game: { shop: GameShop; objectID: string; title: string }, params: Record = {} ) => { const searchParams = new URLSearchParams({ title: game.title, ...params }); diff --git a/src/renderer/src/pages/downloads/downloads.tsx b/src/renderer/src/pages/downloads/downloads.tsx index b3ab4d29..f41d048b 100644 --- a/src/renderer/src/pages/downloads/downloads.tsx +++ b/src/renderer/src/pages/downloads/downloads.tsx @@ -8,7 +8,7 @@ import { steamUrlBuilder, } from "@renderer/helpers"; import { useAppSelector, useDownload, useLibrary } from "@renderer/hooks"; -import type { Game } from "@types"; +import type { LibraryGame } from "@types"; import { useEffect, useMemo, useRef, useState } from "react"; import { BinaryNotFoundModal } from "../shared-modals/binary-not-found-modal"; @@ -30,9 +30,7 @@ export function Downloads() { const gameToBeDeleted = useRef(null); - const [filteredLibrary, setFilteredLibrary] = useState< - Omit[] - >([]); + const [filteredLibrary, setFilteredLibrary] = useState([]); const [showBinaryNotFoundModal, setShowBinaryNotFoundModal] = useState(false); const [showDeleteModal, setShowDeleteModal] = useState(false); @@ -61,7 +59,7 @@ export function Downloads() { updateLibrary(); }); - const getFinalDownloadSize = (game: Omit) => { + const getFinalDownloadSize = (game: LibraryGame) => { const isGameDownloading = lastPacket?.game.id === game.id; if (game.fileSize) return formatBytes(game.fileSize); @@ -72,7 +70,7 @@ export function Downloads() { return "N/A"; }; - const getGameInfo = (game: Omit) => { + const getGameInfo = (game: LibraryGame) => { const isGameDownloading = lastPacket?.game.id === game.id; const finalDownloadSize = getFinalDownloadSize(game); @@ -132,7 +130,7 @@ export function Downloads() { setShowDeleteModal(true); }; - const getGameActions = (game: Omit) => { + const getGameActions = (game: LibraryGame) => { const isGameDownloading = lastPacket?.game.id === game.id; const deleting = isGameDeleting(game.id); diff --git a/src/types/index.ts b/src/types/index.ts index 8d50eb67..25b64361 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -87,7 +87,7 @@ export interface CatalogueEntry { } /* Used by the library */ -export interface Game extends Omit { +export interface Game { id: number; title: string; iconUrl: string; @@ -102,17 +102,21 @@ export interface Game extends Omit { executablePath: string | null; lastTimePlayed: Date | null; fileSize: number; + objectID: string; + shop: GameShop; createdAt: Date; updatedAt: Date; } +export type LibraryGame = Omit; + export interface DownloadProgress { downloadSpeed: number; timeRemaining: number; numPeers: number; numSeeds: number; isDownloadingMetadata: boolean; - game: Omit; + game: LibraryGame; } export interface UserPreferences {