Skip to content

Commit

Permalink
Disable upload button during upload
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Weimann <michael.weimann@nordeck.net>
  • Loading branch information
weeman1337 committed Aug 28, 2024
1 parent 61ee791 commit d3462dd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions example-widget-mui/src/ImagePage/ImagePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const ImagePage = (): ReactElement => {
const handleFileUpload = useCallback(() => {
const uploadImage = async () => {
if (selectedFile) {
setLoading(true);
if (!selectedFile.type.startsWith('image/')) {
setErrorMessage(
'Please select a valid image file. You can upload any image format that is supported by the browser.',
Expand Down Expand Up @@ -103,18 +104,17 @@ export const ImagePage = (): ReactElement => {
const responseUploadMedia = await widgetApi.uploadFile(selectedFile);
const url = responseUploadMedia.content_uri;

setLoading(true);
await widgetApi.sendRoomEvent<UploadedImageEvent>(
ROOM_EVENT_UPLOADED_IMAGE,
{ name: selectedFile.name, size: selectedFile.size, url },
);
setLoading(false);
setSelectedFile(null);

return;
setSelectedFile(null);
} catch (error) {
setErrorMessage('An error occurred during file upload: ' + error);
setErrorDialogOpen(true);
} finally {
setLoading(false);
}
}
};
Expand Down

0 comments on commit d3462dd

Please sign in to comment.