-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
discussion-view.tsx
51 lines (45 loc) · 1.48 KB
/
discussion-view.tsx
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
import { MDPreview } from '@/components/ui/md-preview';
import { Spinner } from '@/components/ui/spinner';
import { formatDate } from '@/utils/format';
import { useDiscussion } from '../api/get-discussion';
import { UpdateDiscussion } from '../components/update-discussion';
export const DiscussionView = ({ discussionId }: { discussionId: string }) => {
const discussionQuery = useDiscussion({
discussionId,
});
if (discussionQuery.isLoading) {
return (
<div className="flex h-48 w-full items-center justify-center">
<Spinner size="lg" />
</div>
);
}
const discussion = discussionQuery?.data?.data;
if (!discussion) return null;
return (
<div>
<span className="text-xs font-bold">
{formatDate(discussion.createdAt)}
</span>
{discussion.author && (
<span className="ml-2 text-sm font-bold">
by {discussion.author.firstName} {discussion.author.lastName}
</span>
)}
<div className="mt-6 flex flex-col space-y-16">
<div className="flex justify-end">
<UpdateDiscussion discussionId={discussionId} />
</div>
<div>
<div className="overflow-hidden bg-white shadow sm:rounded-lg">
<div className="px-4 py-5 sm:px-6">
<div className="mt-1 max-w-2xl text-sm text-gray-500">
<MDPreview value={discussion.body} />
</div>
</div>
</div>
</div>
</div>
</div>
);
};