-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upload support file list thumbnail; Image and ImageViewer support src…
… is File type (#2494) * feat(image): support Image.fallback or Image.src is a type of File * feat(image-viewer): support File * fix(image): fallback * fix(image): set hasError to be false on src change * feat(upload): thunbnail * fix(upload): image preview * fix(upload): preview click * fix(upload): preview * test: update snapshots
- Loading branch information
Showing
30 changed files
with
1,308 additions
and
228 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useEffect, useState } from 'react'; | ||
import log from '../_common/js/log'; | ||
import { getFileUrlByFileRaw } from '../_common/js/upload/utils'; | ||
|
||
export function useImagePreviewUrl(imgUrl: string | File) { | ||
const [previewUrl, setPreviewUrl] = useState(''); | ||
|
||
useEffect(() => { | ||
if (!imgUrl) return; | ||
if (typeof imgUrl === 'string') { | ||
setPreviewUrl(imgUrl); | ||
return; | ||
} | ||
getFileUrlByFileRaw(imgUrl).then( | ||
(url) => { | ||
setPreviewUrl(url); | ||
}, | ||
() => { | ||
log.error('Image', 'Image.src is not a valid file'); | ||
}, | ||
); | ||
}, [imgUrl]); | ||
|
||
return { previewUrl }; | ||
} | ||
|
||
export default useImagePreviewUrl; |
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
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
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
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
Oops, something went wrong.