refactor: Add tag filtering functionality to theme search

This commit is contained in:
Mauro Balades
2024-08-22 21:36:01 +02:00
parent 30cde8f559
commit 7f74a62982
3 changed files with 55 additions and 26 deletions

View File

@@ -7,9 +7,8 @@ export interface ZenTheme {
id: string
homepage?: string
readme: string
preferences: {
[key: string]: string
},
preferences?: string
isColorTheme: boolean
author: string
}
@@ -28,8 +27,16 @@ export async function getAllThemes() {
return themesArray;
}
export function getThemesFromSearch(themes: ZenTheme[], query: string): ZenTheme[] {
return themes.filter((theme) => theme.name.toLowerCase().includes(query.toLowerCase()));
export function getThemesFromSearch(themes: ZenTheme[], query: string, tags: string[]): ZenTheme[] {
let filtered = themes.filter((theme) => theme.name.toLowerCase().includes(query.toLowerCase()));
if (tags.includes("all")) return filtered;
const isSearchingForColorScheme = tags.includes("color-scheme");
const isSearchingForUtility = !isSearchingForColorScheme && tags.includes("utility");
return filtered.filter((theme) => {
if (isSearchingForColorScheme && theme.isColorTheme) return true;
if (isSearchingForUtility && !theme.isColorTheme) return true;
return false;
});
}
export async function getThemeFromId(id: string) {