Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/deco-cx/apps into magento
Browse files Browse the repository at this point in the history
  • Loading branch information
aka-sacci-ccr committed Jul 23, 2024
2 parents c749eda + 6564ec8 commit 9ed5b5c
Show file tree
Hide file tree
Showing 15 changed files with 229 additions and 46 deletions.
11 changes: 8 additions & 3 deletions commerce/sections/Seo/SeoPDPV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export interface Props {
}

/** @title Product details */
export function loader(props: Props, _req: Request, ctx: AppContext) {
export function loader(_props: Props, _req: Request, ctx: AppContext) {
const props = _props as Partial<Props>;
const {
titleTemplate = "",
descriptionTemplate = "",
Expand All @@ -38,11 +39,11 @@ export function loader(props: Props, _req: Request, ctx: AppContext) {

const title = renderTemplateString(
titleTemplate,
titleProp || jsonLD?.seo?.title || "",
titleProp || jsonLD?.seo?.title || ctx.seo?.title || "",
);
const description = renderTemplateString(
descriptionTemplate,
descriptionProp || jsonLD?.seo?.description || "",
descriptionProp || jsonLD?.seo?.description || ctx.seo?.description || "",
);
const image = jsonLD?.product.image?.[0]?.url;
const canonical = jsonLD?.seo?.canonical
Expand Down Expand Up @@ -71,6 +72,10 @@ function Section(props: Props): SEOSection {
return <Seo {...props} />;
}

export function LoadingFallback(props: Partial<Props>) {
return <Seo {...props} />;
}

export { default as Preview } from "../../../website/components/_seo/Preview.tsx";

export default Section;
11 changes: 8 additions & 3 deletions commerce/sections/Seo/SeoPLPV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export interface Props {
}

/** @title Product listing */
export function loader(props: Props, _req: Request, ctx: AppContext) {
export function loader(_props: Props, _req: Request, ctx: AppContext) {
const props = _props as Partial<Props>;
const {
titleTemplate = "",
descriptionTemplate = "",
Expand All @@ -43,11 +44,11 @@ export function loader(props: Props, _req: Request, ctx: AppContext) {

const title = renderTemplateString(
titleTemplate,
titleProp || jsonLD?.seo?.title || "",
titleProp || jsonLD?.seo?.title || ctx.seo?.title || "",
);
const description = renderTemplateString(
descriptionTemplate,
descriptionProp || jsonLD?.seo?.description || "",
descriptionProp || jsonLD?.seo?.description || ctx.seo?.description || "",
);
const canonical = props.canonical
? props.canonical
Expand Down Expand Up @@ -85,6 +86,10 @@ function Section(props: Props): SEOSection {
return <Seo {...props} />;
}

export function LoadingFallback(props: Partial<Props>) {
return <Seo {...props} />;
}

export { default as Preview } from "../../../website/components/_seo/Preview.tsx";

export default Section;
1 change: 1 addition & 0 deletions commerce/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ export interface Search {
export interface Suggestion {
searches?: Search[];
products?: Product[];
hits?: number;
}

/** @titleBy url */
Expand Down
6 changes: 3 additions & 3 deletions decohub/mod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ImportMap } from "deco/blocks/app.ts";
import { buildImportMap } from "deco/blocks/utils.tsx";
import { notUndefined } from "deco/engine/core/utils.ts";
import { type App, AppModule, context, type FnContext } from "deco/mod.ts";
import { type App, AppModule, type FnContext } from "deco/mod.ts";
import { Markdown } from "./components/Markdown.tsx";
import manifest, { Manifest } from "./manifest.gen.ts";

Expand Down Expand Up @@ -79,7 +79,7 @@ export default async function App(
// build apps based on name
...dynamicApps,
...manifest.apps,
...context.play || state.enableAdmin // this is an optimization to not include the admin code for everyone in case of play is not being used.
...state.enableAdmin // this is an optimization to not include the admin code for everyone in case of play is not being used.
? {
[ADMIN_APP]: await import(
resolvedAdminImport
Expand All @@ -92,7 +92,7 @@ export default async function App(
},
} as Manifest,
state,
...(context.play || state.enableAdmin)
...state.enableAdmin
? {
importMap: {
...enhancedImportMap,
Expand Down
8 changes: 4 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"imports": {
"$fresh/": "https://denopkg.com/denoland/fresh@1.5.2/",
"$fresh/": "https://denopkg.com/denoland/fresh@1.6.8/",
"preact": "https://esm.sh/preact@10.15.1",
"preact/": "https://esm.sh/preact@10.15.1/",
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.0",
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.3.0",
"std/": "https://deno.land/std@0.204.0/",
"partytown/": "https://deno.land/x/partytown@0.4.8/",
"deco-sites/std/": "https://denopkg.com/deco-sites/std@1.26.6/",
"deco/": "https://denopkg.com/deco-cx/deco@1.74.0/"
"deco-sites/std/": "https://denopkg.com/deco-sites/std@1.26.7/",
"deco/": "https://cdn.jsdelivr.net/gh/deco-cx/deco@1.78.0/"
},
"lock": false,
"tasks": {
Expand All @@ -36,5 +36,5 @@
"jsx": "react-jsx",
"jsxImportSource": "preact"
},
"version": "0.49.4"
"version": "0.52.1"
}
31 changes: 22 additions & 9 deletions htmx/sections/Deferred.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import type { Section } from "deco/blocks/section.ts";
import { useSection } from "deco/hooks/useSection.ts";
import { asResolved, isDeferred } from "deco/mod.ts";
import { AppContext } from "../mod.ts";
import { shouldForceRender } from "../../utils/deferred.ts";
import { renderSection, shouldForceRender } from "../../utils/deferred.tsx";

/**
* @titleBy type
* @description fires once when the element is first loaded
*/
interface Load {
type: "load";
/** @hide true */
delay?: number;
}

/**
Expand All @@ -32,6 +34,8 @@ interface Intersect {

export interface Props {
sections: Section[];
/** @hide true */
fallbacks?: Section[];
trigger?: Load | Revealed | Intersect;
loading?: "lazy" | "eager";
}
Expand All @@ -42,7 +46,7 @@ const Deferred = (props: Props) => {
if (loading === "eager") {
return (
<>
{sections.map(({ Component, props }) => <Component {...props} />)}
{sections.map(renderSection)}
</>
);
}
Expand All @@ -51,14 +55,22 @@ const Deferred = (props: Props) => {
props: { loading: "eager" },
});

const triggerList: (string | number)[] = [trigger?.type ?? "load", "once"];
if (trigger?.type === "load" && trigger.delay !== undefined) {
triggerList.push(`delay:${trigger.delay}ms`);
}

return (
<div
hx-get={href}
hx-trigger={`${trigger?.type ?? "load"} once`}
hx-target="closest section"
hx-swap="outerHTML"
style={{ height: "100vh" }}
/>
<>
<div
hx-get={href}
hx-trigger={triggerList.join(" ")}
hx-target="closest section"
hx-swap="outerHTML"
style={{ height: "100vh" }}
/>
{props.fallbacks?.map(renderSection)}
</>
);
};

Expand All @@ -81,6 +93,7 @@ const DEFERRED = true;
export const onBeforeResolveProps = (props: Props) => {
return {
...props,
fallback: null,
sections: asResolved(props.sections, DEFERRED),
};
};
Expand Down
6 changes: 5 additions & 1 deletion records/deps.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
export * from "npm:@libsql/client@0.6.0/node";
import { context } from "deco/deco.ts";
export * from "https://esm.sh/drizzle-orm@0.30.10/libsql";
export * from "npm:@libsql/client@0.7.0";

export const createLocalClient = !context.isDeploy &&
(await import("npm:@libsql/client@0.7.0/node")).createClient;
12 changes: 10 additions & 2 deletions records/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { App, AppContext as AC } from "deco/mod.ts";
import manifest, { Manifest } from "./manifest.gen.ts";
import { createClient as createSQLClient, drizzle } from "./deps.ts";
import {
createClient as createSQLClient,
createLocalClient,
drizzle,
} from "./deps.ts";
import { getSQLClientConfig, StorageConfig } from "./utils.ts";

export interface Props extends StorageConfig {}
Expand All @@ -14,7 +18,11 @@ export interface Props extends StorageConfig {}
export default function Records(
{ url, authToken, ...state }: Props,
) {
const sqlClient = createSQLClient(getSQLClientConfig({ url, authToken }));
const sqlClientConfig = getSQLClientConfig({ url, authToken });
const sqlClient =
sqlClientConfig.url.startsWith("file://") && createLocalClient
? createLocalClient(sqlClientConfig)
: createSQLClient(sqlClientConfig);

const appState = {
...state,
Expand Down
5 changes: 5 additions & 0 deletions utils/deferred.ts → utils/deferred.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Section } from "deco/mod.ts";
import { __DECO_FBT } from "../website/handlers/fresh.ts";

export const shouldForceRender = <Ctx extends { isBot?: boolean }>(
{ ctx, searchParams }: { ctx: Ctx; searchParams: URLSearchParams },
): boolean => ctx.isBot || searchParams.get(__DECO_FBT) === "0";

export const renderSection = ({ Component, props }: Section) => (
<Component {...props} />
);
3 changes: 2 additions & 1 deletion vtex/loaders/intelligentSearch/suggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const loaders = async (
.then((res) => res.json());
};

const [{ searches }, { products }] = await Promise.all([
const [{ searches }, { products, recordsFiltered }] = await Promise.all([
query ? suggestions() : topSearches(),
productSearch(),
]);
Expand All @@ -88,6 +88,7 @@ const loaders = async (
withIsSimilarTo(req, ctx, p)
),
),
hits: recordsFiltered,
};
};

Expand Down
15 changes: 9 additions & 6 deletions website/components/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const optimizeVTEX = (opts: OptimizationOptions) => {
};

export const getOptimizedMediaUrl = (opts: OptimizationOptions) => {
const { originalSrc, width, height, factor, fit } = opts;
const { originalSrc, width, height, fit } = opts;

if (originalSrc.startsWith("data:")) {
return originalSrc;
Expand Down Expand Up @@ -120,8 +120,8 @@ export const getOptimizedMediaUrl = (opts: OptimizationOptions) => {

params.set("src", originalSrc);
params.set("fit", fit);
params.set("width", `${Math.trunc(factor * width)}`);
height && params.set("height", `${Math.trunc(factor * height)}`);
params.set("width", `${width}`);
height && params.set("height", `${height}`);

return `${PATH}?${params}`;
};
Expand All @@ -136,16 +136,19 @@ export const getSrcSet = (

for (let it = 0; it < FACTORS.length; it++) {
const factor = FACTORS[it];
const w = Math.trunc(factor * width);
const h = height && Math.trunc(factor * height);

const src = getOptimizedMediaUrl({
originalSrc,
width,
height,
width: w,
height: h,
factor,
fit: fit || "cover",
});

if (src) {
srcSet.push(`${src} ${Math.trunc(factor * width)}w`);
srcSet.push(`${src} ${w}w`);
}
}

Expand Down
2 changes: 0 additions & 2 deletions website/components/_Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ interface Live {
page?: Page;
site: Site;
flags: Flag[];
play: boolean;
avoidRedirectingToEditor?: boolean;
}

Expand Down Expand Up @@ -134,7 +133,6 @@ function LiveControls(
page,
site,
flags,
play: !!context.play,
avoidRedirectingToEditor,
})}
/>
Expand Down
10 changes: 6 additions & 4 deletions website/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ import * as $$$$$$$14 from "./matchers/userAgent.ts";
import * as $$$$$0 from "./pages/Page.tsx";
import * as $$$$$$0 from "./sections/Analytics/Analytics.tsx";
import * as $$$$$$1 from "./sections/Rendering/Deferred.tsx";
import * as $$$$$$2 from "./sections/Seo/Seo.tsx";
import * as $$$$$$3 from "./sections/Seo/SeoV2.tsx";
import * as $$$$$$2 from "./sections/Rendering/SingleDeferred.tsx";
import * as $$$$$$3 from "./sections/Seo/Seo.tsx";
import * as $$$$$$4 from "./sections/Seo/SeoV2.tsx";

const manifest = {
"functions": {
Expand Down Expand Up @@ -85,8 +86,9 @@ const manifest = {
"sections": {
"website/sections/Analytics/Analytics.tsx": $$$$$$0,
"website/sections/Rendering/Deferred.tsx": $$$$$$1,
"website/sections/Seo/Seo.tsx": $$$$$$2,
"website/sections/Seo/SeoV2.tsx": $$$$$$3,
"website/sections/Rendering/SingleDeferred.tsx": $$$$$$2,
"website/sections/Seo/Seo.tsx": $$$$$$3,
"website/sections/Seo/SeoV2.tsx": $$$$$$4,
},
"matchers": {
"website/matchers/always.ts": $$$$$$$0,
Expand Down
Loading

0 comments on commit 9ed5b5c

Please sign in to comment.