Skip to content

Commit

Permalink
Merge pull request #59 from deco-sites/fix/preview
Browse files Browse the repository at this point in the history
preview
  • Loading branch information
tlgimenes authored Oct 31, 2023
2 parents f2e72c4 + 7b41404 commit a485778
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ import_map.local.json
.config.json
# Fresh build directory
_fresh/

deno.lock
4 changes: 2 additions & 2 deletions apps/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { color as vnda } from "apps/vnda/mod.ts";
import { color as vtex } from "apps/vtex/mod.ts";
import { color as wake } from "apps/wake/mod.ts";
import { color as linx } from "apps/linx/mod.ts";
import { Section } from "deco/blocks/section.ts";
import { Flex } from "deco/blocks/section.ts";
import { App } from "deco/mod.ts";
import { rgb24 } from "std/fmt/colors.ts";
import manifest, { Manifest } from "../manifest.gen.ts";
Expand All @@ -16,7 +16,7 @@ export type Props = {
* @default custom
*/
platform: Platform;
theme?: Section;
theme?: Flex;
} & CommerceProps;

export type Platform = "vtex" | "vnda" | "shopify" | "wake" | "linx" | "custom";
Expand Down
6 changes: 0 additions & 6 deletions components/Layout.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions loaders/List/Sections.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Section } from "deco/blocks/section.ts";
import type { Flex } from "deco/blocks/section.ts";
import type { VNode } from "../../constants.tsx";

interface Props {
sections: Section[] | null;
sections: Flex[] | null;
}

function Sections({ sections }: Props): VNode[] | null {
Expand Down
13 changes: 2 additions & 11 deletions sections/Gallery.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import { Section } from "deco/blocks/section.ts";
import { LayoutContext } from "$store/components/Layout.tsx";

interface Props {
children: Section;
}

function Section({ children: { Component, props } }: Props) {
function Gallery({ children: { Component, props } }: Props) {
return (
<>
<Component {...props} />
</>
);
}

export function Preview(props: Props) {
return (
<LayoutContext.Provider value={{ isPreview: true }}>
<Section {...props} />
</LayoutContext.Provider>
);
}

export default Section;
export default Gallery;
20 changes: 5 additions & 15 deletions sections/Layout/Container.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Section } from "deco/blocks/section.ts";
import { LayoutContext, useLayoutContext } from "$store/components/Layout.tsx";
import { context } from "deco/mod.ts";

interface Props {
children?: Section;
Expand All @@ -13,13 +13,11 @@ function Placeholder() {
);
}

function Section({ children }: Props) {
const { isPreview } = useLayoutContext();

if (isPreview && typeof children?.Component !== "function") {
function Container({ children }: Props) {
if (!context.isDeploy && typeof children?.Component !== "function") {
return (
<div class="bg-primary bg-opacity-5 p-4">
<Section children={{ Component: Placeholder, props: {} }} />
<Container children={{ Component: Placeholder, props: {} }} />
</div>
);
}
Expand All @@ -35,12 +33,4 @@ function Section({ children }: Props) {
);
}

export function Preview(props: Props) {
return (
<LayoutContext.Provider value={{ isPreview: true }}>
<Section {...props} />
</LayoutContext.Provider>
);
}

export default Section;
export default Container;
18 changes: 4 additions & 14 deletions sections/Layout/Flex.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { LayoutContext, useLayoutContext } from "$store/components/Layout.tsx";
import { clx } from "$store/sdk/clx.ts";
import { Section } from "deco/blocks/section.ts";
import { context } from "deco/mod.ts";
import { flex, VNode } from "../../constants.tsx";

interface Props {
Expand Down Expand Up @@ -33,9 +32,8 @@ interface Props {
};
}

function Section({ layout, children }: Props) {
const { isPreview } = useLayoutContext();
const items = isPreview && !children?.length
function Flex({ layout, children }: Props) {
const items = !context.isDeploy && !children?.length
? new Array(4).fill(0).map(() => <ItemPreview />)
: children;

Expand All @@ -58,14 +56,6 @@ function Section({ layout, children }: Props) {
);
}

export function Preview(props: Props) {
return (
<LayoutContext.Provider value={{ isPreview: true }}>
<Section {...props} />
</LayoutContext.Provider>
);
}

const ItemPreview = () => (
<div class="card w-48 h-48 bg-base-100 shadow">
<div class="card-body items-center justify-center text-base-300 text-sm">
Expand All @@ -74,4 +64,4 @@ const ItemPreview = () => (
</div>
);

export default Section;
export default Flex;
18 changes: 4 additions & 14 deletions sections/Layout/Grid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Section } from "deco/blocks/section.ts";
import { context } from "deco/mod.ts";
import { grid, VNode } from "../../constants.tsx";
import { clx } from "../../sdk/clx.ts";
import { LayoutContext, useLayoutContext } from "$store/components/Layout.tsx";

interface Props {
children?: VNode[] | null;
Expand Down Expand Up @@ -65,9 +64,8 @@ interface Props {
};
}

function Section({ layout, children }: Props) {
const { isPreview } = useLayoutContext();
const items = isPreview && !children?.length
function Grid({ layout, children }: Props) {
const items = !context.isDeploy && !children?.length
? new Array(12).fill(0).map(() => <ItemPreview />)
: children;

Expand All @@ -92,14 +90,6 @@ function Section({ layout, children }: Props) {
);
}

export function Preview(props: Props) {
return (
<LayoutContext.Provider value={{ isPreview: true }}>
<Section {...props} />
</LayoutContext.Provider>
);
}

const ItemPreview = () => (
<div class="card w-48 h-48 bg-base-100 shadow">
<div class="card-body items-center justify-center text-base-300 text-sm">
Expand All @@ -108,4 +98,4 @@ const ItemPreview = () => (
</div>
);

export default Section;
export default Grid;
6 changes: 3 additions & 3 deletions sections/Product/NotFoundChallenge.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Section } from "deco/blocks/section.ts";
import type { Flex } from "deco/blocks/section.ts";
import type { ProductDetailsPage } from "apps/commerce/types.ts";

export interface Props {
/** @title Integration */
page: ProductDetailsPage | null;

/** @title On Product Found */
children: Section;
children: Flex;

/** @title On Product Not Found */
fallback: Section;
fallback: Flex;
}

function NotFoundChallenge({ page, children, fallback }: Props) {
Expand Down

1 comment on commit a485778

@deno-deploy
Copy link
Contributor

@deno-deploy deno-deploy bot commented on a485778 Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An internal server error occurred.

Please sign in to comment.