changes after pr review

This commit is contained in:
Zamitto 2024-04-29 14:12:06 -03:00
parent e6cc7a2861
commit eb8dc38f1e
3 changed files with 13 additions and 13 deletions

View File

@ -5,11 +5,10 @@ import { Steam250Game, getSteam250List } from "@main/services";
import { registerEvent } from "../register-event";
import { searchGames, searchRepacks } from "../helpers/search-games";
let gamesList: Steam250Game[] = [];
let nextGameIndex = 0;
const state = { games: Array<Steam250Game>(), index: 0 };
const getRandomGame = async (_event: Electron.IpcMainInvokeEvent) => {
if (gamesList.length == 0) {
if (state.games.length == 0) {
const steam250List = await getSteam250List();
const filteredSteam250List = steam250List.filter((game) => {
@ -19,20 +18,20 @@ const getRandomGame = async (_event: Electron.IpcMainInvokeEvent) => {
return repacks.length && catalogue.length;
});
gamesList = shuffle(filteredSteam250List);
state.games = shuffle(filteredSteam250List);
}
if (gamesList.length == 0) {
if (state.games.length == 0) {
return "";
}
const resultObjectId = gamesList[nextGameIndex].objectID;
const resultObjectId = state.games[state.index].objectID;
nextGameIndex += 1;
state.index += 1;
if (nextGameIndex == gamesList.length) {
nextGameIndex = 0;
gamesList = shuffle(gamesList);
if (state.index == state.games.length) {
state.index = 0;
state.games = shuffle(state.games);
}
return resultObjectId;

View File

@ -6,7 +6,7 @@ const searchGamesEvent = async (
_event: Electron.IpcMainInvokeEvent,
query: string
): Promise<CatalogueEntry[]> => {
return Promise.all(searchGames({ query, take: 12 }));
return searchGames({ query, take: 12 });
};
registerEvent(searchGamesEvent, {

View File

@ -36,8 +36,9 @@ const steam250Paths = [
];
export const getSteam250List = async () => {
const gamesPromises = steam250Paths.map((path) => requestSteam250(path));
const gamesList = (await Promise.all(gamesPromises)).flat();
const gamesList = (
await Promise.all(steam250Paths.map((path) => requestSteam250(path)))
).flat();
const gamesMap: Map<string, Steam250Game> = gamesList.reduce((map, item) => {
map.set(item.objectID, item);