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.

clean up ts

Sara Vieirafc6913457144
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 8a26d00c6b..f0b15cdcfc 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
@@ -6,11 +6,12 @@ import { Asset } from "@webstudio-is/prisma-client";
import { AssetManagerImage } from "./components/image";
import { AddAnAssetForm } from "./components/add-an-asset-form";
+import { UploadingAsset } from "../types";
export const TabContent = ({
assets: baseAssets,
}: {
- assets: Array<Asset & { uploading?: boolean }>;
+ assets: Array<Asset | UploadingAsset>;
}) => {
const newImages = useActionData();
@@ -20,7 +21,9 @@ export const TabContent = ({
if (newImages?.assets.length) {
setAsssets((currentAssets) => [
...newImages.assets,
- ...currentAssets.filter((a) => !a.uploading),
+ ...currentAssets.filter(
+ (asset) => "uploading" in asset && !asset.uploading
+ ),
]);
}
}, [newImages]);
@@ -30,7 +33,7 @@ export const TabContent = ({
<Flex justify="between">
<Heading>Assets</Heading>
<AddAnAssetForm
- onSubmit={(uploadedAssets: Array<Asset>) =>
+ onSubmit={(uploadedAssets: Array<UploadingAsset>) =>
setAsssets((assets) => [...uploadedAssets, ...assets])
}
/>
@@ -41,7 +44,7 @@ export const TabContent = ({
key={asset.id}
path={asset.path}
alt={asset.alt || asset.name}
- uploading={asset.uploading}
+ uploading={"uploading" in asset && asset.uploading}
/>
))}
</Grid>
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/components/add-an-asset-form.tsx b/apps/designer/app/designer/features/sidebar-left/panels/components/add-an-asset-form.tsx
index 1ad682cb46..a5f191a378 100644
--- a/apps/designer/app/designer/features/sidebar-left/panels/components/add-an-asset-form.tsx
+++ b/apps/designer/app/designer/features/sidebar-left/panels/components/add-an-asset-form.tsx
@@ -1,10 +1,10 @@
-import { Form, useParams, useSubmit } from "@remix-run/react";
-import { Asset, Decimal, Location } from "@webstudio-is/prisma-client";
+import { Form, useSubmit } from "@remix-run/react";
import ObjectID from "bson-objectid";
import { ChangeEvent, useRef } from "react";
import { Button } from "~/shared/design-system";
+import { UploadingAsset } from "../../types";
-const readImages = async (fileList: FileList, projectId: string) => {
+const readImages = async (fileList: FileList) => {
const images = [];
for (const file of fileList) {
const path = await new Promise((resolve) => {
@@ -21,15 +21,8 @@ const readImages = async (fileList: FileList, projectId: string) => {
path: path as string,
name: file.name,
id: ObjectID().toString(),
- width: 0 as unknown as Decimal,
- height: 0 as unknown as Decimal,
- projectId,
- size: file.size,
- format: file.type,
- createdAt: new Date(),
- location: "FS" as Location,
- alt: "",
uploading: true,
+ alt: file.name,
});
}
@@ -39,17 +32,16 @@ const readImages = async (fileList: FileList, projectId: string) => {
export const AddAnAssetForm = ({
onSubmit,
}: {
- onSubmit: (uploadedAssets: Array<Asset>) => void;
+ onSubmit: (uploadedAssets: Array<UploadingAsset>) => void;
}) => {
const submit = useSubmit();
const inputRef = useRef<HTMLInputElement | null>(null);
- const { id } = useParams();
const onFormChange = async (event: ChangeEvent<HTMLFormElement>) => {
const newFiles = inputRef?.current?.files;
- if (newFiles && id) {
+ if (newFiles) {
submit(event.currentTarget);
- const parsedFiles = await readImages(newFiles, id);
+ const parsedFiles = await readImages(newFiles);
onSubmit(parsedFiles);
event.currentTarget.reset();
}
diff --git a/apps/designer/app/designer/features/sidebar-left/types.ts b/apps/designer/app/designer/features/sidebar-left/types.ts
index dc658bb5f1..b5c95c5310 100644
--- a/apps/designer/app/designer/features/sidebar-left/types.ts
+++ b/apps/designer/app/designer/features/sidebar-left/types.ts
@@ -1,3 +1,11 @@
import { panels } from "./panels";
export type TabName = keyof typeof panels | "none";
+
+export type UploadingAsset = {
+ id: string;
+ uploading: boolean;
+ name: string;
+ path: string;
+ alt: string;
+};