diff --git a/web/src/api/media.ts b/web/src/api/media.ts index fca3c1d..0dfbb2d 100644 --- a/web/src/api/media.ts +++ b/web/src/api/media.ts @@ -1,4 +1,4 @@ -import { useHttp } from './core'; +import { useQuery } from '@tanstack/react-query'; type MediaResponse = { id: number; @@ -6,5 +6,24 @@ type MediaResponse = { url: string; }; -export const useMedia = (id: string) => - useHttp('/api/media/' + id); +export const useMedia = (id: number) => + // useHttp('/api/media/' + id); + { + return useQuery({ + queryKey: ['media', id], + queryFn: () => { + return { + 1: { + id: 1, + description: 'test', + url: '/test.webp', + }, + 2: { + id: 2, + description: 'test2', + url: '/test.stl', + }, + }[id]; + }, + }); + }; diff --git a/web/src/components/media/MediaGallery.tsx b/web/src/components/media/MediaGallery.tsx index eeb4c51..0b8906a 100644 --- a/web/src/components/media/MediaGallery.tsx +++ b/web/src/components/media/MediaGallery.tsx @@ -4,8 +4,8 @@ import { MediaPreview } from './MediaPreview'; export const MediaGallery: FC<{ media_ids: number[] }> = ({ media_ids }) => { return ( -
-
+
+
{media_ids.map((media_id) => ( ))} diff --git a/web/src/components/media/MediaPreview.tsx b/web/src/components/media/MediaPreview.tsx index eef4b0f..b878996 100644 --- a/web/src/components/media/MediaPreview.tsx +++ b/web/src/components/media/MediaPreview.tsx @@ -1,10 +1,39 @@ import { FC } from 'react'; +import { match } from 'ts-pattern'; + +import { useMedia } from '../../api/media'; +import { StlPreview } from '../stl_preview/StlPreview'; export const MediaPreview: FC<{ media_id: number }> = ({ media_id }) => { + const { data: media } = useMedia(media_id); + + const fileType = media?.url.split('.').pop(); + + return ( +
+ {match(fileType) + .with('webp', () => ) + .with('stl', () => ) + .otherwise(() => ( +
+ Unknown file type + {fileType} +
+ ))} +
+ ); +}; + +export const ImagePreview: FC<{ media_id: number }> = ({ media_id }) => { + const { data: media } = useMedia(media_id); + return ( -
- MediaPreview - {media_id} +
+ {media?.description}
); }; diff --git a/web/src/components/stl_preview/StlPreview.tsx b/web/src/components/stl_preview/StlPreview.tsx index c102892..6293fc9 100644 --- a/web/src/components/stl_preview/StlPreview.tsx +++ b/web/src/components/stl_preview/StlPreview.tsx @@ -266,7 +266,7 @@ export const StlPreview = ({ stlUrl }: { stlUrl?: string }) => { }; return ( -
+