From 97268397d68e17a5c81d5c5ca4d822a094b9a9d6 Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Wed, 11 Aug 2021 19:50:42 -0400 Subject: [PATCH] add dialogs frfr --- src/components/EventCreator/EventCreator.tsx | 8 ++--- .../EventCreator/EventCreatorLink.tsx | 6 ++-- src/components/Group/Group.tsx | 11 +++++-- src/components/Group/GroupMembersLink.tsx | 14 ++++++--- src/components/Group/GroupSettings.tsx | 29 ++++++++++++++---- src/components/Group/GroupSettingsLink.tsx | 6 ++-- src/components/GroupCreator/GroupCreator.tsx | 2 +- .../GroupCreator/GroupCreatorLink.tsx | 19 +++++------- src/components/GroupJoinerLink.tsx | 30 +++++++++++-------- src/components/Groups/Groups.tsx | 6 ++-- src/components/UI/UIDialogShell.tsx | 23 ++++++++++++++ src/components/UI/UISecondaryBox.tsx | 11 ++++++- src/components/UI/UITextInput.tsx | 6 ++-- 13 files changed, 118 insertions(+), 53 deletions(-) create mode 100644 src/components/UI/UIDialogShell.tsx diff --git a/src/components/EventCreator/EventCreator.tsx b/src/components/EventCreator/EventCreator.tsx index 6becab4..5a0be7e 100644 --- a/src/components/EventCreator/EventCreator.tsx +++ b/src/components/EventCreator/EventCreator.tsx @@ -84,11 +84,11 @@ export default function EventCreator({ group }: { group: IGroup }) { ]); return ( - -

+ +

Create Event -

-

{group.name}

+

+

{group.name}

Name
diff --git a/src/components/EventCreator/EventCreatorLink.tsx b/src/components/EventCreator/EventCreatorLink.tsx index 2310b14..8719c08 100644 --- a/src/components/EventCreator/EventCreatorLink.tsx +++ b/src/components/EventCreator/EventCreatorLink.tsx @@ -1,5 +1,6 @@ import { useContext } from 'react'; import { GroupContext } from '../Group/Group'; +import UIDialogShell from '../UI/UIDialogShell'; import UIPressable from '../UI/UIPressable'; import useToggle from '../useToggle'; import EventCreator from './EventCreator'; @@ -12,10 +13,9 @@ export default function EventCreatorLink() { <> Create Event {open && ( - <> -
+ - + )} ); diff --git a/src/components/Group/Group.tsx b/src/components/Group/Group.tsx index 4650344..4ece291 100644 --- a/src/components/Group/Group.tsx +++ b/src/components/Group/Group.tsx @@ -30,7 +30,14 @@ export default function Group({ id }: { id: number }) { useEffect(() => { setLoading(true); getGroup(id) - .then(setGroup) + .then((group) => { + // @ts-ignore + if ('status' in group && group.status === 'error') { + setGroup(null); + } else { + setGroup(group); + } + }) .finally(() => setLoading(false)); }, [id, setGroup]); @@ -54,7 +61,7 @@ export default function Group({ id }: { id: number }) { style={{ display: 'flex', flexDirection: 'column', - minWidth: '10rem', + minWidth: '15rem', }} >

{group.name}

diff --git a/src/components/Group/GroupMembersLink.tsx b/src/components/Group/GroupMembersLink.tsx index 1b17f4c..5f78c93 100644 --- a/src/components/Group/GroupMembersLink.tsx +++ b/src/components/Group/GroupMembersLink.tsx @@ -1,6 +1,7 @@ import { useCallback, useContext, useMemo, useState } from 'react'; import { addGroupAdmin, removeGroupAdmin } from '../api'; import { useMe } from '../hooks'; +import UIDialogShell from '../UI/UIDialogShell'; import UIPressable from '../UI/UIPressable'; import UISecondaryBox from '../UI/UISecondaryBox'; import { GroupContext } from './Group'; @@ -47,9 +48,14 @@ export default function GroupMembersLink() { <> Members {open && ( - <> -
- + setOpen(false)}> +

Members

{group.users.map(({ name, id }) => ( @@ -71,7 +77,7 @@ export default function GroupMembersLink() {
- +
)} ); diff --git a/src/components/Group/GroupSettings.tsx b/src/components/Group/GroupSettings.tsx index b7a5f0b..e230333 100644 --- a/src/components/Group/GroupSettings.tsx +++ b/src/components/Group/GroupSettings.tsx @@ -9,6 +9,8 @@ export default function GroupSettings({ group }: { group: IGroup }) { const [deletionSuccessful, setDeletionSuccessful] = useState(null); + const [confirmingDeletion, setConfirmingDeletion] = useState(false); + const onClickedDelete = useCallback(() => { deleteGroup(group.id) .then(({ status }) => { @@ -19,12 +21,29 @@ export default function GroupSettings({ group }: { group: IGroup }) { }); }, [group.id]); + const confirmDeletion = useCallback(() => { + setConfirmingDeletion(false); + onClickedDelete(); + }, [onClickedDelete]); + + const cancelDeletion = useCallback(() => { + setConfirmingDeletion(false); + }, [setConfirmingDeletion]); + return ( - -

Settings

- {deletionSuccessful !== true && ( - Delete Group - )} + +

Settings

+ {deletionSuccessful !== true && + (confirmingDeletion ? ( + <> + Confirm + Cancel + + ) : ( + setConfirmingDeletion(true)}> + Delete Group + + ))} {deletionSuccessful !== null && (deletionSuccessful ? ( diff --git a/src/components/Group/GroupSettingsLink.tsx b/src/components/Group/GroupSettingsLink.tsx index ccdc50e..a7179e9 100644 --- a/src/components/Group/GroupSettingsLink.tsx +++ b/src/components/Group/GroupSettingsLink.tsx @@ -1,4 +1,5 @@ import { useContext } from 'react'; +import UIDialogShell from '../UI/UIDialogShell'; import UIPressable from '../UI/UIPressable'; import useToggle from '../useToggle'; import { GroupContext } from './Group'; @@ -12,10 +13,9 @@ export default function GroupSettingsLink() { <> Settings {open && ( - <> -
+ - + )} ); diff --git a/src/components/GroupCreator/GroupCreator.tsx b/src/components/GroupCreator/GroupCreator.tsx index 199814b..c681dc1 100644 --- a/src/components/GroupCreator/GroupCreator.tsx +++ b/src/components/GroupCreator/GroupCreator.tsx @@ -28,7 +28,7 @@ export default function GroupCreator() { const buttonEnabled = name.length > 0 && !creating; return ( - +

Create Group

Name diff --git a/src/components/GroupCreator/GroupCreatorLink.tsx b/src/components/GroupCreator/GroupCreatorLink.tsx index 313e787..b53055f 100644 --- a/src/components/GroupCreator/GroupCreatorLink.tsx +++ b/src/components/GroupCreator/GroupCreatorLink.tsx @@ -1,25 +1,20 @@ -import GroupCreator from './GroupCreator'; +import UIButton from '../UI/UIButton'; +import UIDialogShell from '../UI/UIDialogShell'; import useToggle from '../useToggle'; +import GroupCreator from './GroupCreator'; export default function GroupCreatorLink() { const [open, toggle] = useToggle(false); return (
-
+ Create Group -
+ {open && ( - <> -
+ - + )}
); diff --git a/src/components/GroupJoinerLink.tsx b/src/components/GroupJoinerLink.tsx index aa1764d..9553037 100644 --- a/src/components/GroupJoinerLink.tsx +++ b/src/components/GroupJoinerLink.tsx @@ -2,7 +2,6 @@ import { useCallback, useEffect, useState } from 'react'; import { joinGroup, resolveCode } from './api'; import UIButton from './UI/UIButton'; import UIPressable from './UI/UIPressable'; -import UISecondaryBox from './UI/UISecondaryBox'; import UITextInput from './UI/UITextInput'; import useToggle from './useToggle'; @@ -11,19 +10,21 @@ export type GroupPreview = { id: number; }; -function GroupJoiner() { +export function GroupJoiner() { const [code, setCode] = useState(''); const [joining, setJoining] = useState(false); const [group, setGroup] = useState(null); useEffect(() => { - const initialCode = code; - resolveCode(code).then((group) => { - if (code === initialCode) { - setGroup(group); - } - }); + if (code) { + const initialCode = code; + resolveCode(code).then((group) => { + if (code === initialCode) { + setGroup(group); + } + }); + } }, [code]); const join = useCallback(() => { @@ -44,10 +45,13 @@ function GroupJoiner() { const buttonEnabled = code.length > 0 && !joining; return ( - -

Join Group

- Code - +
+ Join group with code: + {group && ( <>
@@ -62,7 +66,7 @@ function GroupJoiner() { )} - +
); } diff --git a/src/components/Groups/Groups.tsx b/src/components/Groups/Groups.tsx index 76b3aac..4325511 100644 --- a/src/components/Groups/Groups.tsx +++ b/src/components/Groups/Groups.tsx @@ -1,8 +1,8 @@ import { useEffect, useState } from 'react'; import { getGroups } from '../api'; -import { IGroup } from '../types'; import GroupCreatorLink from '../GroupCreator/GroupCreatorLink'; -import GroupJoinerLink from '../GroupJoinerLink'; +import { GroupJoiner } from '../GroupJoinerLink'; +import { IGroup } from '../types'; import GroupList from './GroupList'; export default function Groups() { @@ -21,7 +21,7 @@ export default function Groups() { }} >

Groups

- +

diff --git a/src/components/UI/UIDialogShell.tsx b/src/components/UI/UIDialogShell.tsx new file mode 100644 index 0000000..488748e --- /dev/null +++ b/src/components/UI/UIDialogShell.tsx @@ -0,0 +1,23 @@ +export default function UIDialogShell({ + children, + onClose, +}: { + children: React.ReactNode; + onClose: () => void; +}) { + return ( +
+ {children} +
+ ); +} diff --git a/src/components/UI/UISecondaryBox.tsx b/src/components/UI/UISecondaryBox.tsx index 185c6dc..93c68e6 100644 --- a/src/components/UI/UISecondaryBox.tsx +++ b/src/components/UI/UISecondaryBox.tsx @@ -13,9 +13,11 @@ const baseStyle: CSSProperties = { export default function UISecondaryBox({ children, style, + cancelClicks = true, }: { children: ReactNode; style?: CSSProperties; + cancelClicks?: boolean; }) { const computedStyle = useMemo(() => { if (!style) { @@ -23,5 +25,12 @@ export default function UISecondaryBox({ } return { ...baseStyle, ...style }; }, [style]); - return
{children}
; + return ( +
e.stopPropagation() } : {})} + > + {children} +
+ ); } diff --git a/src/components/UI/UITextInput.tsx b/src/components/UI/UITextInput.tsx index cdb9bff..2de7134 100644 --- a/src/components/UI/UITextInput.tsx +++ b/src/components/UI/UITextInput.tsx @@ -1,4 +1,4 @@ -import { useCallback } from 'react'; +import { CSSProperties, useCallback } from 'react'; const baseStyle = { marginTop: '0.5em', @@ -13,10 +13,12 @@ export default function UITextInput({ value, disabled = false, onChangeText, + style, }: { value: string; disabled?: boolean; onChangeText: (text: string) => void; + style?: CSSProperties; }) { const onChange = useCallback( (e) => onChangeText(e.target.value), @@ -24,7 +26,7 @@ export default function UITextInput({ ); return (