mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 06:28:51 +00:00
fix(phone/snackbar): Fixed animations & simplified logic (#146)
This commit is contained in:
5 files changed
+27
-24
No files matched your search
+2
-2
@@ -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() {
|
||||
))}
|
||||
</>
|
||||
<NotificationAlert />
|
||||
<Snackbar />
|
||||
<PhoneSnackbar />
|
||||
</div>
|
||||
<Navigation />
|
||||
</>
|
||||
|
||||
@@ -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 (
|
||||
<MuiAlert className={classes.root} elevation={6} variant="filled" {...props}>
|
||||
<MuiAlert className={classes.root} elevation={4} variant="filled" {...props}>
|
||||
<Typography className={classes.msg}>{children}</Typography>
|
||||
</MuiAlert>
|
||||
);
|
||||
|
||||
@@ -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 (
|
||||
<div className={classes.root}>
|
||||
{alert ? <Alert severity={alert.type}>{alert.message}</Alert> : null}
|
||||
</div>
|
||||
<Snackbar autoHideDuration={4000} open={isOpen} className={classes.root} onClose={handleClose}>
|
||||
<Alert severity={alert?.type || 'info'}>{alert?.message || ''}</Alert>
|
||||
</Snackbar>
|
||||
);
|
||||
};
|
||||
@@ -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);
|
||||
@@ -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<boolean>(false);
|
||||
const [alert, setAlert] = useState<IAlert>(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 (
|
||||
<SnackbarContext.Provider value={{ alert, addAlert: setAlert }}>
|
||||
<SnackbarContext.Provider value={{ alert, addAlert: setNewAlert, handleClose, isOpen: open }}>
|
||||
{children}
|
||||
</SnackbarContext.Provider>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user