wip: search page

This commit is contained in:
2025-07-21 14:38:02 +01:00
parent 5d0fa51e01
commit 251e2bc553
6 changed files with 103 additions and 44 deletions

View File

@@ -11,15 +11,10 @@ import {
CategoryUnion,
getUserImages,
JustTheImageWhatAreTheseNames,
UserImage,
} from "../network";
import { groupPropertiesWithImage } from "../utils/groupPropertiesWithImage";
export type ImageWithRawData = Awaited<
ReturnType<typeof getUserImages>
>["ImageProperties"][number] & {
rawData: string[];
};
type TaggedCategory<T extends CategoryUnion["type"]> = Extract<
CategoryUnion,
{ type: T }
@@ -30,7 +25,7 @@ type CategoriesSpecificData = {
};
export type SearchImageStore = {
images: Accessor<ImageWithRawData[]>;
images: Accessor<UserImage[]>;
userImages: Accessor<JustTheImageWhatAreTheseNames>;
@@ -44,51 +39,17 @@ export type SearchImageStore = {
onRefetchImages: () => void;
};
// How wonderfully functional
const getAllValues = (object: object): Array<string> => {
const loop = (acc: Array<string>, next: object): Array<string> => {
for (const [key, _value] of Object.entries(next)) {
if (key === "ID") {
continue;
}
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);
};
const SearchImageContext = createContext<SearchImageStore>();
export const SearchImageContextProvider: Component<ParentProps> = (props) => {
const [data, { refetch }] = createResource(getUserImages);
const imageData = createMemo<ImageWithRawData[]>(() => {
const imageData = createMemo(() => {
const d = data();
if (d == null) {
return [];
}
return d.ImageProperties.map((d) => ({
...d,
rawData: getAllValues(d),
}));
return d.ImageProperties;
});
const processingImages = () => data()?.ProcessingImages ?? [];