Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions apps/demo/app/[...slug]/fetchSlugs.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import { createClient } from '@sanity/client';

const client = createClient({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!,
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET!,
apiVersion: 'vX',
useCdn: false,
token: process.env.NEXT_PUBLIC_SANITY_TOKEN!,
perspective: 'drafts',
});
import { client } from './sanity-client';

export async function fetchSlugs() {
const slugs: string[] = await client.fetch(
Expand Down
38 changes: 31 additions & 7 deletions apps/demo/app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
// import { fetchSlugs } from '@/app/[...slug]/fetchSlugs';
import { RouteLoader } from '@vyuh/react-extension-content';

import { fetchSlugs } from '@/app/[...slug]/fetchSlugs';
import { RouteLoaderNext } from '@vyuh/react-extension-content';
import { ContentItem, PluginDescriptor, VyuhProvider } from '@vyuh/react-core';
import { DefaultContentPlugin } from '@vyuh/react-extension-content';
import { client, fetchSlug } from './sanity-client';
import { system } from '@vyuh/react-feature-system';
import { auth } from '@vyuh/react-feature-auth';
import { blog } from '@vyuh/react-feature-blog';
import { marketing } from '@vyuh/react-feature-marketing';
// Use only if you want to pre-render all routes
// export async function generateStaticParams() {
// return await fetchSlugs();
// }
export async function generateStaticParams() {
return await fetchSlugs();
}

const plugins = new PluginDescriptor({
content: new DefaultContentPlugin(),
});

const features = () => [system, marketing];

export default async function DynamicRoute({
params,
Expand All @@ -16,5 +28,17 @@ export default async function DynamicRoute({
? `/${allParams.slug.join('/')}`
: `/${allParams.slug ?? ''}`;

return <RouteLoader url={slug} allowRefresh={true} live={true} />;
const data: ContentItem = await fetchSlug(slug);
console.log('>>>>>>');
console.log(data);
return (
<RouteLoaderNext
renderContent={plugins.content.render}
features={features}
data={data}
url={slug}
allowRefresh={true}
live={true}
/>
);
}
17 changes: 17 additions & 0 deletions apps/demo/app/[...slug]/sanity-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createClient } from '@sanity/client';

export const client = createClient({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!,
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET!,
apiVersion: 'vX',
useCdn: false,
token: process.env.NEXT_PUBLIC_SANITY_TOKEN!,
perspective: 'drafts',
});

export async function fetchSlug(slug: string) {
const response: any = await client.fetch(
`*[_type == "vyuh.route" && path == "${slug}"][0]`,
);
return response;
}
4 changes: 2 additions & 2 deletions apps/demo/app/client-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { misc } from '@/features/misc-feature';
import { NextNavigationPlugin } from '@/plugins/next-navigation-plugin';
import { PluginDescriptor, VyuhProvider } from '@vyuh/react-core';
import { DefaultContentPlugin } from '@vyuh/react-extension-content';
import { system } from '@vyuh/react-feature-system';
import { auth } from '@vyuh/react-feature-auth';
import { blog } from '@vyuh/react-feature-blog';
import { marketing } from '@vyuh/react-feature-marketing';

import { system } from '@vyuh/react-feature-system';
import { SanityContentProvider } from '@vyuh/react-plugin-content-provider-sanity';
import { ReactNode } from 'react';

Expand All @@ -25,7 +25,7 @@ const sanityProvider = new SanityContentProvider({
});

const plugins = new PluginDescriptor({
content: new DefaultContentPlugin(sanityProvider),
content: new DefaultContentPlugin(),
navigation: new NextNavigationPlugin(),
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import {
executeAction,
LayoutConfiguration,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Accordion as AccordionItem } from '@/content/Accordion/accordion';
import { DefaultAccordionLayout } from '@/content/Accordion/default-accordion-layout';
import { cn } from '@/shared/utils';
import { executeAction } from '@vyuh/react-core';
import React, { useState } from 'react';
import React from 'react';

interface AccordionProps {
content: AccordionItem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import { Banner as BannerItem } from '@/content/banner/banner';
import { DefaultBannerLayout } from '@/content/banner/default-banner-layout';
import { cn } from '@/shared/utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import { DefaultHeaderLayout } from '@/content/header/default-header-layout';
import { Header as HeaderItem } from '@/content/header/header';
import { cn } from '@/shared/utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import { cn } from '@/shared/utils';
import { Moon, Palette, Sun } from 'lucide-react';
import React, { useEffect, useState } from 'react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import { DefaultPricingLayout } from '@/content/pricing/default-pricing-layout';
import { Pricing as PricingContent } from '@/content/pricing/pricing';
import { Section } from '@/shared/components/Section';
Expand Down
14 changes: 8 additions & 6 deletions packages/react-extension-content/src/default-content-plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import React from 'react';
*/
export class DefaultContentPlugin extends ContentPlugin {
private extensionBuilder?: ContentExtensionBuilder;
constructor(provider: ContentProvider) {
super('vyuh.plugin.content.default', 'Default Content Plugin', provider);
constructor() {
super('vyuh.plugin.content.default', 'Default Content Plugin', {});
}

getItem<T extends SchemaItem>(
Expand All @@ -43,8 +43,10 @@ export class DefaultContentPlugin extends ContentPlugin {
json: Record<string, any> | ContentItem,
options?: { layout: LayoutConfiguration },
): React.ReactNode {
const schemaType = json.schemaType ?? this.provider.schemaType(json);

console.log(json);
const schemaType = json.schemaType ?? 'ContentBuilder';
console.log('>@@@@');
console.log(json);
// Wrap the renderer in an error boundary to isolate rendering errors
return (
<ErrorBoundary title={`Failed to render: ${schemaType}`}>
Expand Down Expand Up @@ -78,12 +80,12 @@ export class DefaultContentPlugin extends ContentPlugin {

async dispose(): Promise<void> {
// Dispose the content provider
return this.provider.dispose();
// return this.provider.dispose();
}

async init(): Promise<void> {
// Initialize the content provider
return this.provider.init();
// return this.provider.init();
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/react-extension-content/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './ui/document-loader';
export * from './ui/route-loader';
export * from './ui/route-loader-next';
export * from './ui/async-content-container';

export * from './content-builder';
Expand Down
57 changes: 57 additions & 0 deletions packages/react-extension-content/src/ui/route-loader-next.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { ContentItem, FeatureDescriptor } from '@vyuh/react-core';

/**
* Props for the RouteLoader component
*/
export interface RouteLoaderNextProps<TContent extends ContentItem> {
/**
* The URL to fetch the route for
*/
url?: string;

features: () => FeatureDescriptor[] | Promise<FeatureDescriptor[]>;

/**
* Custom render function for the content
* If not provided, uses the content plugin's render method
*/
renderContent?: (
content: TContent,
) => React.ReactNode;
/**
* Data object for conent
*/
data: TContent;
/**
* The route ID to fetch the route for
*/
routeId?: string;

/**
* Whether to allow refreshing the route
*/
allowRefresh?: boolean;

/**
* Whether to use live updates (observable-based) instead of one-time loading
*/
live?: boolean;
}

/**
* A component that loads and renders a route from a URL or route ID
*/
export async function RouteLoaderNext({
url,
data,
features,
renderContent,
routeId,
allowRefresh = true,
live = false,
}: RouteLoaderNextProps<ContentItem>) {
const returnFeature = await features();
console.log(returnFeature);
console.log('take'+ data);
return <div>{renderContent(data)}</div>;
}
Loading