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
feat: add marketplace section in page settings (#3413)
Bogdan Chadkinc621ce90ca12
diff --git a/apps/builder/app/builder/features/project-settings/section-marketplace.tsx b/apps/builder/app/builder/features/project-settings/section-marketplace.tsxindex 50016b975d..4f8b5411ed 100644--- a/apps/builder/app/builder/features/project-settings/section-marketplace.tsx+++ b/apps/builder/app/builder/features/project-settings/section-marketplace.tsx@@ -300,10 +300,6 @@ export const SectionMarketplace = () => {<Grid gap={2} css={sectionSpacing}><PanelBanner>- <Text>- {`You can add a "ws:category" meta tag in the page settings for pages being grouped by category. You can also define- "ws:title" for each page; otherwise, the page title will be used.`}- </Text><Text color="destructive">{`Don't forget to publish your project after every change to make yourchanges available in the marketplace!`}diff --git a/apps/builder/app/builder/features/sidebar-left/panels/marketplace/templates.tsx b/apps/builder/app/builder/features/sidebar-left/panels/marketplace/templates.tsxindex bb944ef99e..3079a8488c 100644--- a/apps/builder/app/builder/features/sidebar-left/panels/marketplace/templates.tsx+++ b/apps/builder/app/builder/features/sidebar-left/panels/marketplace/templates.tsx@@ -18,18 +18,11 @@ import { builderUrl } from "~/shared/router-utils";import { Card } from "./card";type TemplateData = {- socialImageAsset?: Asset;- socialImageUrl?: string;title?: string;+ thumbnailAsset?: Asset;rootInstanceId: string;};-// Special meta properties for the marketplace-const marketplaceMeta = {- category: "ws:category",- title: "ws:title",-};-const getTemplatesDataByCategory = (data?: WebstudioData) => {const templatesByCategory = new Map<string, Array<TemplateData>>();@@ -37,31 +30,30 @@ const getTemplatesDataByCategory = (data?: WebstudioData) => {return templatesByCategory;}- // In the future we could support bindings in the store as well.- const variableValues = new Map();const pages = [data.pages.homePage, ...data.pages.pages];for (const page of pages) {- const excludePageFromSearch = computeExpression(- page.meta.excludePageFromSearch || "false",- variableValues- );+ // @todo remove after all stores are migrated+ const excludePageFromSearch =+ computeExpression(+ page.meta.excludePageFromSearch || "false",+ new Map()+ ) ?? true;+ const include =+ page.marketplace?.include ?? false === excludePageFromSearch ?? false;// We allow user to hide the page in the marketplace.- if (excludePageFromSearch) {+ if (false === include) {continue;}- let category = page.meta.custom?.find(- ({ property }) => property === marketplaceMeta.category- )?.content;-- if (category !== undefined) {- category = computeExpression(category, variableValues);- }-- if (category === undefined) {- category = "Pages";- }+ const categoryMeta = page.meta.custom?.find(+ ({ property }) => property === "ws:category"+ );+ // @todo remove after all stores are migrated+ const categoryFallback = String(+ computeExpression(categoryMeta?.content ?? `""`, new Map())+ );+ const category = page.marketplace?.category ?? categoryFallback ?? "Pages";let templates = templatesByCategory.get(category);if (templates === undefined) {@@ -69,27 +61,16 @@ const getTemplatesDataByCategory = (data?: WebstudioData) => {templatesByCategory.set(category, templates);}- const socialImageUrl = page.meta.socialImageUrl- ? String(computeExpression(page.meta.socialImageUrl, variableValues))- : undefined;const socialImageAsset = page.meta.socialImageAssetId? data.assets.get(page.meta.socialImageAssetId): undefined;-- let title = page.meta.custom?.find(- ({ property }) => property === marketplaceMeta.title- )?.content;- if (title !== undefined) {- title = computeExpression(title, variableValues);- }- if (title === undefined || title === "") {- title = computeExpression(page.title, variableValues);- }+ const thumbnailImageAsset = page.marketplace?.thumbnailAssetId+ ? data.assets.get(page.marketplace.thumbnailAssetId)+ : undefined;templates.push({- title,- socialImageUrl,- socialImageAsset,+ title: page.name,+ thumbnailAsset: thumbnailImageAsset ?? socialImageAsset,rootInstanceId: page.rootInstanceId,});}@@ -171,11 +152,8 @@ export const Templates = ({}}><Card- image={- templateData.socialImageAsset ??- templateData.socialImageUrl- }title={templateData.title}+ image={templateData.thumbnailAsset}/></ListItem>);diff --git a/apps/builder/app/builder/features/sidebar-left/panels/pages/page-settings.tsx b/apps/builder/app/builder/features/sidebar-left/panels/pages/page-settings.tsxindex 77f40fd784..665f1c4d3c 100644--- a/apps/builder/app/builder/features/sidebar-left/panels/pages/page-settings.tsx+++ b/apps/builder/app/builder/features/sidebar-left/panels/pages/page-settings.tsx@@ -51,6 +51,7 @@ import {buttonStyle,PanelBanner,css,+ Switch,} from "@webstudio-is/design-system";import {ChevronDoubleLeftIcon,@@ -72,6 +73,7 @@ import {computeExpression,$dataSourceVariables,$publishedOrigin,+ $project,} from "~/shared/nano-states";import {BindingControl,@@ -105,6 +107,7 @@ import { Form } from "./form";import { $userPlanFeatures } from "~/builder/shared/nano-states";import type { UserPlanFeatures } from "~/shared/db/user-plan-features.server";import { useUnmount } from "~/shared/hook-utils/use-mount";+import { Card } from "../marketplace/card";const fieldDefaultValues = {name: "Untitled",@@ -120,12 +123,10 @@ const fieldDefaultValues = {status: `200`,redirect: `""`,documentType: "html" as (typeof documentTypes)[number],- customMetas: [- {- property: "",- content: `""`,- },- ],+ customMetas: [{ property: "", content: `""` }],+ marketplaceInclude: false,+ marketplaceCategory: "",+ marketplaceThumbnailAssetId: "",};const fieldNames = Object.keys(@@ -136,6 +137,15 @@ type FieldName = (typeof fieldNames)[number];type Values = typeof fieldDefaultValues;+type OnChange = (+ event: {+ [K in keyof Values]: {+ field: K;+ value: Values[K];+ };+ }[keyof Values]+) => void;+type Errors = {[fieldName in FieldName]?: string[];};@@ -297,6 +307,9 @@ const toFormValues = (documentType: page.meta.documentType ?? fieldDefaultValues.documentType,isHomePage,customMetas: page.meta.custom ?? fieldDefaultValues.customMetas,+ marketplaceInclude: page.marketplace?.include ?? false,+ marketplaceCategory: page.marketplace?.category ?? "",+ marketplaceThumbnailAssetId: page.marketplace?.thumbnailAssetId ?? "",};};@@ -585,6 +598,101 @@ const fieldsetStyle = css({},});+const MarketplaceSection = ({+ values,+ onChange,+}: {+ values: Values;+ onChange: OnChange;+}) => {+ const excludeId = useId();+ const categoryId = useId();+ const categoryMeta = values.customMetas.find(+ ({ property }) => property === "ws:category"+ );+ // @todo remove after all stores are migrated+ const categoryFallback = String(+ computeExpression(categoryMeta?.content ?? `""`, new Map())+ );+ const category = values.marketplaceCategory ?? categoryFallback ?? "Pages";+ const assets = useStore($assets);+ const thumbnailAsset = assets.get(values.marketplaceThumbnailAssetId);+ const thumnailFallbackAsset = assets.get(values.socialImageAssetId);+ return (+ <Grid gap={2} css={{ py: theme.spacing[5], px: theme.spacing[8] }}>+ <Label text="title">Marketplace</Label>+ <Grid+ flow="column"+ gap={1}+ justify="start"+ align="center"+ css={{ py: theme.spacing[2] }}+ >+ <Switch+ id={excludeId}+ checked={values.marketplaceInclude}+ onCheckedChange={(value) =>+ onChange({ field: "marketplaceInclude", value })+ }+ />+ <Label htmlFor={excludeId}>Include in the marketplace</Label>+ </Grid>+ <Grid gap={1}>+ <Label htmlFor={categoryId}>Category</Label>+ <InputField+ id={categoryId}+ name="marketplaceCategory"+ value={values.marketplaceCategory}+ onChange={(event) =>+ onChange({+ field: "marketplaceCategory",+ value: event.target.value,+ })+ }+ />+ </Grid>+ <Grid gap={1} flow="column">+ <ImageControl+ onAssetIdChange={(value) =>+ onChange({ field: "marketplaceThumbnailAssetId", value })+ }+ >+ <Button color="neutral" css={{ justifySelf: "start" }}>+ Choose thumbnail from assets+ </Button>+ </ImageControl>+ </Grid>+ {thumbnailAsset?.type === "image" && (+ <ImageInfo+ asset={thumbnailAsset}+ onDelete={() =>+ onChange({ field: "marketplaceThumbnailAssetId", value: "" })+ }+ />+ )}+ <Grid gap={1}>+ <Label>Marketplace Preview</Label>+ <Box+ css={{+ padding: theme.spacing[5],+ borderRadius: theme.borderRadius[4],+ border: `1px solid ${theme.colors.borderMain}`,+ justifySelf: "start",+ }}+ >+ <Grid gap={1} css={{ width: theme.spacing[30] }}>+ {category && <Label text="title">{category}</Label>}+ <Card+ title={values.name}+ image={thumbnailAsset ?? thumnailFallbackAsset}+ />+ </Grid>+ </Box>+ </Grid>+ </Grid>+ );+};+const FormFields = ({systemDataSourceId,autoSelect,@@ -596,15 +704,9 @@ const FormFields = ({autoSelect?: boolean;errors: Errors;values: Values;- onChange: (- event: {- [K in keyof Values]: {- field: K;- value: Values[K];- };- }[keyof Values]- ) => void;+ onChange: OnChange;}) => {+ const project = useStore($project);const fieldIds = useIds(fieldNames);const assets = useStore($assets);const pages = useStore($pages);@@ -1129,8 +1231,18 @@ const FormFields = ({/></div></InputErrorsTooltip>- <Box css={{ height: theme.spacing[10] }} /></fieldset>++ {(project?.marketplaceApprovalStatus === "PENDING" ||+ project?.marketplaceApprovalStatus === "APPROVED" ||+ project?.marketplaceApprovalStatus === "REJECTED") && (+ <>+ <Separator />+ <MarketplaceSection values={values} onChange={onChange} />+ </>+ )}++ <Box css={{ height: theme.spacing[10] }} /></ScrollArea></Grid>);@@ -1367,6 +1479,21 @@ const updatePage = (pageId: Page["id"], values: Partial<Values>) => {if (values.parentFolderId !== undefined) {registerFolderChildMutable(folders, page.id, values.parentFolderId);}++ if (values.marketplaceCategory !== undefined) {+ page.marketplace ??= {};+ page.marketplace.category =+ values.marketplaceCategory.length > 0+ ? values.marketplaceCategory+ : undefined;+ }+ if (values.marketplaceThumbnailAssetId !== undefined) {+ page.marketplace ??= {};+ page.marketplace.thumbnailAssetId =+ values.marketplaceThumbnailAssetId.length > 0+ ? values.marketplaceThumbnailAssetId+ : undefined;+ }};serverSyncStore.createTransaction([$pages], (pages) => {diff --git a/packages/sdk/src/schema/pages.ts b/packages/sdk/src/schema/pages.tsindex 8cafb64174..6b93330d97 100644--- a/packages/sdk/src/schema/pages.ts+++ b/packages/sdk/src/schema/pages.ts@@ -49,6 +49,8 @@ const commonPageFields = {name: PageName,title: PageTitle,history: z.optional(z.array(z.string())),+ rootInstanceId: z.string(),+ systemDataSourceId: z.string(),meta: z.object({description: z.string().optional(),title: z.string().optional(),@@ -68,8 +70,13 @@ const commonPageFields = {).optional(),}),- rootInstanceId: z.string(),- systemDataSourceId: z.string(),+ marketplace: z.optional(+ z.object({+ include: z.optional(z.boolean()),+ category: z.optional(z.string()),+ thumbnailAssetId: z.optional(z.string()),+ })+ ),} as const;export const HomePagePath = z