diff --git a/frontend/src/network/index.ts b/frontend/src/network/index.ts index 17181e2..04c17e8 100644 --- a/frontend/src/network/index.ts +++ b/frontend/src/network/index.ts @@ -141,29 +141,26 @@ const dataTypeValidator = variant("type", [ export type CategoryUnion = InferOutput; +const imageMetaValidator = strictObject({ + ID: pipe(string(), uuid()), + ImageName: string(), + Description: string(), + Image: null_(), +}); + const userImageValidator = strictObject({ ID: pipe(string(), uuid()), CreatedAt: pipe(string()), ImageID: pipe(string(), uuid()), UserID: pipe(string(), uuid()), - Image: strictObject({ - ID: pipe(string(), uuid()), - ImageName: string(), - Description: string(), - Image: null_(), - }), + Image: imageMetaValidator, }); const userProcessingImageValidator = strictObject({ ID: pipe(string(), uuid()), ImageID: pipe(string(), uuid()), UserID: pipe(string(), uuid()), - Image: strictObject({ - ID: pipe(string(), uuid()), - ImageName: string(), - Description: string(), - Image: null_(), - }), + Image: imageMetaValidator, Status: union([ literal("not-started"), literal("in-progress"), diff --git a/frontend/src/pages/search/search.ts b/frontend/src/pages/search/search.ts index bbd23ce..2e9e92c 100644 --- a/frontend/src/pages/search/search.ts +++ b/frontend/src/pages/search/search.ts @@ -1,7 +1,6 @@ import { useSearchImageContext } from "@contexts/SearchImageContext"; import { UserImage } from "@network/index"; import Fuse from "fuse.js"; -import { createEffect } from "solid-js"; // This language is stupid. `keyof` only returns common keys but this somehow doesnt. type KeysOfUnion = T extends T ? keyof T : never; @@ -15,8 +14,9 @@ const weightedTerms: Record< OrganizerID: undefined, Images: undefined, + Description: 10, + Name: 5, - Description: 2, Address: 2, PhoneNumber: 2, @@ -25,15 +25,16 @@ const weightedTerms: Record< CreatedAt: 1, StartDateTime: 1, EndDateTime: 1, - - Content: 1, }; export const useSearch = () => { - const { images } = useSearchImageContext(); + const { images, userImages } = useSearchImageContext(); + + const imageDescriptions = () => + userImages().map((i) => ({ data: { Description: i.Image.Description } })); return () => - new Fuse(images(), { + new Fuse([...images(), ...imageDescriptions()], { shouldSort: true, keys: Object.entries(weightedTerms) .filter(([, w]) => w != null)