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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
move useActionData into the asset upload
Oleg Isonenb76ef631d0df
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/assets/asset-manager.tsx b/apps/designer/app/designer/features/sidebar-left/panels/assets/asset-manager.tsxindex a576052fe2..9662e5f320 100644--- a/apps/designer/app/designer/features/sidebar-left/panels/assets/asset-manager.tsx+++ b/apps/designer/app/designer/features/sidebar-left/panels/assets/asset-manager.tsx@@ -10,7 +10,7 @@ export const TabContent = ({}: {onSetActiveTab: (tabName: TabName) => void;}) => {- const { assets, onUploadAsset } = useAssets("image");+ const { assets, onSubmitAssets, onActionData } = useAssets("image");return (<><Header@@ -25,7 +25,11 @@ export const TabContent = ({css={{ padding: "$1", paddingTop: "$2" }}><Box css={{ padding: "$2" }}>- <AssetUpload onSubmit={onUploadAsset} type="image" />+ <AssetUpload+ onSubmit={onSubmitAssets}+ onActionData={onActionData}+ type="image"+ /></Box><Grid columns={2} gap={2}>{assets.map((asset) => (diff --git a/apps/designer/app/designer/shared/assets/asset-upload.tsx b/apps/designer/app/designer/shared/assets/asset-upload.tsxindex 3d7c8c28b7..fe9c1b9a25 100644--- a/apps/designer/app/designer/shared/assets/asset-upload.tsx+++ b/apps/designer/app/designer/shared/assets/asset-upload.tsx@@ -1,10 +1,10 @@-import { Form, useSubmit } from "@remix-run/react";+import { Form, useActionData, useSubmit } from "@remix-run/react";import ObjectID from "bson-objectid";-import { ChangeEvent, useRef } from "react";+import { ChangeEvent, useEffect, useRef } from "react";import { Button, Flex, Text } from "@webstudio-is/design-system";import { UploadIcon } from "@webstudio-is/icons";import { type AssetType, FONT_FORMATS } from "@webstudio-is/asset-uploader";-import type { PreviewAsset } from "./types";+import type { ActionData, PreviewAsset } from "./types";const readAssets = (fileList: FileList): Promise<PreviewAsset[]> => {const assets: Array<Promise<PreviewAsset>> = Array.from(fileList).map(@@ -38,13 +38,19 @@ const acceptMap = {};type AssetUploadProps = {+ onActionData: (data: ActionData) => void;onSubmit: (assets: Array<PreviewAsset>) => void;type: AssetType;};-export const AssetUpload = ({ onSubmit, type }: AssetUploadProps) => {+export const AssetUpload = ({+ onSubmit,+ onActionData,+ type,+}: AssetUploadProps) => {const submit = useSubmit();const inputRef = useRef<HTMLInputElement | null>(null);+ const actionData: ActionData | undefined = useActionData();const onFormChange = (event: ChangeEvent<HTMLFormElement>) => {const newFiles = inputRef?.current?.files;@@ -55,6 +61,12 @@ export const AssetUpload = ({ onSubmit, type }: AssetUploadProps) => {}};+ useEffect(() => {+ if (actionData !== undefined) {+ onActionData(actionData);+ }+ }, [actionData, onActionData]);+return (<Flexas={Form}diff --git a/apps/designer/app/designer/shared/assets/use-assets.ts b/apps/designer/app/designer/shared/assets/use-assets.tsindex c9f746836d..dc0b2d7674 100644--- a/apps/designer/app/designer/shared/assets/use-assets.ts+++ b/apps/designer/app/designer/shared/assets/use-assets.ts@@ -1,5 +1,4 @@import { useMemo, useState } from "react";-import { useActionData } from "@remix-run/react";import type { PreviewAsset, ActionData } from "./types";import {type AssetType,@@ -10,7 +9,7 @@ import { useAssets as useAllAssets } from "../nano-states";export const useAssets = (type: AssetType) => {const [allAssets] = useAllAssets();- const actionData: ActionData | undefined = useActionData();+ const [actionData, setActionData] = useState<ActionData>({});const [uploadingAssets, setUploadingAssets] = useState<Array<PreviewAsset>>([]);@@ -48,6 +47,7 @@ export const useAssets = (type: AssetType) => {return {assets,- onUploadAsset: setUploadingAssets,+ onSubmitAssets: setUploadingAssets,+ onActionData: setActionData,};};diff --git a/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx b/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsxindex 6143f82778..b4586902e2 100644--- a/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx+++ b/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx@@ -2,11 +2,15 @@ import { Flex, Box } from "@webstudio-is/design-system";import { AssetUpload, useAssets } from "~/designer/shared/assets";export const FontsManager = () => {- const { assets, onUploadAsset } = useAssets("font");+ const { assets, onSubmitAssets, onActionData } = useAssets("font");return (<Flex gap="3" direction="column" css={{ padding: "$1", paddingTop: "$2" }}><Box css={{ padding: "$2" }}>- <AssetUpload onSubmit={onUploadAsset} type="font" />+ <AssetUpload+ onSubmit={onSubmitAssets}+ onActionData={onActionData}+ type="font"+ /></Box>{assets.map((asset) => asset.name)}</Flex>