From d539fdf0bb454e645b57e1c0c5cb867c33d6b227 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Tue, 10 Sep 2024 15:03:47 -0700 Subject: [PATCH] formatting source --- app/client/web/src/App.tsx | 2 +- app/client/web/src/access/Access.tsx | 8 +- app/client/web/src/access/useAccess.hook.ts | 7 +- .../web/src/context/useAppContext.hook.ts | 8 +- app/client/web/src/identity/Identity.tsx | 75 ++-- .../web/src/identity/useIdentity.hook.ts | 29 +- app/client/web/src/root/useRoot.hook.ts | 11 +- app/client/web/src/session/Session.module.css | 17 +- app/client/web/src/session/Session.tsx | 91 ++-- app/client/web/src/settings/Settings.tsx | 388 +++++++++++------- .../web/src/settings/useSettings.hook.ts | 254 +++++++----- 11 files changed, 533 insertions(+), 357 deletions(-) diff --git a/app/client/web/src/App.tsx b/app/client/web/src/App.tsx index 2e912c24..f886ef16 100644 --- a/app/client/web/src/App.tsx +++ b/app/client/web/src/App.tsx @@ -88,7 +88,7 @@ const theme = createTheme({ '#559e83', '#559e83', ], - 'light-databag-green': [ + 'light-databag-green': [ '#888888', '#448844', '#448844', diff --git a/app/client/web/src/access/Access.tsx b/app/client/web/src/access/Access.tsx index ddf473eb..d4cc0975 100644 --- a/app/client/web/src/access/Access.tsx +++ b/app/client/web/src/access/Access.tsx @@ -22,7 +22,7 @@ import { IconServer, IconKey, } from '@tabler/icons-react' -import { modals } from '@mantine/modals'; +import { modals } from '@mantine/modals' export function Access() { const { state, actions } = useAccess() @@ -65,12 +65,10 @@ export function Access() { backgroundOpacity: 0.55, blur: 3, }, - children: ( -
{state.strings.tryAgain}
- ), + children:
{state.strings.tryAgain}
, cancelProps: { display: 'none' }, confirmProps: { display: 'none' }, - }); + }) } } actions.setLoading(false) diff --git a/app/client/web/src/access/useAccess.hook.ts b/app/client/web/src/access/useAccess.hook.ts index 00efb3a2..e7c56452 100644 --- a/app/client/web/src/access/useAccess.hook.ts +++ b/app/client/web/src/access/useAccess.hook.ts @@ -45,7 +45,7 @@ export function useAccess() { } const { protocol, host } = location - updateState({ host, secure: protocol === 'https' }); + updateState({ host, secure: protocol === 'https' }) }, []) useEffect(() => { @@ -121,8 +121,9 @@ export function useAccess() { updateState({ code }) }, setNode: (host: string) => { - const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(host); - updateState({ host, secure: !insecure }); + const insecure = + /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(host) + updateState({ host, secure: !insecure }) }, setLanguage: (code: string) => { display.actions.setLanguage(code) diff --git a/app/client/web/src/context/useAppContext.hook.ts b/app/client/web/src/context/useAppContext.hook.ts index e33e4acb..7c95c4be 100644 --- a/app/client/web/src/context/useAppContext.hook.ts +++ b/app/client/web/src/context/useAppContext.hook.ts @@ -53,12 +53,12 @@ export function useAppContext() { code, params ) - updateState({ session: login }); + updateState({ session: login }) }, accountLogout: async () => { if (state.session) { await sdk.current.logout(state.session, false) - updateState({ session: null }); + updateState({ session: null }) } }, accountCreate: async ( @@ -87,7 +87,7 @@ export function useAppContext() { token, params ) - updateState({ session }); + updateState({ session }) }, accountAccess: async (node: string, secure: boolean, token: string) => { const params = { @@ -102,7 +102,7 @@ export function useAppContext() { appName: 'databag', } const session = await sdk.current.access(node, secure, token, params) - updateState({ session }); + updateState({ session }) }, getAvailable: async (node: string, secure: boolean) => { return await sdk.current.available(node, secure) diff --git a/app/client/web/src/identity/Identity.tsx b/app/client/web/src/identity/Identity.tsx index c4e3d7b7..c40487a2 100644 --- a/app/client/web/src/identity/Identity.tsx +++ b/app/client/web/src/identity/Identity.tsx @@ -1,32 +1,43 @@ -import { useState } from 'react'; -import classes from './Identity.module.css'; -import { useIdentity } from './useIdentity.hook'; -import { Text, Image, Menu, Switch } from '@mantine/core'; +import { useState } from 'react' +import classes from './Identity.module.css' +import { useIdentity } from './useIdentity.hook' +import { Text, Image, Menu, Switch } from '@mantine/core' import { IconLogout, IconChevronRight, IconSettings, - IconAddressBook + IconAddressBook, } from '@tabler/icons-react' -import { modals } from '@mantine/modals'; +import { modals } from '@mantine/modals' -export function Identity({ settings, contacts }: { settings: () => void, contacts: () => void }) { - const { state, actions } = useIdentity(); - const [all, setAll] = useState(false); +export function Identity({ + settings, + contacts, +}: { + settings: () => void + contacts: () => void +}) { + const { state, actions } = useIdentity() + const [all, setAll] = useState(false) - const logout = () => modals.openConfirmModal({ - title: state.strings.confirmLogout, - withCloseButton: false, - overlayProps: { - backgroundOpacity: 0.55, - blur: 3, - }, - children: ( - actions.setAll(ev.currentTarget.checked)} /> - ), - labels: { confirm: state.strings.logout, cancel: state.strings.cancel }, - onConfirm: actions.logout, - }); + const logout = () => + modals.openConfirmModal({ + title: state.strings.confirmLogout, + withCloseButton: false, + overlayProps: { + backgroundOpacity: 0.55, + blur: 3, + }, + children: ( + actions.setAll(ev.currentTarget.checked)} + /> + ), + labels: { confirm: state.strings.logout, cancel: state.strings.cancel }, + onConfirm: actions.logout, + }) return ( @@ -34,22 +45,30 @@ export function Identity({ settings, contacts }: { settings: () => void, contact
- { !state.profile.name && ( + {!state.profile.name && ( {state.strings.name} )} - { state.profile.name && ( + {state.profile.name && ( {state.profile.name} )} - {`${state.profile.handle}${state.profile.node ? '/' + state.profile.node : ''}`} + {`${state.profile.handle}${state.profile.node ? '/' + state.profile.node : ''}`}
- }>{ state.strings.settings } - }>{ state.strings.contacts } - }>{ state.strings.logout } + }> + {state.strings.settings} + + }> + {state.strings.contacts} + + }> + {state.strings.logout} +
) diff --git a/app/client/web/src/identity/useIdentity.hook.ts b/app/client/web/src/identity/useIdentity.hook.ts index 99a66cff..771497c2 100644 --- a/app/client/web/src/identity/useIdentity.hook.ts +++ b/app/client/web/src/identity/useIdentity.hook.ts @@ -2,7 +2,7 @@ import { useState, useContext, useEffect } from 'react' import { DisplayContext } from '../context/DisplayContext' import { AppContext } from '../context/AppContext' import { ContextType } from '../context/ContextType' -import { Profile } from 'databag-client-sdk'; +import { Profile } from 'databag-client-sdk' export function useIdentity() { const app = useContext(AppContext) as ContextType @@ -13,7 +13,7 @@ export function useIdentity() { profile: {} as Profile, profileSet: false, imageUrl: null, - }); + }) // eslint-disable-next-line @typescript-eslint/no-explicit-any const updateState = (value: any) => { @@ -21,29 +21,32 @@ export function useIdentity() { } useEffect(() => { - const identity = app.state.session?.getIdentity(); + const identity = app.state.session?.getIdentity() if (!identity) { - console.log('session not set in identity hook'); - } - else { + console.log('session not set in identity hook') + } else { const setProfile = (profile: Profile) => { - updateState({ profile, profileSet: true, imageUrl: identity.getProfileImageUrl() }) + updateState({ + profile, + profileSet: true, + imageUrl: identity.getProfileImageUrl(), + }) } identity.addProfileListener(setProfile) return () => { - identity.removeProfileListener(setProfile); + identity.removeProfileListener(setProfile) } } - }, []); + }, []) const actions = { setAll: (all: boolean) => { - updateState({ all }); + updateState({ all }) }, logout: async () => { - await app.actions.accountLogout(state.all); + await app.actions.accountLogout(state.all) }, - }; + } - return { state, actions }; + return { state, actions } } diff --git a/app/client/web/src/root/useRoot.hook.ts b/app/client/web/src/root/useRoot.hook.ts index 6003e9b5..2d8e6625 100644 --- a/app/client/web/src/root/useRoot.hook.ts +++ b/app/client/web/src/root/useRoot.hook.ts @@ -25,16 +25,15 @@ export function useRoot() { useEffect(() => { const { pathname, node, session } = app.state || {} - const path = pathname === '/session' || pathname === '/node' || pathname === '/access' ? pathname : '/'; + const path = + pathname === '/session' || pathname === '/node' || pathname === '/access' + ? pathname + : '/' if (path === '/session' && !session) { navigate('/') } else if (path === '/node' && !node) { navigate('/') - } else if ( - path === '/' && - !session && - !node - ) { + } else if (path === '/' && !session && !node) { navigate('/access') } else if (path !== '/node' && node) { navigate('/node') diff --git a/app/client/web/src/session/Session.module.css b/app/client/web/src/session/Session.module.css index 837c8c09..ae19ae2e 100644 --- a/app/client/web/src/session/Session.module.css +++ b/app/client/web/src/session/Session.module.css @@ -13,17 +13,16 @@ height: 100%; width: 33%; min-width: 325px; - background: var(--mantine-color-surface-2); + background: var(--mantine-color-surface-2); } .right { height: 100%; display: flex; flex-grow: 1; - background: var(--mantine-color-surface-3); + background: var(--mantine-color-surface-3); } } - .screen { width: 100%; @@ -33,7 +32,7 @@ background-color: var(--mantine-color-surface-1); overflow: auto; padding-bottom: 16px; - } + } .tabs { position: absolute; @@ -48,8 +47,8 @@ display: flex; align-items: center; justify-content: center; - background: var(--mantine-color-tab-2); - color: var(--mantine-color-dbgreen-1); + background: var(--mantine-color-tab-2); + color: var(--mantine-color-dbgreen-1); padding-bottom: 8px; padding-top: 8px; cursor: pointer; @@ -61,14 +60,14 @@ display: flex; align-items: center; justify-content: center; - background: var(--mantine-color-tab-1); - color: var(--mantine-color-dbgreen-0); + background: var(--mantine-color-tab-1); + color: var(--mantine-color-dbgreen-0); padding-bottom: 8px; padding-top: 8px; cursor: pointer; &:hover { - background: var(--mantine-color-tab-3); + background: var(--mantine-color-tab-3); } } diff --git a/app/client/web/src/session/Session.tsx b/app/client/web/src/session/Session.tsx index 893e4d59..ec08eed2 100644 --- a/app/client/web/src/session/Session.tsx +++ b/app/client/web/src/session/Session.tsx @@ -1,72 +1,99 @@ import React, { useState, useContext } from 'react' import { Text, Drawer, Button } from '@mantine/core' import { AppContext } from '../context/AppContext' -import { DisplayContext } from '../context/DisplayContext'; +import { DisplayContext } from '../context/DisplayContext' import { ContextType } from '../context/ContextType' import classes from './Session.module.css' -import { IconAddressBook, IconMessages, IconSettings } from '@tabler/icons-react' -import { Settings } from '../settings/Settings'; -import { Identity } from '../identity/Identity'; -import { useDisclosure } from '@mantine/hooks'; +import { + IconAddressBook, + IconMessages, + IconSettings, +} from '@tabler/icons-react' +import { Settings } from '../settings/Settings' +import { Identity } from '../identity/Identity' +import { useDisclosure } from '@mantine/hooks' export function Session() { - const [ tab, setTab ] = useState('channels'); + const [tab, setTab] = useState('channels') const app = useContext(AppContext) as ContextType const display = useContext(DisplayContext) as ContextType - const [settings, { open: openSettings, close: closeSettings }] = useDisclosure(false); + const [settings, { open: openSettings, close: closeSettings }] = + useDisclosure(false) const click = () => { - console.log("SESSION DRAWER", openSettings); - openSettings(); + console.log('SESSION DRAWER', openSettings) + openSettings() } return (
- { display.state.layout === 'small' && ( + {display.state.layout === 'small' && ( <>
- { tab === 'settings' && ( - - )} + {tab === 'settings' && }
- { tab === 'channels' && ( -
+ {tab === 'channels' && ( +
+ +
)} - { tab !== 'channels' && ( -
setTab('channels')}>
+ {tab !== 'channels' && ( +
setTab('channels')} + > + +
)}
- { tab === 'contacts' && ( -
+ {tab === 'contacts' && ( +
+ +
)} - { tab !== 'contacts' && ( -
setTab('contacts')}>
+ {tab !== 'contacts' && ( +
setTab('contacts')} + > + +
)}
- { tab === 'settings' && ( -
+ {tab === 'settings' && ( +
+ +
)} - { tab !== 'settings' && ( -
setTab('settings')}>
+ {tab !== 'settings' && ( +
setTab('settings')} + > + +
)}
)} - { display.state.layout === 'large' && ( + {display.state.layout === 'large' && (
{}} />
-
-
- +
+
)}
- ); + ) } - - diff --git a/app/client/web/src/settings/Settings.tsx b/app/client/web/src/settings/Settings.tsx index 108414ab..5a3bd8c8 100644 --- a/app/client/web/src/settings/Settings.tsx +++ b/app/client/web/src/settings/Settings.tsx @@ -1,135 +1,170 @@ -import { useSettings } from './useSettings.hook'; -import { Modal, Textarea, TextInput, PasswordInput, Radio, Group, Select, Switch, Text, Image, Button, UnstyledButton } from '@mantine/core'; -import classes from './Settings.module.css'; -import { IconLock, IconUser, IconClock, IconIdBadge, IconCalendar, IconUsers, IconVideo, IconMicrophone, IconWorld, IconBrightness, IconTicket, IconCloudLock, IconBell, IconEye, IconBook, IconMapPin, IconLogout, IconLogin } from '@tabler/icons-react' -import { modals } from '@mantine/modals'; +import { useSettings } from './useSettings.hook' +import { + Modal, + Textarea, + TextInput, + PasswordInput, + Radio, + Group, + Select, + Switch, + Text, + Image, + Button, + UnstyledButton, +} from '@mantine/core' +import classes from './Settings.module.css' +import { + IconLock, + IconUser, + IconClock, + IconIdBadge, + IconCalendar, + IconUsers, + IconVideo, + IconMicrophone, + IconWorld, + IconBrightness, + IconTicket, + IconCloudLock, + IconBell, + IconEye, + IconBook, + IconMapPin, + IconLogout, + IconLogin, +} from '@tabler/icons-react' +import { modals } from '@mantine/modals' import { useDisclosure } from '@mantine/hooks' import { useCallback, useState, useRef } from 'react' -import Cropper from 'react-easy-crop'; -import { Area } from 'react-easy-crop/types'; +import Cropper from 'react-easy-crop' +import { Area } from 'react-easy-crop/types' export function Settings({ showLogout }: { showLogout: boolean }) { - const imageFile = useRef(null as null | HTMLInputElement); - const { state, actions } = useSettings(); - const [changeOpened, { open: changeOpen, close: changeClose }] = useDisclosure(false) - const [detailsOpened, { open: detailsOpen, close: detailsClose }] = useDisclosure(false) - const [imageOpened, { open: imageOpen, close: imageClose }] = useDisclosure(false) - const [savingLogin, setSavingLogin] = useState(false); - const [savingDetails, setSavingDetails] = useState(false); - const [savingImage, setSavingImage] = useState(false); - const [savingRegistry, setSavingRegistry] = useState(false); - const [savingNotifications, setSavingNotifications] = useState(false); + const imageFile = useRef(null as null | HTMLInputElement) + const { state, actions } = useSettings() + const [changeOpened, { open: changeOpen, close: changeClose }] = + useDisclosure(false) + const [detailsOpened, { open: detailsOpen, close: detailsClose }] = + useDisclosure(false) + const [imageOpened, { open: imageOpen, close: imageClose }] = + useDisclosure(false) + const [savingLogin, setSavingLogin] = useState(false) + const [savingDetails, setSavingDetails] = useState(false) + const [savingImage, setSavingImage] = useState(false) + const [savingRegistry, setSavingRegistry] = useState(false) + const [savingNotifications, setSavingNotifications] = useState(false) - const logout = () => modals.openConfirmModal({ - title: state.strings.confirmLogout, - withCloseButton: false, - overlayProps: { - backgroundOpacity: 0.55, - blur: 3, - }, - children: ( - actions.setAll(ev.currentTarget.checked)} /> - ), - labels: { confirm: state.strings.logout, cancel: state.strings.cancel }, - onConfirm: actions.logout, - }); + const logout = () => + modals.openConfirmModal({ + title: state.strings.confirmLogout, + withCloseButton: false, + overlayProps: { + backgroundOpacity: 0.55, + blur: 3, + }, + children: ( + actions.setAll(ev.currentTarget.checked)} + /> + ), + labels: { confirm: state.strings.logout, cancel: state.strings.cancel }, + onConfirm: actions.logout, + }) const setRegistry = async (checked: boolean) => { if (!savingRegistry) { - setSavingRegistry(true); + setSavingRegistry(true) try { if (checked) { - await actions.enableRegistry(); + await actions.enableRegistry() } else { - await actions.disableRegistry(); + await actions.disableRegistry() } + } catch (err) { + console.log(err) + showError() } - catch (err) { - console.log(err); - showError(); - } - setSavingRegistry(false); + setSavingRegistry(false) } } const setNotifications = async (checked: boolean) => { if (!savingNotifications) { - setSavingNotifications(true); + setSavingNotifications(true) try { if (checked) { - await actions.enableNotifications(); + await actions.enableNotifications() } else { - await actions.disableNotifications(); + await actions.disableNotifications() } + } catch (err) { + console.log(err) + showError() } - catch (err) { - console.log(err); - showError(); - } - setSavingNotifications(false); + setSavingNotifications(false) } } const setDetails = async () => { if (!savingDetails) { - setSavingDetails(true); + setSavingDetails(true) try { - await actions.setDetails(); - detailsClose(); + await actions.setDetails() + detailsClose() + } catch (err) { + console.log(err) + showError() } - catch (err) { - console.log(err); - showError(); - } - setSavingDetails(false); + setSavingDetails(false) } } const clickSelect = () => { if (imageFile.current) { - imageFile.current.click(); + imageFile.current.click() } } const selectImage = (target: HTMLInputElement) => { if (target.files) { - var reader = new FileReader(); + var reader = new FileReader() reader.onload = () => { if (typeof reader.result === 'string') { - actions.setEditImage(reader.result); + actions.setEditImage(reader.result) } } - reader.readAsDataURL(target.files[0]); + reader.readAsDataURL(target.files[0]) } } const setImage = async () => { if (!savingImage) { - setSavingImage(true); + setSavingImage(true) try { - await actions.setImage(); - imageClose(); + await actions.setImage() + imageClose() + } catch (err) { + console.log(err) + showError() } - catch (err) { - console.log(err); - showError(); - } - setSavingImage(false); + setSavingImage(false) } } const setLogin = async () => { - if (!savingLogin) { - setSavingLogin(true); + if (!savingLogin) { + setSavingLogin(true) try { - await actions.setLogin(); - changeClose(); + await actions.setLogin() + changeClose() + } catch (err) { + console.log(err) + showError() } - catch (err) { - console.log(err); - showError(); - } - setSavingLogin(false); + setSavingLogin(false) } } @@ -141,58 +176,71 @@ export function Settings({ showLogout }: { showLogout: boolean }) { backgroundOpacity: 0.55, blur: 3, }, - children: ( - {state.strings.tryAgain} - ), + children: {state.strings.tryAgain}, cancelProps: { display: 'none' }, confirmProps: { display: 'none' }, - }); + }) } const onCropComplete = useCallback((crop: Area) => { actions.setEditImageCrop(crop) // eslint-disable-next-line - }, []); + }, []) return ( <> - { state.profileSet && ( + {state.profileSet && (
- {`${state.profile.handle}${state.profile.node ? '/' + state.profile.node : ''}`} + {`${state.profile.handle}${state.profile.node ? '/' + state.profile.node : ''}`}
- { state.profile.imageSet && ( + {state.profile.imageSet && (
- +
- +
)} - { !state.profile.imageSet && ( + {!state.profile.imageSet && (
- - { state.strings.edit } + + {state.strings.edit}
)}
- { state.strings.edit } + + {state.strings.edit} +
- { !state.profile.name && ( + {!state.profile.name && ( {state.strings.name} )} - { state.profile.name && ( + {state.profile.name && ( {state.profile.name} )}
- { !state.profile.location && ( - {state.strings.location} + {!state.profile.location && ( + + {state.strings.location} + )} - { state.profile.location && ( + {state.profile.location && ( {state.profile.location} )}
@@ -200,11 +248,15 @@ export function Settings({ showLogout }: { showLogout: boolean }) {
- { !state.profile.description && ( - {state.strings.description} + {!state.profile.description && ( + + {state.strings.description} + )} - { state.profile.description && ( - {state.profile.description} + {state.profile.description && ( + + {state.profile.description} + )}
@@ -212,43 +264,59 @@ export function Settings({ showLogout }: { showLogout: boolean }) {
- { state.strings.registry } - setRegistry(ev.currentTarget.checked)} /> + {state.strings.registry} + setRegistry(ev.currentTarget.checked)} + />
- { state.strings.manageTopics } + + {state.strings.manageTopics} +
- { state.strings.enableNotifications } - setNotifications(ev.currentTarget.checked)} /> + + {state.strings.enableNotifications} + + setNotifications(ev.currentTarget.checked)} + />
- { showLogout && ( + {showLogout && (
- { state.strings.logout } + + {state.strings.logout} +
)}
- { state.strings.mfaTitle } + {state.strings.mfaTitle}
- { state.strings.changeLogin } + + {state.strings.changeLogin} +
@@ -256,7 +324,9 @@ export function Settings({ showLogout }: { showLogout: boolean }) {
- { state.strings.timeFormat } + + {state.strings.timeFormat} + - - + +
@@ -273,7 +343,9 @@ export function Settings({ showLogout }: { showLogout: boolean }) {
- { state.strings.dateFormat } + + {state.strings.dateFormat} + - - + +
@@ -290,7 +362,9 @@ export function Settings({ showLogout }: { showLogout: boolean }) {
- { state.strings.theme } + + {state.strings.theme} +
- { state.strings.microphone } + + {state.strings.microphone} + @@ -357,9 +443,7 @@ export function Settings({ showLogout }: { showLogout: boolean }) { leftSection={} rightSection={state.taken ? : null} placeholder={state.strings.username} - onChange={(event) => - actions.setHandle(event.currentTarget.value) - } + onChange={(event) => actions.setHandle(event.currentTarget.value)} error={state.taken} /> } placeholder={state.strings.password} - onChange={(event) => - actions.setPassword(event.currentTarget.value) - } + onChange={(event) => actions.setPassword(event.currentTarget.value)} /> } placeholder={state.strings.confirmPassword} - onChange={(event) => - actions.setConfirm(event.currentTarget.value) - } + onChange={(event) => actions.setConfirm(event.currentTarget.value)} />
@@ -412,9 +498,7 @@ export function Settings({ showLogout }: { showLogout: boolean }) { leftSectionPointerEvents="none" leftSection={} placeholder={state.strings.name} - onChange={(event) => - actions.setName(event.currentTarget.value) - } + onChange={(event) => actions.setName(event.currentTarget.value)} /> } placeholder={state.strings.location} - onChange={(event) => - actions.setLocation(event.currentTarget.value) - } + onChange={(event) => actions.setLocation(event.currentTarget.value)} />