From c38fe9ef66708777702370d8b20b8725668bf89f Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 9 Feb 2021 19:19:36 +0100 Subject: [PATCH] feat(SnackbarProvider): interface update | wrap around phone --- phone/src/Phone.tsx | 23 +++++++++------- phone/src/ui/components/SnackbarProvider.tsx | 29 +++++++++++++++++--- phone/src/ui/hooks/useSnackbar.ts | 2 +- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 547f0c0..bbca10f 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -32,6 +32,7 @@ import { useModal } from './modal/hooks/useModal'; import { useDialService } from './apps/dialer/hooks/useDialService'; import InjectDebugData from './os/debug/InjectDebugData'; import { useQuickAccess } from './os/notifications/hooks/useQuickAccess'; +import SnackbarProvider from './ui/components/SnackbarProvider'; InjectDebugData([ { @@ -151,16 +152,18 @@ function Phone() { }))} />
- {modal ? ( - - ) : ( - <> - - {allApps.map((App) => ( - - ))} - - )} + + {modal ? ( + + ) : ( + <> + + {allApps.map((App) => ( + + ))} + + )} +
diff --git a/phone/src/ui/components/SnackbarProvider.tsx b/phone/src/ui/components/SnackbarProvider.tsx index 7947098..4df39a6 100644 --- a/phone/src/ui/components/SnackbarProvider.tsx +++ b/phone/src/ui/components/SnackbarProvider.tsx @@ -1,12 +1,25 @@ import React, { createContext, useState, useEffect, useMemo, useCallback } from 'react'; -import { SnackBar } from './SnackBar'; +import Alert from './Alert'; +import { makeStyles } from '@material-ui/core/styles'; +import { Snackbar } from '@material-ui/core'; + +const useStyles = makeStyles(() => ({ + alert: { + position: 'absolute', + bottom: '15%', + right: '25%', + margin: '0 auto', + textAlign: 'center' + } +})) export const SnackbarContext = createContext(null); -const AUTO_HIDE = 2000; +const AUTO_HIDE = 1500; function SnackbarProvider({ children }) { const [alerts, setAlerts] = useState([]); + const classes = useStyles(); const alertIdx = alerts.join(','); @@ -21,8 +34,16 @@ function SnackbarProvider({ children }) { return ( - {children} - {alerts.map((alert) => {alert})} + <> + {children} + {alerts.map((alert) => ( +
+ + {alert} + +
+ ))} +
) } diff --git a/phone/src/ui/hooks/useSnackbar.ts b/phone/src/ui/hooks/useSnackbar.ts index fe6077a..ee9dd33 100644 --- a/phone/src/ui/hooks/useSnackbar.ts +++ b/phone/src/ui/hooks/useSnackbar.ts @@ -2,7 +2,7 @@ import { useContext } from 'react'; import { SnackbarContext } from '../components/SnackbarProvider'; interface ISnackBar { - addAlert: (message: string, severity: string) => void; + addAlert: (message: string, type: string) => void; } export const useSnackbar = (): ISnackBar => useContext(SnackbarContext); \ No newline at end of file