-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
import { useHttp } from './core'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
type MediaResponse = { | ||
id: number; | ||
description: string; | ||
url: string; | ||
}; | ||
|
||
export const useMedia = (id: string) => | ||
useHttp<MediaResponse>('/api/media/' + id); | ||
export const useMedia = (id: number) => | ||
// useHttp<MediaResponse>('/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]; | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div className="aspect-video bg-neutral-100 max-w-md w-full border border-neutral-200 rounded-md"> | ||
{match(fileType) | ||
.with('webp', () => <ImagePreview media_id={media_id} />) | ||
.with('stl', () => <StlPreview stlUrl={media?.url} />) | ||
.otherwise(() => ( | ||
<div className="p-3"> | ||
<span>Unknown file type</span> | ||
<span>{fileType}</span> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export const ImagePreview: FC<{ media_id: number }> = ({ media_id }) => { | ||
const { data: media } = useMedia(media_id); | ||
|
||
return ( | ||
<div className="aspect-video bg-neutral-100"> | ||
MediaPreview | ||
{media_id} | ||
<div className="w-full h-full"> | ||
<img | ||
src={media?.url} | ||
alt={media?.description} | ||
className="w-full h-full object-contain" | ||
/> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters