Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

create useFakeProgressHook

Sara Vieirab3f6c145ef4a
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsx b/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsx
index 3fba23a610..e823778ce5 100644
--- a/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsx
+++ b/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsx
@@ -26,6 +26,28 @@ const useImageWithFallback = ({ path }: { path: string }) => {
return src;
};
+export const useFakeProgress = ({
+ isUploading,
+ isDeleting,
+}: {
+ isUploading: boolean;
+ isDeleting: boolean;
+}) => {
+ const [progressBarPercentage, setProgressBarPercentage] = useState(0);
+
+ // @todo rewrite this fake indication to show real progress
+ useInterval(
+ () => {
+ setProgressBarPercentage((percentage) =>
+ percentage < 60 ? percentage + 1 : percentage
+ );
+ },
+ isUploading || isDeleting ? 100 : null
+ );
+
+ return progressBarPercentage;
+};
+
export const AssetManagerThumbnail = ({
path,
alt,
@@ -34,24 +56,14 @@ export const AssetManagerThumbnail = ({
id,
}: Asset) => {
const submit = useSubmit();
+ const [isDeleting, setIsDeleting] = useState(false);
const isUploading = status === "uploading";
const src = useImageWithFallback({ path });
const [isTooltipOpen, setTolltipOpen] = useState(false);
- const [isDeleting, setIsDeleting] = useState(false);
- const [progressBarPercentage, setProgressBarPercentage] = useState(0);
+ const progressBarPercentage = useFakeProgress({ isUploading, isDeleting });
const closeTooltip = () => setTolltipOpen(false);
- // @todo rewrite this fake indication to show real progress
- useInterval(
- () => {
- setProgressBarPercentage((percentage) =>
- percentage < 60 ? percentage + 1 : percentage
- );
- },
- isUploading || isDeleting ? 100 : null
- );
-
const deleteAsset = () => {
const formData = new FormData();
formData.append("assetId", id);