diff options
| author | Wolfboy248 <105884620+Wolfboy248@users.noreply.github.com> | 2024-10-20 00:27:38 +0200 |
|---|---|---|
| committer | Wolfboy248 <105884620+Wolfboy248@users.noreply.github.com> | 2024-10-20 00:27:38 +0200 |
| commit | 8c8edfc9c8bb1a0fa3d1e02aab576044857f1c95 (patch) | |
| tree | cf23b52befb9af6d16321b9e9031ace724543875 /frontend/src/components | |
| parent | backend: actually fix download demo (diff) | |
| download | lphub-8c8edfc9c8bb1a0fa3d1e02aab576044857f1c95.tar.gz lphub-8c8edfc9c8bb1a0fa3d1e02aab576044857f1c95.tar.bz2 lphub-8c8edfc9c8bb1a0fa3d1e02aab576044857f1c95.zip | |
refactor: custom modals
Diffstat (limited to 'frontend/src/components')
| -rw-r--r-- | frontend/src/components/ConfirmDialog.tsx | 31 | ||||
| -rw-r--r-- | frontend/src/components/MapDeleteConfirmDialog.tsx | 28 | ||||
| -rw-r--r-- | frontend/src/components/MessageDialog.tsx | 29 | ||||
| -rw-r--r-- | frontend/src/components/UseConfirm.tsx | 36 | ||||
| -rw-r--r-- | frontend/src/components/UseMessage.tsx | 27 |
5 files changed, 123 insertions, 28 deletions
diff --git a/frontend/src/components/ConfirmDialog.tsx b/frontend/src/components/ConfirmDialog.tsx new file mode 100644 index 0000000..c4299fd --- /dev/null +++ b/frontend/src/components/ConfirmDialog.tsx | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | import React from 'react'; | ||
| 2 | |||
| 3 | import "../css/Dialog.css" | ||
| 4 | |||
| 5 | interface ConfirmDialogProps { | ||
| 6 | title: string; | ||
| 7 | subtitle: string; | ||
| 8 | onConfirm: () => void; | ||
| 9 | onCancel: () => void; | ||
| 10 | }; | ||
| 11 | |||
| 12 | const ConfirmDialog: React.FC<ConfirmDialogProps> = ({ title, subtitle, onConfirm, onCancel }) => { | ||
| 13 | return ( | ||
| 14 | <div className='dimmer'> | ||
| 15 | <div className='dialog'> | ||
| 16 | <div className='dialog-element dialog-header'> | ||
| 17 | <span>{title}</span> | ||
| 18 | </div> | ||
| 19 | <div className='dialog-element dialog-description'> | ||
| 20 | <span>{subtitle}</span> | ||
| 21 | </div> | ||
| 22 | <div className='dialog-element dialog-btns-container'> | ||
| 23 | <button onClick={onCancel}>Cancel</button> | ||
| 24 | <button onClick={onConfirm}>Confirm</button> | ||
| 25 | </div> | ||
| 26 | </div> | ||
| 27 | </div> | ||
| 28 | ) | ||
| 29 | }; | ||
| 30 | |||
| 31 | export default ConfirmDialog; | ||
diff --git a/frontend/src/components/MapDeleteConfirmDialog.tsx b/frontend/src/components/MapDeleteConfirmDialog.tsx deleted file mode 100644 index 1518a14..0000000 --- a/frontend/src/components/MapDeleteConfirmDialog.tsx +++ /dev/null | |||
| @@ -1,28 +0,0 @@ | |||
| 1 | import React from 'react'; | ||
| 2 | |||
| 3 | import "../css/MapDeleteConfirmDialog.css" | ||
| 4 | |||
| 5 | interface MapDeleteConfirmDialogProps { | ||
| 6 | open: boolean; | ||
| 7 | onClose: () => void; | ||
| 8 | map_id: number; | ||
| 9 | record_id: number; | ||
| 10 | }; | ||
| 11 | |||
| 12 | const MapDeleteConfirmDialog: React.FC<MapDeleteConfirmDialogProps> = ({ open, onClose, map_id, record_id }) => { | ||
| 13 | if (open) { | ||
| 14 | return ( | ||
| 15 | <div className='dimmer'> | ||
| 16 | <div> | ||
| 17 | |||
| 18 | </div> | ||
| 19 | </div> | ||
| 20 | ) | ||
| 21 | } | ||
| 22 | |||
| 23 | return ( | ||
| 24 | <></> | ||
| 25 | ) | ||
| 26 | }; | ||
| 27 | |||
| 28 | export default MapDeleteConfirmDialog; | ||
diff --git a/frontend/src/components/MessageDialog.tsx b/frontend/src/components/MessageDialog.tsx new file mode 100644 index 0000000..0a8db42 --- /dev/null +++ b/frontend/src/components/MessageDialog.tsx | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | import React from 'react'; | ||
| 2 | |||
| 3 | import "../css/Dialog.css" | ||
| 4 | |||
| 5 | interface MessageDialogProps { | ||
| 6 | title: string; | ||
| 7 | subtitle: string; | ||
| 8 | onClose: () => void; | ||
| 9 | }; | ||
| 10 | |||
| 11 | const MessageDialog: React.FC<MessageDialogProps> = ({ title, subtitle, onClose }) => { | ||
| 12 | return ( | ||
| 13 | <div className='dimmer'> | ||
| 14 | <div className='dialog'> | ||
| 15 | <div className='dialog-element dialog-header'> | ||
| 16 | <span>{title}</span> | ||
| 17 | </div> | ||
| 18 | <div className='dialog-element dialog-description'> | ||
| 19 | <span>{subtitle}</span> | ||
| 20 | </div> | ||
| 21 | <div className='dialog-element dialog-btns-container'> | ||
| 22 | <button onClick={onClose}>Ok</button> | ||
| 23 | </div> | ||
| 24 | </div> | ||
| 25 | </div> | ||
| 26 | ) | ||
| 27 | } | ||
| 28 | |||
| 29 | export default MessageDialog; | ||
diff --git a/frontend/src/components/UseConfirm.tsx b/frontend/src/components/UseConfirm.tsx new file mode 100644 index 0000000..2fe0e12 --- /dev/null +++ b/frontend/src/components/UseConfirm.tsx | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | import React, { useState } from 'react'; | ||
| 2 | import ConfirmDialog from './ConfirmDialog'; | ||
| 3 | |||
| 4 | const useConfirm = ( title: string, subtitle: string ) => { | ||
| 5 | const [isOpen, setIsOpen] = useState(false); | ||
| 6 | const [resolvePromise, setResolvePromise] = useState<((value: boolean) => void) | null>(null); | ||
| 7 | |||
| 8 | const confirm = () => { | ||
| 9 | setIsOpen(true); | ||
| 10 | return new Promise((resolve) => { | ||
| 11 | setResolvePromise(() => resolve); | ||
| 12 | }); | ||
| 13 | }; | ||
| 14 | |||
| 15 | const handleConfirm = () => { | ||
| 16 | setIsOpen(false); | ||
| 17 | if (resolvePromise) { | ||
| 18 | resolvePromise(true); | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | const handleCancel = () => { | ||
| 23 | setIsOpen(false); | ||
| 24 | if (resolvePromise) { | ||
| 25 | resolvePromise(false); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | const ConfirmDialogComponent = isOpen && ( | ||
| 30 | <ConfirmDialog title={title} subtitle={subtitle} onConfirm={handleConfirm} onCancel={handleCancel}></ConfirmDialog> | ||
| 31 | ); | ||
| 32 | |||
| 33 | return { confirm, ConfirmDialogComponent }; | ||
| 34 | } | ||
| 35 | |||
| 36 | export default useConfirm; | ||
diff --git a/frontend/src/components/UseMessage.tsx b/frontend/src/components/UseMessage.tsx new file mode 100644 index 0000000..fbd3c82 --- /dev/null +++ b/frontend/src/components/UseMessage.tsx | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | import React, { useState } from 'react'; | ||
| 2 | import MessageDialog from "./MessageDialog"; | ||
| 3 | |||
| 4 | const useMessage = () => { | ||
| 5 | const [isOpen, setIsOpen] = useState(false); | ||
| 6 | |||
| 7 | const [title, setTitle] = useState<string>(""); | ||
| 8 | const [subtitle, setSubtitle] = useState<string>(""); | ||
| 9 | |||
| 10 | const message = (title: string, subtitle: string) => { | ||
| 11 | setIsOpen(true); | ||
| 12 | setTitle(title); | ||
| 13 | setSubtitle(subtitle); | ||
| 14 | }; | ||
| 15 | |||
| 16 | const handleClose = () => { | ||
| 17 | setIsOpen(false); | ||
| 18 | }; | ||
| 19 | |||
| 20 | const MessageDialogComponent = isOpen && ( | ||
| 21 | <MessageDialog title={title} subtitle={subtitle} onClose={handleClose}></MessageDialog> | ||
| 22 | ); | ||
| 23 | |||
| 24 | return { message, MessageDialogComponent }; | ||
| 25 | } | ||
| 26 | |||
| 27 | export default useMessage; | ||