feat: adding rawData search
This commit is contained in:
@ -26,6 +26,33 @@ const getCardComponent = (item: UserImage) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// How wonderfully functional
|
||||||
|
const getAllValues = (object: object): Array<string> => {
|
||||||
|
const loop = (acc: Array<string>, next: object): Array<string> => {
|
||||||
|
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() {
|
function App() {
|
||||||
const [searchResults, setSearchResults] = createSignal<UserImage[]>([]);
|
const [searchResults, setSearchResults] = createSignal<UserImage[]>([]);
|
||||||
const [searchQuery, setSearchQuery] = createSignal("");
|
const [searchQuery, setSearchQuery] = createSignal("");
|
||||||
@ -33,16 +60,29 @@ function App() {
|
|||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
|
||||||
const [data] = createResource(getUserImages);
|
const [data] = createResource(() =>
|
||||||
|
getUserImages().then((data) =>
|
||||||
|
data.map((d) => ({
|
||||||
|
...d,
|
||||||
|
rawData: getAllValues(d),
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
let fuze = new Fuse<UserImage>(data() ?? [], {
|
let fuze = new Fuse<UserImage>(data() ?? [], {
|
||||||
keys: [{ name: "title", weight: 2 }, "data"],
|
keys: [
|
||||||
|
{ name: "rawData", weight: 1 },
|
||||||
|
{ name: "title", weight: 1 },
|
||||||
|
],
|
||||||
threshold: 0.4,
|
threshold: 0.4,
|
||||||
});
|
});
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
fuze = new Fuse<UserImage>(data() ?? [], {
|
fuze = new Fuse<UserImage>(data() ?? [], {
|
||||||
keys: [{ name: "data.Name", weight: 2 }],
|
keys: [
|
||||||
|
{ name: "data.Name", weight: 2 },
|
||||||
|
{ name: "rawData", weight: 1 },
|
||||||
|
],
|
||||||
threshold: 0.4,
|
threshold: 0.4,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user