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.

cleanup

Sara Vieirab4754bbb7f5a
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/asset-manager.tsx b/apps/designer/app/designer/features/sidebar-left/panels/asset-manager.tsx
index 3033a75372..480ff5525e 100644
--- a/apps/designer/app/designer/features/sidebar-left/panels/asset-manager.tsx
+++ b/apps/designer/app/designer/features/sidebar-left/panels/asset-manager.tsx
@@ -4,6 +4,7 @@ import { ChangeEvent, useEffect, useRef, useState } from "react";
import { Form, useSubmit } from "@remix-run/react";
import type { Asset } from "@webstudio-is/prisma-client";
import { AssetManagerImage } from "./components/image";
+import ObjectID from "bson-objectid";
const readImages = async (fileList: FileList) => {
const images = [];
@@ -11,43 +12,49 @@ const readImages = async (fileList: FileList) => {
const path = await new Promise((resolve) => {
const reader = new FileReader();
reader.addEventListener("load", (event) => {
- resolve(event?.target?.result);
+ const dataUri = event?.target?.result;
+
+ resolve(dataUri);
});
reader.readAsDataURL(file);
});
- images.push({ path, name: file.name, size: file.size, uploading: true });
+ images.push({
+ path: path as string,
+ name: file.name,
+ id: ObjectID.toString(),
+ });
}
return images;
};
-export const TabContent = ({
- assets: baseAssets,
-}: {
- assets: Array<Asset>;
-}) => {
+type ParsedFiles = {
+ path: string;
+ name?: string;
+ id?: string;
+}[];
+
+export const TabContent = ({ assets }: { assets: Array<Asset> }) => {
const inputRef = useRef<HTMLInputElement | null>(null);
const submit = useSubmit();
- const [assets, setAssets] = useState(baseAssets);
-
- useEffect(() => {
- if (baseAssets.length === assets.length) {
- setAssets(baseAssets);
- }
- }, [baseAssets, assets.length]);
+ const [uploadedImages, setUploadedImages] = useState<ParsedFiles>([]);
const onFormChange = async (event: ChangeEvent<HTMLFormElement>) => {
const newFiles = inputRef?.current?.files;
if (newFiles) {
submit(event.currentTarget);
const parsedFiles = await readImages(newFiles);
- setAssets((assets) => [...parsedFiles, ...assets]);
+ setUploadedImages(parsedFiles);
- //event.currentTarget.reset();
+ event.currentTarget.reset();
}
};
+ useEffect(() => {
+ setUploadedImages([]);
+ }, [assets?.length]);
+
return (
<Flex gap="3" direction="column" css={{ padding: "$1" }}>
<Flex justify="between">
@@ -71,8 +78,15 @@ export const TabContent = ({
</Form>
</Flex>
<Grid columns={2} gap={2}>
+ {uploadedImages.map((asset) => (
+ <AssetManagerImage
+ key={asset.id}
+ path={asset.path}
+ uploading={true}
+ />
+ ))}
{assets.map((asset) => (
- <AssetManagerImage key={asset.id} asset={asset} />
+ <AssetManagerImage key={asset.id} path={asset.path} />
))}
</Grid>
</Flex>
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/components/image.tsx b/apps/designer/app/designer/features/sidebar-left/panels/components/image.tsx
index f1ecb611da..5b2d1e2418 100644
--- a/apps/designer/app/designer/features/sidebar-left/panels/components/image.tsx
+++ b/apps/designer/app/designer/features/sidebar-left/panels/components/image.tsx
@@ -1,4 +1,3 @@
-import { Asset } from "@webstudio-is/prisma-client";
import { useEffect, useState } from "react";
import { Box, ProgressBar } from "~/shared/design-system";
import placholderImage from "~/shared/images/image-placeholder.svg";
@@ -18,18 +17,30 @@ const useImageWithFallback = ({ path }: { path: string }) => {
};
export const AssetManagerImage = ({
- asset: { path, alt, uploading },
+ path,
+ alt,
+ uploading,
}: {
- asset: Asset;
+ path: string;
+ alt?: string;
+ uploading?: boolean;
}) => {
const src = useImageWithFallback({ path });
+ const [progressBarPercentage, setProgressBarPercentage] = useState(0);
+
+ useEffect(() => {
+ setInterval(() => {
+ if (progressBarPercentage < 60) {
+ setProgressBarPercentage((percentage) => percentage + 1);
+ }
+ }, 100);
+ }, []);
+
return (
<Box
title={alt || ""}
css={{
- opacity: uploading ? 0.5 : 1,
aspectRatio: "1/1",
-
backgroundImage: `url(${src})`,
backgroundSize: "contain",
backgroundRepeat: "no-repeat",
@@ -40,7 +51,13 @@ export const AssetManagerImage = ({
padding: "0 $2",
}}
>
- <ProgressBar css={{ width: "100%" }} />
+ {uploading && (
+ <ProgressBar
+ value={progressBarPercentage}
+ max={60}
+ css={{ width: "100%", height: "$1" }}
+ />
+ )}
</Box>
);
};