diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index c419689..01b2138 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -26,6 +26,33 @@ const getCardComponent = (item: UserImage) => { } }; +// How wonderfully functional +const getAllValues = (object: object): Array => { + const loop = (acc: Array, next: object): Array => { + for (const _value of Object.values(next)) { + const value: unknown = _value; + switch (typeof value) { + case "object": + if (value != null) { + acc.push(...loop(acc, value)); + } + break; + case "string": + case "number": + case "boolean": + acc.push(value.toString()); + break; + default: + break; + } + } + + return acc; + }; + + return loop([], object); +}; + function App() { const [searchResults, setSearchResults] = createSignal([]); const [searchQuery, setSearchQuery] = createSignal(""); @@ -33,16 +60,29 @@ function App() { null, ); - const [data] = createResource(getUserImages); + const [data] = createResource(() => + getUserImages().then((data) => + data.map((d) => ({ + ...d, + rawData: getAllValues(d), + })), + ), + ); let fuze = new Fuse(data() ?? [], { - keys: [{ name: "title", weight: 2 }, "data"], + keys: [ + { name: "rawData", weight: 1 }, + { name: "title", weight: 1 }, + ], threshold: 0.4, }); createEffect(() => { fuze = new Fuse(data() ?? [], { - keys: [{ name: "data.Name", weight: 2 }], + keys: [ + { name: "data.Name", weight: 2 }, + { name: "rawData", weight: 1 }, + ], threshold: 0.4, }); });