forked from codeisneverodd/programmers-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsols.tsx
112 lines (106 loc) · 3.24 KB
/
sols.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
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
104
105
106
107
108
109
110
111
112
import MainLayout from "@/lib/@components/MainLayout";
import useProbs from "@/lib/@hooks/useProbs";
import useSols from "@/lib/@hooks/useSols";
import {
AlertDialog,
AlertDialogBody,
AlertDialogContent,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogOverlay,
Box,
Button,
Code,
Flex,
Icon,
IconButton,
Text,
useDisclosure
} from "@chakra-ui/react";
import { faXmarkCircle } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useRef, useState } from "react";
import { Sol } from "./api/sol";
export default function Home() {
const { probQuery } = useProbs();
const { solsQuery, deleteSolMutation } = useSols();
const { isOpen, onOpen, onClose } = useDisclosure();
const [targetSol, setTargetSol] = useState<Sol | null>(null);
const cancelRef = useRef(null);
if (!probQuery.data || !solsQuery.data)
return (
<MainLayout title="Home">
<Text>Loading...</Text>
</MainLayout>
);
return (
<MainLayout title="Home">
<Text>New Template</Text>
<Button>해설 목록 갱신</Button>
<Text fontWeight="bold">해설 수 : {solsQuery.data.length}</Text>
{solsQuery.data
.slice()
.sort((a, b) =>
a.probId === b.probId
? a.createdAt - b.createdAt
: +a.probId - +b.probId
)
.map(s => (
<Flex key={s.id} alignItems="center" gap="20px" w="full">
<Text>
{probQuery.data.find(p => p.id === s.probId)?.title ?? ""} |{" "}
{s.author} | {s.id} | {new Date(s.createdAt).toLocaleString()}
</Text>
<IconButton
size="sm"
icon={<Icon as={FontAwesomeIcon} icon={faXmarkCircle} />}
aria-label="문제 삭제"
onClick={() => {
setTargetSol(s);
onOpen();
}}
/>
</Flex>
))}
{targetSol && (
<AlertDialog
isOpen={isOpen}
leastDestructiveRef={cancelRef}
onClose={onClose}
size="2xl"
>
<AlertDialogOverlay>
<AlertDialogContent>
<AlertDialogHeader fontSize="lg" fontWeight="bold">
아래 해설을 삭제할까요?
</AlertDialogHeader>
<AlertDialogBody>
<Text>생성일: {targetSol.createdAt}</Text>
<Text>아이디: {targetSol.id}</Text>
코드
<Box as="pre" overflow="scroll" p="12px">
<Code>{targetSol.code}</Code>
</Box>
</AlertDialogBody>
<AlertDialogFooter>
<Button ref={cancelRef} onClick={onClose}>
취소
</Button>
<Button
colorScheme="red"
onClick={() => {
deleteSolMutation.mutate({ solId: targetSol.id });
onClose();
}}
ml={3}
>
삭제
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialogOverlay>
</AlertDialog>
)}
</MainLayout>
);
}