({ problem }: { problem: Problem })
| 18 | import { updateProblem } from "../utils"; |
| 19 | |
| 20 | const ProblemCard = ({ problem }: { problem: Problem }) => { |
| 21 | const [isEditing, setIsEditing] = useState(false); |
| 22 | const [id, setId] = useState(problem.id); |
| 23 | const [title, setTitle] = useState(problem.title); |
| 24 | const [description, setDescription] = useState(problem.description); |
| 25 | const [type, setType] = useState(problem.type); |
| 26 | const [notionDocId, setNotionDocId] = useState(problem.notionDocId); |
| 27 | function handleEdit(id: string) { |
| 28 | if (isEditing) { |
| 29 | updateProblem(problem.id, { id, title, description, type, notionDocId }); |
| 30 | return setIsEditing(false); |
| 31 | } |
| 32 | setIsEditing(true); |
| 33 | } |
| 34 | function handleDiscardButton() { |
| 35 | setTitle(problem.title); |
| 36 | setDescription(problem.description); |
| 37 | setType(problem.type); |
| 38 | setNotionDocId(problem.notionDocId); |
| 39 | setIsEditing(false); |
| 40 | } |
| 41 | return ( |
| 42 | <Card key={problem.id}> |
| 43 | {!isEditing && ( |
| 44 | <div> |
| 45 | <CardHeader> |
| 46 | <div className="flex justify-between items-start"> |
| 47 | <div> |
| 48 | <CardTitle>{id}</CardTitle> |
| 49 | <CardTitle>{title}</CardTitle> |
| 50 | </div> |
| 51 | <div className="flex gap-4 items-center"> |
| 52 | <Button variant={"outline"} className="" onClick={() => handleEdit(problem.id)}> |
| 53 | Edit |
| 54 | </Button> |
| 55 | </div> |
| 56 | </div> |
| 57 | <CardDescription>{description}</CardDescription> |
| 58 | <CardDescription>{type}</CardDescription> |
| 59 | </CardHeader> |
| 60 | <CardContent>{notionDocId}</CardContent> |
| 61 | </div> |
| 62 | )} |
| 63 | {isEditing && ( |
| 64 | <div> |
| 65 | <CardHeader> |
| 66 | <div className="flex justify-between"> |
| 67 | <div> |
| 68 | <CardTitle> |
| 69 | <Input onChange={(e) => setId(e.target.value)} value={id} /> |
| 70 | </CardTitle> |
| 71 | <CardTitle> |
| 72 | <Input onChange={(e) => setTitle(e.target.value)} value={title} /> |
| 73 | </CardTitle> |
| 74 | </div> |
| 75 | <div className="space-x-3"> |
| 76 | <Button variant={"outline"} className="" onClick={() => handleDiscardButton()}> |
| 77 | Discard |
nothing calls this directly
no test coverage detected