From 9b1ba349328ba7cc795efcadceb1c2d7cd466166 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Fri, 27 Jun 2025 09:31:39 +0200 Subject: [PATCH] running dev environment --- frontend/tsconfig.json | 8 +++++-- frontend/vite.config.ts | 7 ++++++- lib/src/Components/Auth/index.tsx | 2 ++ .../Profile/Subcomponents/GalleryForm.tsx | 4 +++- .../Profile/Subcomponents/GalleryView.tsx | 21 +++++++++++++------ lib/src/Components/Profile/itemFunctions.ts | 2 +- lib/src/types/Item.d.ts | 14 +++++++------ 7 files changed, 41 insertions(+), 17 deletions(-) diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index e9b25bfb..fefa4124 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -13,8 +13,12 @@ "noFallthroughCasesInSwitch": true, "paths": { "utopia-ui": ["../lib/src"], - "utopia-ui/types": ["../lib/src/types"], - "utopia-ui/types/*": ["../lib/src/types/*"] + "#components/*": ["../lib/src/Components/*"], + "#utils/*": ["../lib/src/Utils/*"], + "#types/*": ["../lib/src/types/*"], + "#assets/*": ["../lib/src/assets/*"], + "#src/*": ["../lib/src/*"], + "#root/*": ["../lib/*"] } }, "include": ["src"], diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 8509e990..1c47d087 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -25,7 +25,12 @@ export default defineConfig({ resolve: { alias: { 'utopia-ui': path.resolve(__dirname, '../lib/src'), - + '#components': path.resolve(__dirname, '../lib/src/Components'), + '#utils': path.resolve(__dirname, '../lib/src/Utils'), + '#types': path.resolve(__dirname, '../lib/src/types'), + '#assets': path.resolve(__dirname, '../lib/src/assets'), + '#src': path.resolve(__dirname, '../lib/src'), + '#root': path.resolve(__dirname, '../lib'), } } }); diff --git a/lib/src/Components/Auth/index.tsx b/lib/src/Components/Auth/index.tsx index ae8a8d02..d1029e26 100644 --- a/lib/src/Components/Auth/index.tsx +++ b/lib/src/Components/Auth/index.tsx @@ -3,3 +3,5 @@ export { LoginPage } from './LoginPage' export { SignupPage } from './SignupPage' export { RequestPasswordPage } from './RequestPasswordPage' export { SetNewPasswordPage } from './SetNewPasswordPage' +export type { UserItem } from '#types/UserItem' +export type { UserApi } from '#types/UserApi' diff --git a/lib/src/Components/Profile/Subcomponents/GalleryForm.tsx b/lib/src/Components/Profile/Subcomponents/GalleryForm.tsx index e252d790..a118c5dc 100644 --- a/lib/src/Components/Profile/Subcomponents/GalleryForm.tsx +++ b/lib/src/Components/Profile/Subcomponents/GalleryForm.tsx @@ -76,7 +76,9 @@ export const GalleryForm = ({ state, setState }: Props) => { const images = state.gallery .map((image) => ({ - src: appState.assetsApi.url + `${image.directus_files_id.id}.jpg`, + src: + typeof image.directus_files_id !== 'string' && + appState.assetsApi.url + `${image.directus_files_id.id}.jpg`, state: 'uploaded', })) .concat( diff --git a/lib/src/Components/Profile/Subcomponents/GalleryView.tsx b/lib/src/Components/Profile/Subcomponents/GalleryView.tsx index 13549cb0..c3fca484 100644 --- a/lib/src/Components/Profile/Subcomponents/GalleryView.tsx +++ b/lib/src/Components/Profile/Subcomponents/GalleryView.tsx @@ -23,12 +23,21 @@ export const GalleryView = ({ item }: { item: Item }) => { const [index, setIndex] = useState(-1) const appState = useAppState() const images = - item.gallery?.map(({ directus_files_id: { id, type, width, height } }, index) => ({ - src: `${appState.assetsApi.url}${id}${getExtension(type)}`, - width, - height, - index, - })) ?? [] + item.gallery?.flatMap((g, index) => { + const file = g.directus_files_id + // if it's just a string, skip it + if (typeof file === 'string') return [] + // otherwise it's the object you want + const { id, type, width, height } = file + return [ + { + src: `${appState.assetsApi.url}${id}${getExtension(type)}`, + width, + height, + index, + }, + ] + }) ?? [] if (images.length > 0) return ( diff --git a/lib/src/Components/Profile/itemFunctions.ts b/lib/src/Components/Profile/itemFunctions.ts index 7f3d2dd3..51045c04 100644 --- a/lib/src/Components/Profile/itemFunctions.ts +++ b/lib/src/Components/Profile/itemFunctions.ts @@ -200,7 +200,7 @@ export const onUpdateItem = async ( ...(state.needs.length > 0 && { needs: needsUpdates }), ...(state.openCollectiveSlug && { openCollectiveSlug: state.openCollectiveSlug }), gallery: state.gallery.map((i) => ({ - directus_files_id: i.directus_files_id.id, + directus_files_id: typeof i.directus_files_id !== 'string' && i.directus_files_id.id, })), } diff --git a/lib/src/types/Item.d.ts b/lib/src/types/Item.d.ts index be3d6194..7dd9dcf1 100644 --- a/lib/src/types/Item.d.ts +++ b/lib/src/types/Item.d.ts @@ -8,12 +8,14 @@ import type { Point } from 'geojson' type TagIds = { tags_id: string }[] interface GalleryItem { - directus_files_id: { - id: string - width: number - height: number - type: string - } + directus_files_id: + | { + id: string + width: number + height: number + type: string + } + | string } /**