mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +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 { useDialService } from './apps/dialer/hooks/useDialService';
|
||||||
import InjectDebugData from './os/debug/InjectDebugData';
|
import InjectDebugData from './os/debug/InjectDebugData';
|
||||||
import { usePhoneVisibility } from './os/phone/hooks/usePhoneVisibility';
|
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 { NotificationAlert } from './os/notifications/components/NotificationAlert';
|
||||||
import { useCallModal } from './os/call/hooks/useCallModal';
|
import { useCallModal } from './os/call/hooks/useCallModal';
|
||||||
import WindowSnackbar from './ui/components/WindowSnackbar';
|
import WindowSnackbar from './ui/components/WindowSnackbar';
|
||||||
@@ -90,7 +90,7 @@ function Phone() {
|
|||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
<NotificationAlert />
|
<NotificationAlert />
|
||||||
<Snackbar />
|
<PhoneSnackbar />
|
||||||
</div>
|
</div>
|
||||||
<Navigation />
|
<Navigation />
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ const useStyles = makeStyles({
|
|||||||
msg: {
|
msg: {
|
||||||
maxWidth: '300px',
|
maxWidth: '300px',
|
||||||
wordWrap: 'break-word',
|
wordWrap: 'break-word',
|
||||||
fontSize: '1em',
|
fontSize: '1.1em',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export function Alert({ children, ...props }) {
|
export function Alert({ children, ...props }) {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
return (
|
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>
|
<Typography className={classes.msg}>{children}</Typography>
|
||||||
</MuiAlert>
|
</MuiAlert>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { makeStyles } from '@material-ui/core';
|
import { makeStyles, Snackbar } from '@material-ui/core';
|
||||||
import { useSnackbar } from '../hooks/useSnackbar';
|
import { useSnackbar } from '../hooks/useSnackbar';
|
||||||
import Alert from './Alert';
|
import Alert from './Alert';
|
||||||
|
|
||||||
@@ -14,18 +14,19 @@ const useStyles = makeStyles({
|
|||||||
margin: '0 auto',
|
margin: '0 auto',
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
left: 0,
|
left: 0,
|
||||||
bottom: '100px',
|
bottom: 75,
|
||||||
right: 0,
|
right: 0,
|
||||||
|
transform: 'none',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const Snackbar = () => {
|
export const PhoneSnackbar = () => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { alert } = useSnackbar();
|
const { alert, isOpen, handleClose } = useSnackbar();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.root}>
|
<Snackbar autoHideDuration={4000} open={isOpen} className={classes.root} onClose={handleClose}>
|
||||||
{alert ? <Alert severity={alert.type}>{alert.message}</Alert> : null}
|
<Alert severity={alert?.type || 'info'}>{alert?.message || ''}</Alert>
|
||||||
</div>
|
</Snackbar>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -11,6 +11,8 @@ export type AlertType = 'success' | 'error' | 'info';
|
|||||||
interface ISnackBar {
|
interface ISnackBar {
|
||||||
addAlert: ({ message, type }: IAlert) => void;
|
addAlert: ({ message, type }: IAlert) => void;
|
||||||
alert: IAlert | null;
|
alert: IAlert | null;
|
||||||
|
isOpen: boolean;
|
||||||
|
handleClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useSnackbar = (): ISnackBar => useContext(SnackbarContext);
|
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);
|
export const SnackbarContext = createContext(null);
|
||||||
|
|
||||||
function SnackbarProvider({ children }) {
|
function SnackbarProvider({ children }) {
|
||||||
const [alert, setAlert] = useState(null);
|
const [open, setOpen] = useState<boolean>(false);
|
||||||
const timer = useRef(null);
|
const [alert, setAlert] = useState<IAlert>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
const setNewAlert = (alert: IAlert) => {
|
||||||
if (alert) {
|
setAlert(alert);
|
||||||
clearTimeout(timer.current);
|
setOpen(true);
|
||||||
timer.current = setTimeout(() => {
|
};
|
||||||
setAlert(null);
|
|
||||||
}, 2000);
|
const handleClose = () => {
|
||||||
}
|
setOpen(false);
|
||||||
return () => clearTimeout(timer.current);
|
};
|
||||||
}, [alert]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SnackbarContext.Provider value={{ alert, addAlert: setAlert }}>
|
<SnackbarContext.Provider value={{ alert, addAlert: setNewAlert, handleClose, isOpen: open }}>
|
||||||
{children}
|
{children}
|
||||||
</SnackbarContext.Provider>
|
</SnackbarContext.Provider>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user