Skip to content

Commit 34b5c09

Browse files
authored
Merge pull request #11 from will-lp1/add-toolbar
Add toolbar, and improve sidebar document switching
2 parents 16cef98 + 35bacb6 commit 34b5c09

6 files changed

Lines changed: 388 additions & 579 deletions

File tree

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { notFound } from 'next/navigation';
22
import { getUser } from '@/app/(auth)/auth';
3-
import { getDocumentById } from '@/lib/db/queries';
3+
import { getDocumentsById } from '@/lib/db/queries';
44
import { AlwaysVisibleArtifact } from '@/components/always-visible-artifact';
55
import { checkSubscriptionStatus } from '@/lib/subscription';
66
import { Paywall } from '@/components/paywall';
7+
import type { Document } from '@snow-leopard/db';
78

89
export const dynamic = 'auto';
910
export const dynamicParams = true;
@@ -13,45 +14,54 @@ export default async function DocumentPage(props: { params: Promise<{ id: string
1314
try {
1415
const documentId = params.id;
1516

17+
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
18+
if (!uuidRegex.test(documentId)) {
19+
console.warn(`[DocumentPage] Invalid document ID format: ${documentId}`);
20+
return notFound();
21+
}
22+
1623
const { hasActiveSubscription } = await checkSubscriptionStatus();
1724

1825
if (!hasActiveSubscription) {
1926
return <Paywall isOpen={true} required={true} />;
2027
}
2128

22-
const [document, user] = await Promise.all([
23-
getDocumentById({ id: documentId }),
29+
const [documentsResult, user] = await Promise.all([
30+
getDocumentsById({ ids: [documentId], userId: 'placeholder' }),
2431
getUser(),
2532
]);
2633

2734
if (!user) {
28-
console.warn(`[documents/[id]/page.tsx] User ${documentId}: Active subscription status but no logged-in user found by getUser(). Redirecting.`);
29-
return notFound(); // Or redirect('/login')
35+
console.warn(`[DocumentPage] User not found after subscription check. Redirecting.`);
36+
return notFound();
3037
}
3138

32-
if (!document || user.id !== document.userId) {
33-
if (!document) {
34-
return (
35-
<AlwaysVisibleArtifact
36-
chatId="placeholder-for-artifact"
37-
initialDocumentId="init"
38-
showCreateDocumentForId={documentId}
39-
/>
40-
);
41-
} else {
42-
return notFound();
43-
}
44-
}
39+
const documents: Document[] = await getDocumentsById({ ids: [documentId], userId: user.id });
4540

41+
if (!documents || documents.length === 0) {
42+
console.log(`[DocumentPage] Document ${documentId} not found for user ${user.id}. Showing create prompt.`);
43+
return (
44+
<AlwaysVisibleArtifact
45+
chatId="placeholder-for-artifact"
46+
initialDocumentId="init"
47+
initialDocuments={[]}
48+
showCreateDocumentForId={documentId}
49+
user={user}
50+
/>
51+
);
52+
}
53+
4654
return (
4755
<AlwaysVisibleArtifact
4856
chatId="placeholder-for-artifact"
4957
initialDocumentId={documentId}
58+
initialDocuments={documents}
59+
user={user}
5060
/>
5161
);
5262

5363
} catch (error) {
54-
console.error(`Page error for document ${params.id}:`, error);
64+
console.error(`[DocumentPage] Page error for document ${params.id}:`, error);
5565
return notFound();
5666
}
5767
}

apps/snow-leopard/app/documents/page.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { redirect } from 'next/navigation';
2-
import { getSession } from '@/app/(auth)/auth';
2+
import { getSession, getUser } from '@/app/(auth)/auth';
33
import { AlwaysVisibleArtifact } from '@/components/always-visible-artifact';
44
import { checkSubscriptionStatus } from '@/lib/subscription';
55
import { Paywall } from '@/components/paywall';
@@ -13,12 +13,21 @@ export default async function Page() {
1313

1414
const { hasActiveSubscription } = await checkSubscriptionStatus();
1515

16+
// Fetch user data for passing to client component
17+
const user = await getUser();
18+
if (!user) {
19+
// If getUser fails, redirect to login or home
20+
redirect('/');
21+
}
22+
1623
return (
1724
<>
1825
{hasActiveSubscription ? (
1926
<AlwaysVisibleArtifact
20-
chatId="new-chat"
21-
initialDocumentId="init"
27+
chatId="new-chat"
28+
initialDocumentId="init"
29+
initialDocuments={[]} // No existing docs for new chat
30+
user={user}
2231
/>
2332
) : (
2433
<Paywall isOpen={true} required={true} />

apps/snow-leopard/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default function Home() {
8888

8989
<div className="flex flex-col items-center max-w-4xl mb-32">
9090
{/* START ADD: Add Snow Leopard GIF */}
91-
<div className="mb-8 w-full max-w-xs sm:max-w-sm md:max-w-md lg:max-w-lg xl:max-w-xl p-1 bg-muted/30 rounded-xl border border-border/50 shadow-inner">
91+
<div className="mt-4 mb-8 w-full max-w-xs sm:max-w-sm md:max-w-md lg:max-w-lg xl:max-w-xl p-1 bg-muted/30 rounded-xl border border-border/50 shadow-inner">
9292
<img
9393
src="/demo.gif"
9494
alt="Snow Leopard demo"

0 commit comments

Comments
 (0)