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.

fix delete, simplify logic

Oleg Isonena1b1a4e88932
diff --git a/apps/designer/app/designer/shared/assets/asset-upload.tsx b/apps/designer/app/designer/shared/assets/asset-upload.tsx
index 2ad8c095c6..ffec2741a5 100644
--- a/apps/designer/app/designer/shared/assets/asset-upload.tsx
+++ b/apps/designer/app/designer/shared/assets/asset-upload.tsx
@@ -4,7 +4,6 @@ import { UploadIcon } from "@webstudio-is/icons";
import { type AssetType } from "@webstudio-is/asset-uploader";
import { FONT_MIME_TYPES } from "@webstudio-is/fonts";
import { useAssets } from "./use-assets";
-import { useProject } from "../nano-states";
const useUpload = (type: AssetType) => {
const { handleSubmit, Form } = useAssets(type);
@@ -14,7 +13,7 @@ const useUpload = (type: AssetType) => {
const form = event.currentTarget;
const input = inputRef.current;
if (input === null) return;
- handleSubmit({ form, input });
+ handleSubmit(input);
form.reset();
};
@@ -32,16 +31,8 @@ type AssetUploadProps = {
export const AssetUpload = ({ type }: AssetUploadProps) => {
const { inputRef, onChange, Form } = useUpload(type);
- const [project] = useProject();
return (
- <Flex
- as={Form}
- css={{ flexGrow: 1 }}
- action={`/rest/assets/${project?.id}`}
- method="post"
- encType="multipart/form-data"
- onChange={onChange}
- >
+ <Flex as={Form} css={{ flexGrow: 1 }} onChange={onChange}>
<input
accept={acceptMap[type]}
type="file"
diff --git a/apps/designer/app/designer/shared/assets/use-assets.ts b/apps/designer/app/designer/shared/assets/use-assets.ts
index 71752bcdf5..e4d10fdff7 100644
--- a/apps/designer/app/designer/shared/assets/use-assets.ts
+++ b/apps/designer/app/designer/shared/assets/use-assets.ts
@@ -1,4 +1,4 @@
-import { FormEncType, FormMethod, useFetcher } from "@remix-run/react";
+import { useFetcher } from "@remix-run/react";
import {
AssetType,
filterByType,
@@ -8,7 +8,7 @@ import {
import { toast } from "@webstudio-is/design-system";
import ObjectID from "bson-objectid";
import { useMemo } from "react";
-import { useAssets as useAssetsState } from "../nano-states";
+import { useAssets as useAssetsState, useProject } from "../nano-states";
import { PreviewAsset } from "./types";
const toPreviewAssets = (formData: FormData): Promise<PreviewAsset[]> => {
@@ -61,27 +61,23 @@ const toFormData = (type: AssetType, input: HTMLInputElement) => {
export const useAssets = (type: AssetType) => {
const { submit, Form } = useFetcher();
const [assets, setAssets] = useAssetsState();
+ const [project] = useProject();
+ const action = `/rest/assets/${project?.id}`;
const handleDelete = (ids: Array<string>) => {
const formData = new FormData();
for (const id of ids) {
formData.append("assetId", id);
}
- submit(formData, { method: "delete" });
+ submit(formData, { method: "delete", action });
};
- const handleSubmit = ({
- form,
- input,
- }: {
- form: HTMLFormElement;
- input: HTMLInputElement;
- }) => {
+ const handleSubmit = (input: HTMLInputElement) => {
const formData = toFormData(type, input);
submit(formData, {
- method: form.method as FormMethod,
- action: form.action,
- encType: form.enctype as FormEncType,
+ method: "post",
+ action,
+ encType: "multipart/form-data",
});
toPreviewAssets(formData)
.then((previewAssets) => {
diff --git a/apps/designer/app/routes/rest/assets.$projectId.tsx b/apps/designer/app/routes/rest/assets.$projectId.tsx
index 3386e8baad..d5ff53df49 100644
--- a/apps/designer/app/routes/rest/assets.$projectId.tsx
+++ b/apps/designer/app/routes/rest/assets.$projectId.tsx
@@ -1,7 +1,3 @@
-// @todo this file structure is WIP
-// What we actually need is load assets panel based on a route and only load
-// data, js etc for assets when we are on that route
-
import { ActionFunction } from "@remix-run/node";
import { useActionData } from "@remix-run/react";
import {