From 325551c654b3f6ef2b2d2a0904620e81a5774922 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sat, 1 Jul 2023 19:26:45 +0800 Subject: [PATCH] Fix more components Streamline mounting of components for file preview components. --- .../components/AudioFilePreview/index.tsx | 31 ++- .../components/AudioMiniFilePreview/index.tsx | 220 ++++++++++++++++-- .../components/BinaryFilePreview/index.tsx | 15 +- .../react/components/FilePreview/index.tsx | 42 +--- .../react/components/FileSelectBox/index.tsx | 193 +++++++-------- .../components/ImageFilePreview/index.tsx | 172 ++++++++++---- .../components/TextFilePreview/index.tsx | 11 +- .../components/VideoFilePreview/index.tsx | 21 +- .../blob/react/hooks/blob/metadata.ts | 14 +- .../blob/react/hooks/interactive/image.ts | 10 + .../blob/react/hooks/interactive/media.ts | 81 +++---- .../src/categories/blob/react/index.ts | 4 +- .../components/MaskedTextInput/index.tsx | 2 - .../number/react/components/Spinner/index.tsx | 20 +- .../react/components/Spinner/style.module.css | 12 + .../src/categories/number/react/index.ts | 1 + .../src/packages/react-refractor/index.tsx | 1 - .../src/packages/react-utils/index.ts | 17 ++ .../SpectrogramCanvas/index.tsx | 81 ++++--- .../react-wavesurfer/WaveformCanvas/index.tsx | 69 +++--- .../src/pages/categories/blob/index.tsx | 18 +- .../src/pages/categories/number/index.tsx | 15 +- .../src/utils/blob.ts | 23 +- .../tailwind.config.js | 1 + 24 files changed, 676 insertions(+), 398 deletions(-) create mode 100644 packages/web-kitchensink-reactnext/src/categories/number/react/components/Spinner/style.module.css create mode 100644 packages/web-kitchensink-reactnext/src/packages/react-utils/index.ts diff --git a/packages/web-kitchensink-reactnext/src/categories/blob/react/components/AudioFilePreview/index.tsx b/packages/web-kitchensink-reactnext/src/categories/blob/react/components/AudioFilePreview/index.tsx index b8dd03e..c658fbc 100644 --- a/packages/web-kitchensink-reactnext/src/categories/blob/react/components/AudioFilePreview/index.tsx +++ b/packages/web-kitchensink-reactnext/src/categories/blob/react/components/AudioFilePreview/index.tsx @@ -14,16 +14,17 @@ import clsx from 'clsx'; import {SpectrogramCanvas, WaveformCanvas} from '@modal-soft/react-wavesurfer'; import {Slider} from '@/categories/number/react'; import {KeyValueTable} from '@/categories/information/react'; +import {useEnhanced} from '@modal-soft/react-utils'; -type AudioFilePreviewDerivedComponent = HTMLAudioElement; +type AudioFilePreviewDerivedElement = HTMLAudioElement; -export interface AudioFilePreviewProps = Partial> extends Omit, 'controls'> { +export interface AudioFilePreviewProps = Partial> extends Omit, 'controls'> { file?: F; disabled?: boolean; enhanced?: boolean; } -export const AudioFilePreview = React.forwardRef(({ +export const AudioFilePreview = React.forwardRef(({ file, style, className, @@ -58,16 +59,12 @@ export const AudioFilePreview = React.forwardRef({ controllerRef: forwardedRef, visualizationMode: 'waveform', }); - const formId = React.useId(); - - const [enhanced, setEnhanced] = React.useState(false); - React.useEffect(() => { - setEnhanced(enhancedProp); - }, [enhancedProp]); + const { enhanced } = useEnhanced({ enhanced: enhancedProp }); if (!fileWithMetadata) { return null; @@ -90,11 +87,10 @@ export const AudioFilePreview = React.forwardRef