|
8 | 8 | Selection, |
9 | 9 | useDragAndDrop, |
10 | 10 | } from "react-aria-components"; |
11 | | -import { useModalRef } from "../misc/useModalRef"; |
12 | | -import { GenericModal } from "../GenericModal"; |
| 11 | +import { Modal, ModalContent } from "../components/modal/Modal.tsx"; |
13 | 12 |
|
14 | 13 | interface Layer { |
15 | 14 | id: number; |
@@ -49,56 +48,62 @@ const EditLabelModal = ({ |
49 | 48 | }: { |
50 | 49 | open: boolean; |
51 | 50 | onClose: () => void; |
52 | | - editLabelData: EditLabelData; |
| 51 | + editLabelData: EditLabelData | null; |
53 | 52 | handleSaveNewLabel: ( |
54 | 53 | id: number, |
55 | 54 | oldName: string, |
56 | 55 | newName: string | null |
57 | 56 | ) => void; |
58 | 57 | }) => { |
59 | | - const ref = useModalRef(open); |
60 | | - const [newLabelName, setNewLabelName] = useState(editLabelData.name); |
| 58 | + const [newLabelName, setNewLabelName] = useState(editLabelData?.name ?? ''); |
61 | 59 |
|
62 | | - const handleSave = () => { |
| 60 | + const handleSave = useCallback(() => { |
| 61 | + if (!editLabelData) return |
| 62 | + |
63 | 63 | handleSaveNewLabel(editLabelData.id, editLabelData.name, newLabelName); |
64 | 64 | onClose(); |
65 | | - }; |
| 65 | + }, [editLabelData]); |
66 | 66 |
|
67 | 67 | return ( |
68 | | - <GenericModal |
69 | | - ref={ref} |
70 | | - onClose={onClose} |
71 | | - className="min-w-min w-[30vw] flex flex-col" |
72 | | - > |
73 | | - <span className="mb-3 text-lg">New Layer Name</span> |
74 | | - <input |
75 | | - className="p-1 border rounded border-base-content border-solid" |
76 | | - type="text" |
77 | | - defaultValue={editLabelData.name} |
78 | | - autoFocus |
79 | | - onChange={(e) => setNewLabelName(e.target.value)} |
80 | | - onKeyDown={(e) => { |
81 | | - if (e.key === "Enter") { |
82 | | - e.preventDefault(); |
83 | | - handleSave(); |
84 | | - } |
85 | | - }} |
86 | | - /> |
87 | | - <div className="mt-4 flex justify-end"> |
88 | | - <button className="py-1.5 px-2" type="button" onClick={onClose}> |
89 | | - Cancel |
90 | | - </button> |
91 | | - <button |
92 | | - className="py-1.5 px-2 ml-4 rounded-md bg-gray-100 text-black hover:bg-gray-300" |
93 | | - type="button" |
94 | | - onClick={() => { |
95 | | - handleSave(); |
96 | | - }} |
97 | | - > |
98 | | - Save |
99 | | - </button> |
100 | | - </div> |
101 | | - </GenericModal> |
| 68 | + <Modal open={open} onOpenChange={onClose}> |
| 69 | + <ModalContent |
| 70 | + className="min-w-min w-[30vw] flex flex-col" |
| 71 | + > |
| 72 | + {editLabelData && ( |
| 73 | + <> |
| 74 | + <span className="mb-3 text-lg">New Layer Name</span> |
| 75 | + <input |
| 76 | + className="p-1 border rounded border-base-content border-solid" |
| 77 | + type="text" |
| 78 | + defaultValue={editLabelData.name} |
| 79 | + autoFocus |
| 80 | + onChange={(e) => setNewLabelName(e.target.value)} |
| 81 | + onKeyDown={(e) => { |
| 82 | + if (e.key === "Enter") { |
| 83 | + e.preventDefault(); |
| 84 | + handleSave(); |
| 85 | + } |
| 86 | + }} |
| 87 | + /> |
| 88 | + <div className="mt-4 flex justify-end"> |
| 89 | + <button className="py-1.5 px-2" type="button" onClick={onClose}> |
| 90 | + Cancel |
| 91 | + </button> |
| 92 | + <button |
| 93 | + className="py-1.5 px-2 ml-4 rounded-md bg-gray-100 text-black hover:bg-gray-300" |
| 94 | + type="button" |
| 95 | + disabled={!!editLabelData} |
| 96 | + onClick={() => { |
| 97 | + handleSave(); |
| 98 | + }} |
| 99 | + > |
| 100 | + Save |
| 101 | + </button> |
| 102 | + </div> |
| 103 | + </> |
| 104 | + )} |
| 105 | + </ModalContent> |
| 106 | + </Modal> |
102 | 107 | ); |
103 | 108 | }; |
104 | 109 |
|
@@ -190,14 +195,14 @@ export const LayerPicker = ({ |
190 | 195 | </button> |
191 | 196 | )} |
192 | 197 | </div> |
193 | | - {editLabelData !== null && ( |
194 | | - <EditLabelModal |
195 | | - open={editLabelData !== null} |
196 | | - onClose={() => setEditLabelData(null)} |
197 | | - editLabelData={editLabelData} |
198 | | - handleSaveNewLabel={handleSaveNewLabel} |
199 | | - /> |
200 | | - )} |
| 198 | + |
| 199 | + <EditLabelModal |
| 200 | + open={!!editLabelData} |
| 201 | + onClose={() => setEditLabelData(null)} |
| 202 | + editLabelData={editLabelData} |
| 203 | + handleSaveNewLabel={handleSaveNewLabel} |
| 204 | + /> |
| 205 | + |
201 | 206 | <ListBox |
202 | 207 | aria-label="Keymap Layer" |
203 | 208 | selectionMode="single" |
|
0 commit comments