Skip to content
Merged
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
4 changes: 4 additions & 0 deletions packages/chronicle/src/server/App.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.fallback {
padding: var(--rs-space-8);
width: 80%;
}
47 changes: 32 additions & 15 deletions packages/chronicle/src/server/App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import '@raystack/apsara/normalize.css';
import '@raystack/apsara/style.css';
import { ThemeProvider } from '@raystack/apsara';
import { ThemeProvider, Skeleton, Flex } from '@raystack/apsara';
import { lazy, Suspense } from 'react';
import { Navigate, useLocation } from 'react-router';
import { Head } from '@/lib/head';
import { usePageContext } from '@/lib/page-context';
import { resolveRoute, RouteType } from '@/lib/route-resolver';
import { ApiLayout } from '@/pages/ApiLayout';
import { ApiPage } from '@/pages/ApiPage';
import { DocsLayout } from '@/pages/DocsLayout';
import { DocsPage } from '@/pages/DocsPage';
import { LandingPage } from '@/pages/LandingPage';
import type { ChronicleConfig } from '@/types';
import { getThemeConfig } from '@/themes/registry';
import styles from './App.module.css';

const ApiLayout = lazy(() => import('@/pages/ApiLayout').then(m => ({ default: m.ApiLayout })));
const ApiPage = lazy(() => import('@/pages/ApiPage').then(m => ({ default: m.ApiPage })));
const DocsLayout = lazy(() => import('@/pages/DocsLayout').then(m => ({ default: m.DocsLayout })));
const DocsPage = lazy(() => import('@/pages/DocsPage').then(m => ({ default: m.DocsPage })));
const LandingPage = lazy(() => import('@/pages/LandingPage').then(m => ({ default: m.LandingPage })));

export function App() {
const { pathname } = useLocation();
Expand All @@ -35,19 +38,33 @@ export function App() {
forcedTheme={themeConfig.forcedTheme}
>
<RootHead config={config} />
{isApi ? (
<ApiLayout>
<ApiPage slug={apiSlug} />
</ApiLayout>
) : (
<DocsLayout hideSidebar={isLanding}>
{isLanding ? <LandingPage /> : <DocsPage slug={docsSlug} />}
</DocsLayout>
)}
<Suspense fallback={<PageFallback />}>
{isApi ? (
<ApiLayout>
<ApiPage slug={apiSlug} />
</ApiLayout>
) : (
<DocsLayout hideSidebar={isLanding}>
{isLanding ? <LandingPage /> : <DocsPage slug={docsSlug} />}
</DocsLayout>
)}
</Suspense>
</ThemeProvider>
);
}

function PageFallback() {
return (
<Flex direction="column" gap={4} className={styles.fallback}>
<Skeleton width="40%" height="var(--rs-line-height-t2)" />
<Skeleton width="60%" height="var(--rs-line-height-regular)" />
{[...new Array(12)].map((_, i) => (
<Skeleton key={i} width="100%" height="var(--rs-line-height-regular)" />
))}
</Flex>
);
}

function RootHead({ config }: { config: ChronicleConfig }) {
return (
<Head
Expand Down
35 changes: 20 additions & 15 deletions packages/chronicle/src/themes/default/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import {
import { Flex, IconButton, Button, Sidebar } from '@raystack/apsara';
import { PlayIcon } from '@radix-ui/react-icons';
import { cx } from 'class-variance-authority';
import { useState, useEffect, useMemo, useRef } from 'react';
import { useState, useEffect, useMemo, useRef, lazy, Suspense } from 'react';
import { Link as RouterLink, useLocation, useNavigate } from 'react-router';
import type { OpenAPIV3 } from 'openapi-types';
import { MethodBadge } from '@/components/api/method-badge';
import { useApiOperation } from '@/lib/use-api-operation';
import { PlaygroundDialog } from '@/components/api/playground-dialog';

const PlaygroundDialog = lazy(() => import('@/components/api/playground-dialog').then(m => ({ default: m.PlaygroundDialog })));
import { ClientThemeSwitcher } from '@/components/ui/client-theme-switcher';
import { Search } from '@/components/ui/search';
import { Breadcrumbs } from '@/components/ui/breadcrumbs';
Expand Down Expand Up @@ -144,7 +145,7 @@ export function Layout({
))}
{apiEntries.map(api => (
<Sidebar.Item
key={api.basePath}
key={`${api.basePath}-${api.name}`}
href={api.basePath}
active={isApiBase(api.basePath)}
leadingIcon={renderConfigIcon(
Expand Down Expand Up @@ -371,18 +372,22 @@ function TestRequestButton() {
>
Test request
</Button>
<PlaygroundDialog
key={`${match.spec.name}-${match.path}-${match.method}`}
open={open}
onOpenChange={setOpen}
method={match.method}
path={match.path}
operation={match.operation}
serverUrl={match.spec.server.url}
specName={match.spec.name}
auth={match.spec.auth}
document={match.spec.document}
/>
{open && (
<Suspense fallback={null}>
<PlaygroundDialog
key={`${match.spec.name}-${match.path}-${match.method}`}
open={open}
onOpenChange={setOpen}
method={match.method}
path={match.path}
operation={match.operation}
serverUrl={match.spec.server.url}
specName={match.spec.name}
auth={match.spec.auth}
document={match.spec.document}
/>
</Suspense>
)}
</>
);
}
Expand Down
8 changes: 6 additions & 2 deletions packages/chronicle/src/themes/default/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use client';

import { Flex, Headline } from '@raystack/apsara';
import { lazy, Suspense } from 'react';
import type { ThemePageProps } from '@/types';
import styles from './Page.module.css';
import { Toc } from './Toc';

const Toc = lazy(() => import('./Toc').then(m => ({ default: m.Toc })));

export function Page({ page }: ThemePageProps) {
return (
Expand All @@ -16,7 +18,9 @@ export function Page({ page }: ThemePageProps) {
)}
<div className={styles.content}>{page.content}</div>
</article>
<Toc items={page.toc} />
<Suspense fallback={null}>
<Toc items={page.toc} />
</Suspense>
</Flex>
);
}
Loading