From 61d2b81e8cd0398b706fbf4e3d715772a0343054 Mon Sep 17 00:00:00 2001 From: John Costa Date: Mon, 25 Aug 2025 14:31:11 +0100 Subject: [PATCH] better handling of empty lists --- backend/models/user.go | 4 ++-- frontend/src/contexts/SearchImageContext.tsx | 5 ++++ frontend/src/network/index.ts | 24 ++++++++++++-------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/backend/models/user.go b/backend/models/user.go index 9b10e3b..050e4e8 100644 --- a/backend/models/user.go +++ b/backend/models/user.go @@ -104,10 +104,10 @@ func (m UserModel) ListWithImages(ctx context.Context, userId uuid.UUID) ([]List ). FROM( Lists. - INNER_JOIN(ImageLists, ImageLists.ListID.EQ(Lists.ID)). INNER_JOIN(Schemas, Schemas.ListID.EQ(Lists.ID)). INNER_JOIN(SchemaItems, SchemaItems.SchemaID.EQ(Schemas.ID)). - INNER_JOIN(ImageSchemaItems, ImageSchemaItems.ImageID.EQ(ImageLists.ImageID)), + LEFT_JOIN(ImageLists, ImageLists.ListID.EQ(Lists.ID)). + LEFT_JOIN(ImageSchemaItems, ImageSchemaItems.ImageID.EQ(ImageLists.ImageID)), ). WHERE(Lists.UserID.EQ(UUID(userId))) diff --git a/frontend/src/contexts/SearchImageContext.tsx b/frontend/src/contexts/SearchImageContext.tsx index c3d8869..83f5d7f 100644 --- a/frontend/src/contexts/SearchImageContext.tsx +++ b/frontend/src/contexts/SearchImageContext.tsx @@ -3,6 +3,7 @@ import { type Component, type ParentProps, createContext, + createEffect, createMemo, createResource, useContext, @@ -29,6 +30,10 @@ const SearchImageContext = createContext(); export const SearchImageContextProvider: Component = (props) => { const [data, { refetch }] = createResource(getUserImages); + createEffect(() => { + console.log(data()); + }); + const sortedImages = createMemo>( () => { const d = data(); diff --git a/frontend/src/network/index.ts b/frontend/src/network/index.ts index 60b0038..612c269 100644 --- a/frontend/src/network/index.ts +++ b/frontend/src/network/index.ts @@ -10,6 +10,7 @@ import { pipe, strictObject, string, + transform, union, uuid, } from "valibot"; @@ -127,20 +128,25 @@ const listValidator = strictObject({ Name: string(), Description: nullable(string()), - Images: array( - strictObject({ - ID: pipe(string(), uuid()), - ImageID: pipe(string(), uuid()), - ListID: pipe(string(), uuid()), - Items: array( + Images: pipe( + nullable( + array( strictObject({ ID: pipe(string(), uuid()), ImageID: pipe(string(), uuid()), - SchemaItemID: pipe(string(), uuid()), - Value: string(), + ListID: pipe(string(), uuid()), + Items: array( + strictObject({ + ID: pipe(string(), uuid()), + ImageID: pipe(string(), uuid()), + SchemaItemID: pipe(string(), uuid()), + Value: string(), + }), + ), }), ), - }), + ), + transform((n) => n ?? []), ), Schema: strictObject({