mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
Feature/floating notifications calling and twitter (#112)
* Add floating notifications :O * Add phone notifications and refactor calling ui * This is unsafe * Fix controls null check * Remove go to alert * Fix phone stuck after call * Remove lazy mount for Phone * Fix open/close cl_main * Use effect for notification visibility * Remove all alerts when phone closes * Avoid re-render useNuiEvent * It works now :c
This commit is contained in:
1 parent
4633146d40
commit
f6d7a3dbe1
42 files changed
+869
-679
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import React from 'react';
|
||||
import { Box, makeStyles } from '@material-ui/core';
|
||||
import { useNotifications } from '../hooks/useNotifications';
|
||||
import { Alert, AlertTitle } from '@material-ui/lab';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
snackbar: {
|
||||
marginTop: '-710px',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
},
|
||||
alert: {
|
||||
position: 'relative',
|
||||
cursor: 'pointer',
|
||||
width: '370px',
|
||||
height: '120px',
|
||||
zIndex: 50,
|
||||
backgroundColor: theme.palette.background.paper,
|
||||
color: theme.palette.text.primary,
|
||||
'& .MuiAlert-icon': {
|
||||
color: theme.palette.text.primary,
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
export const NotificationAlert = () => {
|
||||
const classes = useStyles();
|
||||
const { currentAlert } = useNotifications();
|
||||
|
||||
return (
|
||||
<div className={classes.snackbar}>
|
||||
{currentAlert ? (
|
||||
<Alert
|
||||
onClick={() => currentAlert.onClick?.(currentAlert)}
|
||||
icon={currentAlert.icon || false}
|
||||
className={classes.alert}
|
||||
elevation={6}
|
||||
>
|
||||
<AlertTitle>{currentAlert.title}</AlertTitle>
|
||||
<Box width='100%'>{currentAlert.content}</Box>
|
||||
</Alert>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -8,18 +8,14 @@ import {
|
||||
Paper,
|
||||
Box,
|
||||
List,
|
||||
ListItem,
|
||||
ListItemText,
|
||||
Divider,
|
||||
ListItemAvatar,
|
||||
} from '@material-ui/core';
|
||||
import SignalIcon from '@material-ui/icons/SignalCellular3Bar';
|
||||
import CloseIcon from '@material-ui/icons/Close';
|
||||
import Battery90Icon from '@material-ui/icons/Battery90';
|
||||
import ArrowDropUpIcon from '@material-ui/icons/ArrowDropUp';
|
||||
import Default from '../../../config/default.json';
|
||||
import { useNotifications } from '../hooks/useNotifications';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { NotificationItem } from './NotificationItem';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -67,9 +63,8 @@ const useStyles = makeStyles((theme) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
export const NotificationBar = ({ forceUncollapse }: { forceUncollapse: boolean }) => {
|
||||
export const NotificationBar = () => {
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
|
||||
const { icons, notifications, removeNotification } = useNotifications();
|
||||
|
||||
@@ -120,41 +115,29 @@ export const NotificationBar = ({ forceUncollapse }: { forceUncollapse: boolean
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Slide direction='down' in={forceUncollapse || uncollapsed}>
|
||||
<Slide direction='down' in={uncollapsed}>
|
||||
<Paper square className={classes.drawer}>
|
||||
<Box p={2}>
|
||||
<List>
|
||||
<Divider />
|
||||
{notifications.map(({ href, title, content, icon }, idx) => (
|
||||
<ListItem
|
||||
divider
|
||||
button
|
||||
onClick={() => {
|
||||
if (href) {
|
||||
history.push(href);
|
||||
{notifications.map((notification, idx) => (
|
||||
<NotificationItem
|
||||
key={idx}
|
||||
onClose={(e) => {
|
||||
e.stopPropagation();
|
||||
if (notifications.length === 1) {
|
||||
setUncollapsed(false);
|
||||
}
|
||||
removeNotification(idx);
|
||||
}}
|
||||
onClickClose={() => {
|
||||
setUncollapsed(false);
|
||||
if (!notification.cantClose) {
|
||||
removeNotification(idx);
|
||||
}
|
||||
}}
|
||||
className={classes.notificationItem}
|
||||
key={idx}
|
||||
>
|
||||
{icon && <ListItemAvatar>{icon}</ListItemAvatar>}
|
||||
<ListItemText secondary={content}>{title}</ListItemText>
|
||||
<IconButton
|
||||
className={classes.closeNotifBtn}
|
||||
size='small'
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (notifications.length === 1) {
|
||||
setUncollapsed(false);
|
||||
}
|
||||
removeNotification(idx);
|
||||
}}
|
||||
>
|
||||
<CloseIcon color='primary' />
|
||||
</IconButton>
|
||||
</ListItem>
|
||||
{...notification}
|
||||
/>
|
||||
))}
|
||||
</List>
|
||||
</Box>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import React from 'react';
|
||||
import CloseIcon from '@material-ui/icons/Close';
|
||||
import {
|
||||
IconButton,
|
||||
ListItem,
|
||||
ListItemAvatar,
|
||||
ListItemText,
|
||||
makeStyles,
|
||||
} from '@material-ui/core';
|
||||
import { INotification } from '../providers/NotificationsProvider';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
closeNotifBtn: {
|
||||
position: 'absolute',
|
||||
right: '8px',
|
||||
top: '8px',
|
||||
},
|
||||
notificationItem: {
|
||||
position: 'relative',
|
||||
},
|
||||
}));
|
||||
|
||||
export const NotificationItem = ({
|
||||
onClose,
|
||||
onClickClose,
|
||||
...notification
|
||||
}: INotification & {
|
||||
onClose: (e: any) => void;
|
||||
onClickClose: (e: any) => void;
|
||||
}) => {
|
||||
const { title, icon, content, cantClose, onClick } = notification;
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<ListItem
|
||||
divider
|
||||
button
|
||||
onClick={(e) => {
|
||||
if (onClick) {
|
||||
onClick(notification);
|
||||
onClickClose(e);
|
||||
}
|
||||
}}
|
||||
className={classes.notificationItem}
|
||||
>
|
||||
{icon && <ListItemAvatar>{icon}</ListItemAvatar>}
|
||||
<ListItemText secondary={content}>{title}</ListItemText>
|
||||
{!cantClose && (
|
||||
<IconButton
|
||||
className={classes.closeNotifBtn}
|
||||
size='small'
|
||||
onClick={onClose}
|
||||
>
|
||||
<CloseIcon color='primary' />
|
||||
</IconButton>
|
||||
)}
|
||||
</ListItem>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user