-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpage.tsx
More file actions
103 lines (89 loc) · 2.7 KB
/
page.tsx
File metadata and controls
103 lines (89 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import ShareChatInput from '@/components/share/share-chat-input';
import ShareGroupedMessage from '@/components/share/share-grouped-message';
import ShareScrollTop from '@/components/share/share-scroll-top';
import { Button } from '@/components/ui/button';
import { getSnapshot } from '@/lib/firebase/firebase-admin';
import {
getCurrentUser,
getParties,
getSystemStatus,
} from '@/lib/firebase/firebase-server';
import { InternalReferrers } from '@/lib/internal-referrers';
import { cn, generateOgImageUrl } from '@/lib/utils';
import { ArrowLeftIcon } from 'lucide-react';
import Link from 'next/link';
import { redirect } from 'next/navigation';
type Props = {
searchParams: Promise<{
snapshot_id: string;
ref?: InternalReferrers;
}>;
};
export async function generateMetadata({ searchParams }: Props) {
const { snapshot_id } = await searchParams;
const snapshot = await getSnapshot(snapshot_id);
if (snapshot.party_ids.length > 1) {
return {};
}
const partyId = snapshot.party_ids[0];
const imageUrl = await generateOgImageUrl(partyId);
if (!imageUrl) {
return {};
}
return {
openGraph: {
images: [imageUrl],
},
};
}
async function SharePage({ searchParams }: Props) {
const { snapshot_id, ref } = await searchParams;
if (!snapshot_id) {
redirect('/');
}
const snapshot = await getSnapshot(snapshot_id);
const parties = await getParties();
const isFromTopics = ref === InternalReferrers.TOPICS;
const systemStatus = await getSystemStatus();
const user = await getCurrentUser();
return (
<div className="relative flex h-full min-h-[calc(100vh-var(--header-height)-16px)] flex-col gap-4">
<ShareScrollTop />
{isFromTopics && (
<Button variant="link" asChild className="mt-4 w-fit px-0">
<Link href="/topics">
<ArrowLeftIcon className="size-4" />
Zurück zur Themenübersicht
</Link>
</Button>
)}
<div
className={cn(
'flex grow flex-col gap-6 overflow-y-auto',
!isFromTopics && 'mt-4',
)}
>
{snapshot.messages.map((message) => (
<ShareGroupedMessage
key={message.id}
message={message}
parties={parties.filter((p) =>
snapshot.party_ids.includes(p.party_id),
)}
/>
))}
</div>
<ShareChatInput
snapshotId={snapshot_id}
quickReplies={
snapshot.messages.length > 1
? snapshot.messages[snapshot.messages.length - 1].quick_replies
: []
}
initialSystemStatus={systemStatus}
hasValidServerUser={!user?.isAnonymous}
/>
</div>
);
}
export default SharePage;