Skip to content

Commit

Permalink
Merge pull request #195 from Tormak9970/dev
Browse files Browse the repository at this point in the history
chore: build v3.6.6
  • Loading branch information
Tormak9970 authored May 17, 2024
2 parents c70ee89 + 1cf42c6 commit 28a3f68
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/components/core/grids/GridResults.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { SGDBImage } from "../../../lib/models/SGDB";
import { dbFilters, gridType, GridTypes, isOnline, needsSGDBAPIKey, selectedGameAppId, selectedGameName, steamGridDBKey, selectedSteamGridGameId, lastPageCache, hasMorePagesCache, loadingSettings, steamGridSearchCache } from "../../../stores/AppState";
import Grid from "./Grid.svelte";
import { debounce, filterGrids, getHasMorePages, getPageNumberForGame } from "../../../lib/utils/Utils";
import { debounce, filterGrids, getHasMorePages, getLastLoadedPageNumberForGame } from "../../../lib/utils/Utils";
import GridLoadingSkeleton from "../../layout/GridLoadingSkeleton.svelte";
import PaddedScrollContainer from "../../layout/PaddedScrollContainer.svelte";
import { SMALL_GRID_DIMENSIONS } from "../../../lib/utils/ImageConstants";
Expand Down Expand Up @@ -34,12 +34,13 @@
*/
async function handleLoadOnScroll() {
if ($isOnline && $steamGridDBKey !== "" && !!$selectedGameAppId) {
const lastPageLoaded = getPageNumberForGame($selectedSteamGridGameId, $gridType);
const lastPageLoaded = getLastLoadedPageNumberForGame($selectedSteamGridGameId, $gridType);
const newPageNumber = lastPageLoaded + 1;
const oldGridsLength = grids.length;
await filterGridsOnStateChange(lastPageLoaded + 1);
await filterGridsOnStateChange(newPageNumber);
if (oldGridsLength !== grids.length) {
lastPageCache[parseInt($selectedSteamGridGameId)][$gridType] = lastPageLoaded + 1;
lastPageCache[parseInt($selectedSteamGridGameId)][$gridType] = newPageNumber;
} else {
hasMorePagesCache[parseInt($selectedSteamGridGameId)][$gridType] = false;
hasMorePages = false;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/controllers/CacheController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import { appCacheDir } from "@tauri-apps/api/path";

import { get, type Unsubscriber } from "svelte/store";
import { RequestError, SGDB, type SGDBGame, type SGDBImage } from "../models/SGDB";
import { dowloadingGridId, gridType, GridTypes, steamGridSearchCache, Platforms, steamGridDBKey, gridsCache, lastPageCache, selectedSteamGridGameId, steamGridSteamAppIdMap, canSave, appLibraryCache, steamGames, nonSteamGames, steamShortcuts, dbFilters, requestTimeoutLength, manualSteamGames } from "../../stores/AppState";
import { dowloadingGridId, gridType, GridTypes, steamGridSearchCache, Platforms, steamGridDBKey, gridsCache, steamGridSteamAppIdMap, canSave, appLibraryCache, steamGames, nonSteamGames, steamShortcuts, dbFilters, requestTimeoutLength, manualSteamGames } from "../../stores/AppState";
import { batchApplyWasCancelled, showBatchApplyProgress, batchApplyProgress, batchApplyMessage } from "../../stores/Modals";
import { LogController } from "./LogController";
import { RustInterop } from "./RustInterop";
import { ToastController } from "./ToastController";
import { filterGrids, getPageNumberForGame } from "../utils/Utils";
import { filterGrids, getLastLoadedPageNumberForGame } from "../utils/Utils";


/**
Expand Down Expand Up @@ -314,7 +314,7 @@ export class CacheController {
logToFile(`Fetching grids for game ${appId}...`, useCoreFile);
const type = get(gridType);

return await this.fetchGridsForGame(parseInt(selectedSteamGridId), type, page, getPageNumberForGame(selectedSteamGridId, type), useCoreFile);
return await this.fetchGridsForGame(parseInt(selectedSteamGridId), type, page, getLastLoadedPageNumberForGame(selectedSteamGridId, type), useCoreFile);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/lib/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function filterGrids(allGrids: SGDBImage[], type: GridTypes, filters: DBF
&& (grid.nsfw ? nsfwAllowed : true);
});

const query = `"${type === GridTypes.HERO ? "Heroe" : type}s for ${gameName} - page${page === 1 ? " 1" : "s 1 - " + page}"`;
const query = `"${type === GridTypes.HERO ? "Heroe" : type}s for ${gameName} - page${page === 0 ? " 0" : ("s 0 - " + page)}"`;
if (resGrids.length > 0) {
if (useCoreFile) {
LogController.log(`Query: ${query}. Result: ${resGrids.length} grids.`);
Expand Down Expand Up @@ -269,16 +269,16 @@ export function getHasMorePages(sgdbGameId: string, type: GridTypes) {
* Gets the most recent page number cached for a given sgdb game.
* @param sgdbGameId The id of the sgdb game to check for more pages.
* @param type The current grid type.
* @returns The most recent page number cached.
* @returns The most recent page number cached, or -1 if never cached.
*/
export function getPageNumberForGame(sgdbGameId: string, type: GridTypes) {
export function getLastLoadedPageNumberForGame(sgdbGameId: string, type: GridTypes) {
if (sgdbGameId === "None") {
return 0;
return -1;
} else {
const id = parseInt(sgdbGameId);

if (!lastPageCache[id]) lastPageCache[id] = {};
if (!lastPageCache[id][type]) lastPageCache[id][type] = 0;
if (!lastPageCache[id][type] && lastPageCache[id][type] !== 0) lastPageCache[id][type] = -1;

return lastPageCache[id][type];
}
Expand Down

0 comments on commit 28a3f68

Please sign in to comment.