-
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.
Fix: add unsupported icon for resource can't that generate the thumbnail
Related Issues: - #25
- Loading branch information
Showing
15 changed files
with
99 additions
and
27 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
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,8 +1,7 @@ | ||
export * from './icons'; | ||
export * from './thumbnail'; | ||
export * from './ResponsiveImage'; | ||
export * from './YoutubeThunbnail'; | ||
export * from './EditableText'; | ||
export * from './ResourceThumbnailDisplayer'; | ||
export * from './DateTimeDisplayer'; | ||
export * from './TagTypography'; | ||
export * from './SubTitle'; |
25 changes: 25 additions & 0 deletions
25
src/components/display/thumbnail/LocalFileThumbnailDisplayer.tsx
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
import { LocalImageThumbnail, LocalUnsupportThumbnail } from './file'; | ||
import { LocalThumbnailProps } from './file/types'; | ||
|
||
const LOCAL_MEDIA_TYPE = new Map<string, typeof LocalImageThumbnail>(); | ||
|
||
LOCAL_MEDIA_TYPE.set('image/jpeg', LocalImageThumbnail); | ||
LOCAL_MEDIA_TYPE.set('image/png', LocalImageThumbnail); | ||
LOCAL_MEDIA_TYPE.set('image/gif', LocalImageThumbnail); | ||
|
||
interface LocalFileThumbnailDisplayerProps extends LocalThumbnailProps { | ||
mediaType: string; | ||
} | ||
|
||
export function LocalFileThumbnailDisplayer(props: LocalFileThumbnailDisplayerProps) { | ||
const { filePath, mediaType, ...imgProps } = props; | ||
|
||
if (LOCAL_MEDIA_TYPE.has(mediaType) === false) { | ||
return <LocalUnsupportThumbnail mediaType={mediaType} {...imgProps} />; | ||
} | ||
|
||
const Thumbnail = LOCAL_MEDIA_TYPE.get(mediaType)!; | ||
|
||
return <Thumbnail filePath={filePath} {...imgProps} />; | ||
} |
29 changes: 29 additions & 0 deletions
29
src/components/display/thumbnail/ResourceThumbnailDisplayer.tsx
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
import { ResponsiveImageProps } from '@components/display'; | ||
|
||
import { YoutubeThumbnail } from './url'; | ||
import { LocalFileThumbnailDisplayer } from './LocalFileThumbnailDisplayer'; | ||
|
||
export interface ResourceThumbnailDisplayerProps extends ResponsiveImageProps { | ||
url?: string | undefined | null; | ||
|
||
filePath?: string | undefined | null; | ||
|
||
mediaType?: string; | ||
} | ||
|
||
export function ResourceThumbnailDisplayer(props: ResourceThumbnailDisplayerProps) { | ||
const { url, filePath, mediaType, ...imgProps } = props; | ||
|
||
return ( | ||
url | ||
? <YoutubeThumbnail url={url!} {...imgProps} /> | ||
: ( | ||
<LocalFileThumbnailDisplayer | ||
mediaType={mediaType!} | ||
filePath={filePath!} | ||
{...imgProps} | ||
/> | ||
) | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/components/display/thumbnail/file/LocalImageThumbnail.tsx
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
import { convertFileSrc } from '@tauri-apps/api/tauri'; | ||
import { ResponsiveImage } from '@components/display'; | ||
import { LocalThumbnailProps } from './types'; | ||
|
||
export function LocalImageThumbnail(props: LocalThumbnailProps) { | ||
const { filePath, ...imgProps } = props; | ||
return <ResponsiveImage src={convertFileSrc(filePath)} {...imgProps} />; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/components/display/thumbnail/file/LocalUnsupportThumbnail.tsx
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
import { ResponsiveImage, ResponsiveImageProps } from '@components/display/ResponsiveImage'; | ||
import UnsupportImage from '@assets/icons/not-supported-icon.png'; | ||
|
||
export interface LocalUnsupportThumbnailProps extends Omit<ResponsiveImageProps, 'src' | 'ref'> { | ||
mediaType: string; | ||
} | ||
|
||
export function LocalUnsupportThumbnail(props: LocalUnsupportThumbnailProps) { | ||
const { mediaType, ...imgProps } = props; | ||
|
||
return (<ResponsiveImage src={UnsupportImage} {...imgProps} alt={mediaType} />); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './LocalUnsupportThumbnail'; | ||
export * from './LocalImageThumbnail'; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ResponsiveImageProps } from '@components/display/ResponsiveImage'; | ||
|
||
export interface LocalThumbnailProps extends Omit<ResponsiveImageProps, 'src' | 'ref'> { | ||
filePath: string; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './file'; | ||
export * from './url'; | ||
export * from './ResourceThumbnailDisplayer'; |
5 changes: 2 additions & 3 deletions
5
src/components/display/YoutubeThunbnail.tsx → ...isplay/thumbnail/url/YoutubeThunbnail.tsx
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './YoutubeThunbnail'; |
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