diff --git a/main/components/GamePanel.vue b/main/components/GamePanel.vue new file mode 100644 index 00000000..a931f308 --- /dev/null +++ b/main/components/GamePanel.vue @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + {{ game.mName }} + + + {{ game.mShortDescription }} + + + + + {{ statusText }} + + + + + + + + + + diff --git a/main/components/LibrarySearch.vue b/main/components/LibrarySearch.vue index d4beffaf..b19288ab 100644 --- a/main/components/LibrarySearch.vue +++ b/main/components/LibrarySearch.vue @@ -25,6 +25,14 @@ > + + + + @@ -52,7 +60,7 @@ }; -} = {}; -const icons: { [key: string]: string } = {}; - -const collections: Ref = ref([]); - -async function calculateGames(clearAll = false, forceRefresh = false) { - if (clearAll) { - collections.value = []; - loading.value = true; - } - // If we update immediately, the navigation gets re-rendered before we - // add all the necessary state, and it freaks tf out - const newGames = await invoke("fetch_library", { - hardRefresh: forceRefresh, - }); - const otherCollections = await invoke("fetch_collections", { - hardRefresh: forceRefresh, - }); - const allGames = [ - ...newGames, - ...otherCollections - .map((e) => e.entries) - .flat() - .map((e) => e.game), - ].filter((v, i, a) => a.indexOf(v) === i); - - for (const game of allGames) { - if (games[game.id]) continue; - games[game.id] = await useGame(game.id); - } - for (const game of allGames) { - if (icons[game.id]) continue; - icons[game.id] = await useObject(game.mIconObjectId); - } - - const libraryCollection = { - id: "library", - name: "Library", - isDefault: true, - entries: newGames.map((e) => ({ gameId: e.id, game: e })), - } satisfies Collection; - - loading.value = false; - collections.value = [libraryCollection, ...otherCollections]; -} +// Use library view composable +const { libraryView, toggleView } = useLibraryView(); +const { loading, games, icons, collections, calculateGames } = useLibraryGames(); // Wait up to 300 ms for the library to load, otherwise // show the loading state while we while @@ -229,6 +190,16 @@ await new Promise((r) => { setTimeout(resolveFunc, 300); }); +// Listen for library updates +listen("update_library", async (event) => { + console.log("Updating library"); + let oldNavigation = currentNavigation.value; + await calculateGames(); + if (oldNavigation !== currentNavigation.value) { + router.push("/library"); + } +}); + const navigation = computed(() => collections.value.map((collection) => { const items = collection.entries.map(({ game }) => { @@ -273,15 +244,6 @@ const filteredNavigation = computed(() => { })) .filter((e) => e.items.length > 0); }); - -listen("update_library", async (event) => { - console.log("Updating library"); - let oldNavigation = currentNavigation.value; - await calculateGames(); - if (oldNavigation !== currentNavigation.value) { - router.push("/library"); - } -});
+ {{ game.mShortDescription }} +