forked from alan2207/bulletproof-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Discussion.tsx
51 lines (45 loc) · 1.63 KB
/
Discussion.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 { useParams } from 'react-router-dom';
import { Spinner, MDPreview } from '@/components/Elements';
import { Head } from '@/components/Head';
import { ContentLayout } from '@/components/Layout';
import { Comments } from '@/features/comments';
import { formatDate } from '@/utils/format';
import { useDiscussion } from '../api/getDiscussion';
import { UpdateDiscussion } from '../components/UpdateDiscussion';
export const Discussion = () => {
const { discussionId } = useParams();
const discussionQuery = useDiscussion({ discussionId });
if (discussionQuery.isLoading) {
return (
<div className="w-full h-48 flex justify-center items-center">
<Spinner size="lg" />
</div>
);
}
if (!discussionQuery.data) return null;
return (
<>
<Head title={discussionQuery.data.title} />
<ContentLayout title={discussionQuery.data.title}>
<span className="text-xs font-bold">{formatDate(discussionQuery.data.createdAt)}</span>
<div className="mt-6 flex flex-col space-y-16">
<div className="flex justify-end">
<UpdateDiscussion discussionId={discussionId} />
</div>
<div>
<div className="bg-white shadow overflow-hidden 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={discussionQuery.data.body} />
</div>
</div>
</div>
</div>
<div>
<Comments discussionId={discussionId} />
</div>
</div>
</ContentLayout>
</>
);
};