mirror of
https://github.com/balzack/databag.git
synced 2025-04-23 18:15:19 +00:00
added image file component
This commit is contained in:
parent
1be6ab4770
commit
21b4d1a4b6
@ -0,0 +1,9 @@
|
||||
.asset {
|
||||
padding-top: 16px;
|
||||
|
||||
.thumb {
|
||||
width: auto;
|
||||
height: 64px;
|
||||
}
|
||||
}
|
||||
|
17
app/client/web/src/conversation/imageFile/ImageFile.tsx
Normal file
17
app/client/web/src/conversation/imageFile/ImageFile.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
import React from 'react';
|
||||
import { Image } from '@mantine/core'
|
||||
import { useImageFile } from './useImageFile.hook';
|
||||
import classes from './ImageFile.module.css'
|
||||
|
||||
export function ImageFile({ source }: {source: File}) {
|
||||
const { state, actions } = useImageFile(source);
|
||||
|
||||
return (
|
||||
<div className={classes.asset}>
|
||||
{ state.thumbUrl && (
|
||||
<Image radius="sm" className={classes.thumb} src={state.thumbUrl} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
export function useImageFile(source: File) {
|
||||
const [state, setState] = useState({
|
||||
thumbUrl: null,
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const updateState = (value: any) => {
|
||||
setState((s) => ({ ...s, ...value }))
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const thumbUrl = URL.createObjectURL(source);
|
||||
updateState({ thumbUrl });
|
||||
return () => { URL.revokeObjectURL(thumbUrl) };
|
||||
}, [source]);
|
||||
|
||||
const actions = {
|
||||
}
|
||||
|
||||
return { state, actions }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user