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.

Merge branch 'main' into 54-multi-page-sites-and-routing

Roman Pominovf7fb78a426a4
diff --cc apps/designer/app/routes/designer/$id.tsx
index b7b9ca4967,a5ac843248..d065d0d7ff
--- a/apps/designer/app/routes/designer/$id.tsx
+++ b/apps/designer/app/routes/designer/$id.tsx
@@@ -4,23 -3,15 +3,18 @@@ import { LoaderFunction } from "@remix-
import { Designer, links } from "~/designer";
import * as db from "~/shared/db";
import config from "~/config";
-import env from "~/env.server";
+import env, { type Env } from "~/env.server";
- import { uploadAssets } from "~/shared/db/misc.server";
import { ErrorMessage } from "~/shared/error";
- // if this file does not end in .server remix will not build
- // since it only allows node code in those files
- import { deleteAsset } from "@webstudio-is/asset-uploader/index.server";
- import { zfd } from "zod-form-data";
- import { useEffect } from "react";
+ import { action, useAction } from "./_assets";
- export { links };
+ export { links, action };
-export const loader: LoaderFunction = async ({ params }) => {
+export const loader: LoaderFunction = async ({
+ params,
+}): Promise<Data | Error> => {
if (params.id === undefined) throw new Error("Project id undefined");
const project = await db.project.loadById(params.id);
+
if (project === null) {
return { errors: `Project "${params.id}" not found` };
}
@@@ -34,67 -24,12 +28,12 @@@ type Data =
};
type Error = {
- errors: "string";
+ errors: string;
};
- const deleteAssetSchema = zfd.formData({
- assetId: zfd.text(),
- assetName: zfd.text(),
- });
-
- export const action: ActionFunction = async ({ request, params }) => {
- if (params.id === undefined) throw new Error("Project id undefined");
- try {
- if (request.method === "DELETE") {
- const { assetId, assetName } = deleteAssetSchema.parse(
- await request.formData()
- );
- const deletedAsset = await deleteAsset({
- id: assetId,
- name: assetName,
- });
-
- return { deletedAsset };
- }
- } catch (error) {
- if (error instanceof Error) {
- return {
- errors: error.message,
- };
- }
- }
- if (request.method === "POST") {
- try {
- const assets = await uploadAssets({
- request,
- projectId: params.id,
- });
- return {
- uploadedAssets: assets.map((asset) => ({
- ...asset,
- status: "uploaded",
- })),
- };
- } catch (error) {
- if (error instanceof Error) {
- return {
- errors: error.message,
- };
- }
- }
- }
- };
-
- const DesignerRoute = () => {
- const actionData = useActionData();
+ export const DesignerRoute = () => {
const data = useLoaderData<Data | Error>();
-
- useEffect(() => {
- if (actionData && "errors" in actionData) {
- toast.error(actionData.errors);
- }
- }, [actionData]);
-
+ useAction();
if ("errors" in data) {
return <ErrorMessage message={data.errors} />;
}