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.

start loading work

Sara Vieira7119620f6e96
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 cbda921c0e..3033a75372 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
@@ -1,13 +1,52 @@
import { ImageIcon } from "~/shared/icons";
import { Button, Flex, Grid, Heading } from "~/shared/design-system";
-import { useRef } from "react";
+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";
-export const TabContent = ({ assets }: { assets: Array<Asset> }) => {
+const readImages = async (fileList: FileList) => {
+ const images = [];
+ for (const file of fileList) {
+ const path = await new Promise((resolve) => {
+ const reader = new FileReader();
+ reader.addEventListener("load", (event) => {
+ resolve(event?.target?.result);
+ });
+ reader.readAsDataURL(file);
+ });
+
+ images.push({ path, name: file.name, size: file.size, uploading: true });
+ }
+
+ return images;
+};
+
+export const TabContent = ({
+ assets: baseAssets,
+}: {
+ 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 onFormChange = async (event: ChangeEvent<HTMLFormElement>) => {
+ const newFiles = inputRef?.current?.files;
+ if (newFiles) {
+ submit(event.currentTarget);
+ const parsedFiles = await readImages(newFiles);
+ setAssets((assets) => [...parsedFiles, ...assets]);
+
+ //event.currentTarget.reset();
+ }
+ };
return (
<Flex gap="3" direction="column" css={{ padding: "$1" }}>
@@ -16,12 +55,7 @@ export const TabContent = ({ assets }: { assets: Array<Asset> }) => {
<Form
method="post"
encType="multipart/form-data"
- onChange={(event) => {
- if (inputRef.current?.files) {
- submit(event.currentTarget);
- event.currentTarget.reset();
- }
- }}
+ onChange={onFormChange}
>
<input
accept="image/*"
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 c4e5e75195..f1ecb611da 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,6 +1,6 @@
import { Asset } from "@webstudio-is/prisma-client";
import { useEffect, useState } from "react";
-import { Box } from "~/shared/design-system";
+import { Box, ProgressBar } from "~/shared/design-system";
import placholderImage from "~/shared/images/image-placeholder.svg";
import brokenImage from "~/shared/images/broken-image-placeholder.svg";
@@ -18,7 +18,7 @@ const useImageWithFallback = ({ path }: { path: string }) => {
};
export const AssetManagerImage = ({
- asset: { path, alt },
+ asset: { path, alt, uploading },
}: {
asset: Asset;
}) => {
@@ -27,12 +27,20 @@ export const AssetManagerImage = ({
<Box
title={alt || ""}
css={{
+ opacity: uploading ? 0.5 : 1,
aspectRatio: "1/1",
+
backgroundImage: `url(${src})`,
backgroundSize: "contain",
backgroundRepeat: "no-repeat",
backgroundPosition: "center",
+ display: "flex",
+ justifyContent: "center",
+ alignItems: "center",
+ padding: "0 $2",
}}
- ></Box>
+ >
+ <ProgressBar css={{ width: "100%" }} />
+ </Box>
);
};
diff --git a/apps/designer/app/shared/design-system/index.ts b/apps/designer/app/shared/design-system/index.ts
index d94c0e1062..9c912df80b 100644
--- a/apps/designer/app/shared/design-system/index.ts
+++ b/apps/designer/app/shared/design-system/index.ts
@@ -39,6 +39,7 @@ export { Tooltip } from "./components/tooltip";
export { Button } from "./components/button";
export { IconButton } from "./components/icon-button";
export { Box } from "./components/box";
+export { ProgressBar } from "./components/progress-bar";
export {
Popover,
PopoverContent,