refactor: replace AdminPageHeader with PageShell
Migrate pages to PageShell, add global autofill styles, and update SDK/simulator page logic for server URL and state consistency.
This commit is contained in:
1 parent
fa4516b078
commit
81c5e4e2fd
24 files changed
+1238
-595
No files matched your search
+75
-51
@@ -1,24 +1,35 @@
|
||||
'use client';
|
||||
|
||||
import { AdminPageHeader } from '@/components/layout/AdminPageHeader';
|
||||
import { PageShell } from '@/components/layout/PageShell';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { CodeBlock } from '@/components/ui/CodeBlock';
|
||||
import { Select } from '@/components/ui/Input';
|
||||
import { Panel } from '@/components/ui/Panel';
|
||||
import { StatStrip } from '@/components/ui/StatStrip';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { getCached, setCached } from '@/lib/vconCache';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export default function SdkGuidePage() {
|
||||
const { success } = useToast();
|
||||
const [clients, setClients] = useState<any[]>(() => getCached<any[]>('vcon:clients', []));
|
||||
const [clients, setClients] = useState<any[]>(() =>
|
||||
getCached<any[]>('vcon:clients', [])
|
||||
);
|
||||
const [selectedClientId, setSelectedClientId] = useState<string>(() => {
|
||||
const cached = getCached<any[]>('vcon:clients', []);
|
||||
return cached[0]?.clientId ?? '';
|
||||
});
|
||||
const [serverUrl, setServerUrl] = useState<string>('http://localhost:4000');
|
||||
|
||||
useEffect(() => {
|
||||
const isLocalDev = window.location.port === '3000';
|
||||
setServerUrl(
|
||||
isLocalDev
|
||||
? `${window.location.protocol}//${window.location.hostname}:4000`
|
||||
: window.location.origin
|
||||
);
|
||||
|
||||
async function loadClients() {
|
||||
try {
|
||||
const res = await fetch('/api/clients');
|
||||
@@ -37,13 +48,14 @@ export default function SdkGuidePage() {
|
||||
loadClients();
|
||||
}, []);
|
||||
|
||||
const activeClient = clients.find((c) => c.clientId === selectedClientId) || clients[0];
|
||||
const activeClient =
|
||||
clients.find((c) => c.clientId === selectedClientId) || clients[0];
|
||||
const sampleToken = activeClient?.token || 'YOUR_SIGNED_CLIENT_JWT_TOKEN';
|
||||
|
||||
const pythonSnippet = `from datastack_sdk import DataStackClient
|
||||
|
||||
client = DataStackClient(
|
||||
server_url="http://localhost:4000",
|
||||
server_url="${serverUrl}",
|
||||
token="${sampleToken}"
|
||||
)
|
||||
|
||||
@@ -69,55 +81,67 @@ if client.connect():
|
||||
};
|
||||
|
||||
return (
|
||||
<section className="w-full">
|
||||
<AdminPageHeader
|
||||
title="Python SDK"
|
||||
actions={
|
||||
<Button
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
icon="Copy"
|
||||
onClick={() => copySnippet(pythonSnippet, 'Snippet')}
|
||||
>
|
||||
Copy Code
|
||||
</Button>
|
||||
}
|
||||
<PageShell
|
||||
title="Python SDK"
|
||||
actions={
|
||||
<Button
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
icon="Copy"
|
||||
onClick={() => copySnippet(pythonSnippet, 'Snippet')}
|
||||
>
|
||||
Copy Code
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<StatStrip
|
||||
items={[
|
||||
{ label: 'SDK package', value: 'datastack_sdk', dot: 'ok' },
|
||||
{ label: 'Transport', value: 'Socket.IO / JWT' },
|
||||
{ label: 'Server endpoint', value: serverUrl },
|
||||
{
|
||||
label: 'Active client',
|
||||
value: activeClient?.clientId || 'None selected',
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
<div className="flex max-w-[860px] flex-col gap-2.5">
|
||||
<Card compact className="flex items-center justify-between bg-[var(--surface)] px-3 py-2 font-mono text-[11.5px]">
|
||||
<span className="text-[var(--accent)]">pip install ./sdk-python</span>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="Copy"
|
||||
onClick={() => copySnippet('pip install ./sdk-python', 'Pip command')}
|
||||
/>
|
||||
</Card>
|
||||
<Card
|
||||
compact
|
||||
className="flex w-full items-center justify-between bg-[var(--surface)] px-3 py-2 font-mono text-[11.5px]"
|
||||
>
|
||||
<span className="text-[var(--accent)]">pip install ./sdk-python</span>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="Copy"
|
||||
onClick={() => copySnippet('pip install ./sdk-python', 'Pip command')}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<Panel
|
||||
title="Client Snippet"
|
||||
action={
|
||||
clients.length > 0 ? (
|
||||
<div className="w-[170px]">
|
||||
<Select
|
||||
compact
|
||||
value={selectedClientId}
|
||||
onChange={(e) => setSelectedClientId(e.target.value)}
|
||||
>
|
||||
{clients.map((c) => (
|
||||
<option key={c.clientId} value={c.clientId}>
|
||||
{c.clientId}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
) : undefined
|
||||
}
|
||||
>
|
||||
<CodeBlock>{pythonSnippet}</CodeBlock>
|
||||
</Panel>
|
||||
</div>
|
||||
</section>
|
||||
<Panel
|
||||
title="Client Snippet"
|
||||
className="w-full"
|
||||
action={
|
||||
clients.length > 0 ? (
|
||||
<div className="w-[190px]">
|
||||
<Select
|
||||
compact
|
||||
value={selectedClientId}
|
||||
onChange={(e) => setSelectedClientId(e.target.value)}
|
||||
>
|
||||
{clients.map((c) => (
|
||||
<option key={c.clientId} value={c.clientId}>
|
||||
{c.clientId}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
) : undefined
|
||||
}
|
||||
>
|
||||
<CodeBlock>{pythonSnippet}</CodeBlock>
|
||||
</Panel>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user