Skip to content

Commit

Permalink
Normalize title names in search
Browse files Browse the repository at this point in the history
Closes #9
  • Loading branch information
Ecks1337 committed Sep 3, 2022
1 parent fd3d442 commit 8cc5448
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface IConfigContainer {
config: RyujinxConfigMeta;
}

const nonAlphaNumeric = new RegExp(/[^a-z0-9\s]/g);

const Label = styled(Paper)(({ theme }) => ({
...theme.typography.body2,
border: "1px solid black",
Expand Down Expand Up @@ -53,18 +55,23 @@ const GameListingComponent = ({ config }: IConfigContainer) => {
// 1. Scan games on user system
// 2. Build metadata from eshop with titleId as argument
const createLibrary = async () => {
const titleIds = await invokeIpc("scan-games", config.path);
let titleIds = await invokeIpc("scan-games", config.path);
titleIds = titleIds.filter(id => id !== "0000000000000000"); // Homebrew app

const gamesCollection: EShopTitleMeta[] = await Promise.all(titleIds.map(async (i: string) => invokeIpc("build-metadata-from-titleId", i)));
setGames(gamesCollection.filter(i => i.id !== "0000000000000000")); // Homebrew app
gamesCollection.forEach(title => title.normalizedName = title.name.toLowerCase().normalize("NFKD").replace(nonAlphaNumeric, ""));

setGames(gamesCollection);
};

useEffect(() => {
createLibrary().catch(() => setIsLoaded(true));
}, [config]);

useEffect(() => {
const searchTermLowerCase = searchTerm.toLowerCase();
setFilteredGames(searchTerm.length > 0
? games.filter(item => searchTerm.length > 0 ? item.name.toLowerCase().includes(searchTerm.toLowerCase()) : true)
? games.filter(title => title.normalizedName.includes(searchTermLowerCase))
: games);
setIsLoaded(true);
}, [games, searchTerm]);
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type EShopTitleMeta = {
id: string;
name: string;
iconUrl: string;
normalizedName?: string;
};

export type EShopTitles = {
Expand Down

0 comments on commit 8cc5448

Please sign in to comment.