Use{" "}
diff --git a/frontend/src/contexts/SearchImageContext.tsx b/frontend/src/contexts/SearchImageContext.tsx
index debdbbb..63dcc8b 100644
--- a/frontend/src/contexts/SearchImageContext.tsx
+++ b/frontend/src/contexts/SearchImageContext.tsx
@@ -1,19 +1,25 @@
import {
- createContext,
- type Resource,
+ type Accessor,
type Component,
type ParentProps,
+ createContext,
+ createMemo,
createResource,
useContext,
} from "solid-js";
import { getUserImages } from "../network";
+import { groupPropertiesWithImage } from "../utils/groupPropertiesWithImage";
-type ImageWithRawData = Awaited>[number] & {
+export type ImageWithRawData = Awaited<
+ ReturnType
+>["ImageProperties"][number] & {
rawData: string[];
};
type SearchImageStore = {
- images: Resource;
+ images: Accessor;
+
+ imagesWithProperties: Accessor>;
onRefetchImages: () => void;
};
@@ -50,19 +56,36 @@ const getAllValues = (object: object): Array => {
const SearchImageContext = createContext();
export const SearchImageContextProvider: Component = (props) => {
- const [images, { refetch }] = createResource(() =>
- getUserImages().then((data) => {
- return data.map((d) => ({
- ...d,
- rawData: getAllValues(d),
- }));
- }),
- );
+ const [data, { refetch }] = createResource(getUserImages);
+
+ const imageData = createMemo(() => {
+ const d = data();
+ if (d == null) {
+ return [];
+ }
+
+ return d.ImageProperties.map((d) => ({
+ ...d,
+ rawData: getAllValues(d),
+ }));
+ });
+
+ const imagesWithProperties = createMemo<
+ ReturnType
+ >(() => {
+ const d = data();
+ if (d == null) {
+ return {};
+ }
+
+ return groupPropertiesWithImage(d);
+ });
return (
diff --git a/frontend/src/network/index.ts b/frontend/src/network/index.ts
index 7fd7a94..03f3de2 100644
--- a/frontend/src/network/index.ts
+++ b/frontend/src/network/index.ts
@@ -4,6 +4,7 @@ import {
type InferOutput,
array,
literal,
+ null_,
nullable,
parse,
pipe,
@@ -84,6 +85,7 @@ export const sendImage = async (
const locationValidator = strictObject({
ID: pipe(string(), uuid()),
+ CreatedAt: pipe(string()),
Name: string(),
Address: nullable(string()),
Description: nullable(string()),
@@ -92,6 +94,7 @@ const locationValidator = strictObject({
const contactValidator = strictObject({
ID: pipe(string(), uuid()),
+ CreatedAt: pipe(string()),
Name: string(),
Description: nullable(string()),
PhoneNumber: nullable(string()),
@@ -101,6 +104,7 @@ const contactValidator = strictObject({
const eventValidator = strictObject({
ID: pipe(string(), uuid()),
+ CreatedAt: pipe(string()),
Name: string(),
StartDateTime: nullable(pipe(string())),
EndDateTime: nullable(pipe(string())),
@@ -114,6 +118,7 @@ const eventValidator = strictObject({
const noteValidator = strictObject({
ID: pipe(string(), uuid()),
+ CreatedAt: pipe(string()),
Name: string(),
Description: nullable(string()),
Content: string(),
@@ -146,18 +151,36 @@ const dataTypeValidator = variant("type", [
noteDataType,
contactDataType,
]);
-const getUserImagesResponseValidator = array(dataTypeValidator);
+
+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(),
+ Image: null_(),
+ }),
+});
export type UserImage = InferOutput;
-export const getUserImages = async (): Promise => {
+const imageRequestValidator = strictObject({
+ UserImages: array(userImageValidator),
+ ImageProperties: array(dataTypeValidator),
+});
+
+export const getUserImages = async (): Promise<
+ InferOutput
+> => {
const request = getBaseAuthorizedRequest({ path: "image" });
const res = await fetch(request).then((res) => res.json());
console.log("BACKEND RESPONSE: ", res);
- return parse(getUserImagesResponseValidator, res);
+ return parse(imageRequestValidator, res);
};
export const getImage = async (imageId: string): Promise => {
diff --git a/frontend/src/utils/groupPropertiesWithImage.ts b/frontend/src/utils/groupPropertiesWithImage.ts
new file mode 100644
index 0000000..962abe1
--- /dev/null
+++ b/frontend/src/utils/groupPropertiesWithImage.ts
@@ -0,0 +1,16 @@
+import type { getUserImages } from "../network";
+
+export const groupPropertiesWithImage = ({
+ UserImages,
+ ImageProperties,
+}: Awaited>) => {
+ const imageToProperties: Record = {};
+
+ for (const image of UserImages) {
+ imageToProperties[image.ImageID] = ImageProperties.filter((i) =>
+ i.data.Images.includes(image.ImageID),
+ );
+ }
+
+ return imageToProperties;
+};