From 6e72e2c50ee53aabfa5805264b707efce6b9dc4f Mon Sep 17 00:00:00 2001 From: Taso Date: Sat, 6 Mar 2021 17:32:01 -0500 Subject: [PATCH] fix(phone/snackbar): Fixed animations & simplified logic (#146) --- phone/src/Phone.tsx | 4 +-- phone/src/ui/components/Alert.tsx | 4 +-- .../{Snackbar.tsx => PhoneSnackbar.tsx} | 15 ++++++----- phone/src/ui/hooks/useSnackbar.ts | 2 ++ phone/src/ui/providers/SnackbarProvider.tsx | 26 +++++++++---------- 5 files changed, 27 insertions(+), 24 deletions(-) rename phone/src/ui/components/{Snackbar.tsx => PhoneSnackbar.tsx} (52%) diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 264bf63..7fe22ab 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -25,7 +25,7 @@ import { useCallService } from './os/call/hooks/useCallService'; import { useDialService } from './apps/dialer/hooks/useDialService'; import InjectDebugData from './os/debug/InjectDebugData'; import { usePhoneVisibility } from './os/phone/hooks/usePhoneVisibility'; -import { Snackbar } from './ui/components/Snackbar'; +import { PhoneSnackbar } from './ui/components/PhoneSnackbar'; import { NotificationAlert } from './os/notifications/components/NotificationAlert'; import { useCallModal } from './os/call/hooks/useCallModal'; import WindowSnackbar from './ui/components/WindowSnackbar'; @@ -90,7 +90,7 @@ function Phone() { ))} - + diff --git a/phone/src/ui/components/Alert.tsx b/phone/src/ui/components/Alert.tsx index 0daee4a..ef68f94 100644 --- a/phone/src/ui/components/Alert.tsx +++ b/phone/src/ui/components/Alert.tsx @@ -9,14 +9,14 @@ const useStyles = makeStyles({ msg: { maxWidth: '300px', wordWrap: 'break-word', - fontSize: '1em', + fontSize: '1.1em', }, }); export function Alert({ children, ...props }) { const classes = useStyles(); return ( - + {children} ); diff --git a/phone/src/ui/components/Snackbar.tsx b/phone/src/ui/components/PhoneSnackbar.tsx similarity index 52% rename from phone/src/ui/components/Snackbar.tsx rename to phone/src/ui/components/PhoneSnackbar.tsx index 3da6e6f..e0761cc 100644 --- a/phone/src/ui/components/Snackbar.tsx +++ b/phone/src/ui/components/PhoneSnackbar.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { makeStyles } from '@material-ui/core'; +import { makeStyles, Snackbar } from '@material-ui/core'; import { useSnackbar } from '../hooks/useSnackbar'; import Alert from './Alert'; @@ -14,18 +14,19 @@ const useStyles = makeStyles({ margin: '0 auto', position: 'absolute', left: 0, - bottom: '100px', + bottom: 75, right: 0, + transform: 'none', }, }); -export const Snackbar = () => { +export const PhoneSnackbar = () => { const classes = useStyles(); - const { alert } = useSnackbar(); + const { alert, isOpen, handleClose } = useSnackbar(); return ( -
- {alert ? {alert.message} : null} -
+ + {alert?.message || ''} + ); }; diff --git a/phone/src/ui/hooks/useSnackbar.ts b/phone/src/ui/hooks/useSnackbar.ts index 2e5f33b..b693a5a 100644 --- a/phone/src/ui/hooks/useSnackbar.ts +++ b/phone/src/ui/hooks/useSnackbar.ts @@ -11,6 +11,8 @@ export type AlertType = 'success' | 'error' | 'info'; interface ISnackBar { addAlert: ({ message, type }: IAlert) => void; alert: IAlert | null; + isOpen: boolean; + handleClose: () => void; } export const useSnackbar = (): ISnackBar => useContext(SnackbarContext); diff --git a/phone/src/ui/providers/SnackbarProvider.tsx b/phone/src/ui/providers/SnackbarProvider.tsx index 4a721c5..4421dbd 100644 --- a/phone/src/ui/providers/SnackbarProvider.tsx +++ b/phone/src/ui/providers/SnackbarProvider.tsx @@ -1,23 +1,23 @@ -import React, { createContext, useState, useEffect, useRef } from 'react'; +import React, { createContext, useState } from 'react'; +import { IAlert } from '../hooks/useSnackbar'; export const SnackbarContext = createContext(null); function SnackbarProvider({ children }) { - const [alert, setAlert] = useState(null); - const timer = useRef(null); + const [open, setOpen] = useState(false); + const [alert, setAlert] = useState(null); - useEffect(() => { - if (alert) { - clearTimeout(timer.current); - timer.current = setTimeout(() => { - setAlert(null); - }, 2000); - } - return () => clearTimeout(timer.current); - }, [alert]); + const setNewAlert = (alert: IAlert) => { + setAlert(alert); + setOpen(true); + }; + + const handleClose = () => { + setOpen(false); + }; return ( - + {children} );