mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
feat(assets): add image upload state management and update button behavior during upload
This commit is contained in:
@@ -109,6 +109,7 @@ export const AssetsPane = memo(function AssetsPane({
|
||||
const [youtubeUrl, setYoutubeUrl] = useState('');
|
||||
const [youtubeTitle, setYoutubeTitle] = useState('');
|
||||
const [bunnyTitle, setBunnyTitle] = useState('');
|
||||
const [isUploadingImage, setIsUploadingImage] = useState(false);
|
||||
const [isUploadingBunny, setIsUploadingBunny] = useState(false);
|
||||
const [bunnyProgress, setBunnyProgress] = useState(0);
|
||||
const [bunnyProcessingByAssetId, setBunnyProcessingByAssetId] = useState<Record<string, boolean>>({});
|
||||
@@ -290,6 +291,7 @@ export const AssetsPane = memo(function AssetsPane({
|
||||
return;
|
||||
}
|
||||
|
||||
setIsUploadingImage(true);
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('image', file);
|
||||
@@ -319,6 +321,8 @@ export const AssetsPane = memo(function AssetsPane({
|
||||
} catch (error) {
|
||||
console.error('Failed to upload image asset:', error);
|
||||
toast.error('Failed to upload image');
|
||||
} finally {
|
||||
setIsUploadingImage(false);
|
||||
}
|
||||
}, [videoId, getGuestUploadToken, createAsset, imageTitle]);
|
||||
|
||||
@@ -807,7 +811,7 @@ export const AssetsPane = memo(function AssetsPane({
|
||||
<Button
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
disabled={isCreatingAsset}
|
||||
disabled={isUploadingImage || isCreatingAsset}
|
||||
onClick={() => {
|
||||
if (pendingImageFile) {
|
||||
void handleImageUpload(pendingImageFile);
|
||||
@@ -816,8 +820,10 @@ export const AssetsPane = memo(function AssetsPane({
|
||||
imageInputRef.current?.click();
|
||||
}}
|
||||
>
|
||||
<UploadCloud className="h-4 w-4 mr-2" />
|
||||
{pendingImageFile ? 'Upload Image' : 'Select Image'}
|
||||
{isUploadingImage || isCreatingAsset
|
||||
? <Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||
: <UploadCloud className="h-4 w-4 mr-2" />}
|
||||
{isUploadingImage ? 'Uploading...' : isCreatingAsset ? 'Saving...' : pendingImageFile ? 'Upload Image' : 'Select Image'}
|
||||
</Button>
|
||||
<input
|
||||
ref={imageInputRef}
|
||||
|
||||
Reference in New Issue
Block a user