Merge pull request #169 from project-error/tweak/dialer

tweak(dialer): Several fixes and improvements
This commit is contained in:
Christopher Gjelten authored and GitHub committed 2021-03-19 12:08:16 +01:00
commit 769f5a3d21
10 files changed
+70 -33

No files matched your search

@@ -28,7 +28,7 @@ export const DialerApp = () => {
<Route exact path="/phone"> <Route exact path="/phone">
<DialerHistory calls={history} /> <DialerHistory calls={history} />
</Route> </Route>
<Route path="/phone/contacts" component={ContactList}></Route> <Route path="/phone/contacts" component={ContactList} />
</Switch> </Switch>
</AppContent> </AppContent>
<DialerNavBar /> <DialerNavBar />
@@ -39,18 +39,18 @@ export const DialerApp = () => {
InjectDebugData([ InjectDebugData([
{ {
app: 'DAILER', app: 'DIALER',
method: 'setHistory', method: 'setHistory',
data: [ data: [
{ {
id: 1, id: 1,
transmitter: '636-6496', transmitter: '636-6496',
start: 1612301545782, start: 1615946292,
}, },
{ {
id: 2, id: 2,
transmitter: '777-7777', transmitter: '777-7777',
start: 1612301545782, start: 1615946292,
}, },
], ],
}, },
@@ -3,7 +3,7 @@ import { Box, IconButton, InputBase, Paper } from '@material-ui/core';
import { makeStyles, Theme } from '@material-ui/core/styles'; import { makeStyles, Theme } from '@material-ui/core/styles';
import PhoneIcon from '@material-ui/icons/Phone'; import PhoneIcon from '@material-ui/icons/Phone';
import PersonAddIcon from '@material-ui/icons/PersonAdd'; import PersonAddIcon from '@material-ui/icons/PersonAdd';
import { DialInputCtx } from '../context/InputContext'; import { DialInputCtx, IDialInputCtx } from '../context/InputContext';
import Nui from '../../../os/nui-events/utils/Nui'; import Nui from '../../../os/nui-events/utils/Nui';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
@@ -30,7 +30,7 @@ export const DialerInput = () => {
const classes = useStyles(); const classes = useStyles();
const history = useHistory(); const history = useHistory();
const { inputVal } = useContext(DialInputCtx); const { inputVal, set } = useContext<IDialInputCtx>(DialInputCtx);
const handleCall = (number: string) => { const handleCall = (number: string) => {
Nui.send('phone:beginCall', { Nui.send('phone:beginCall', {
@@ -44,8 +44,13 @@ export const DialerInput = () => {
return ( return (
<Box component={Paper} className={classes.root}> <Box component={Paper} className={classes.root}>
<InputBase placeholder="Enter a number" className={classes.input} value={inputVal} /> <InputBase
<IconButton color="primary" className={classes.iconBtn}> placeholder="Enter a number"
className={classes.input}
value={inputVal}
onChange={(e) => set(e.target.value)}
/>
<IconButton color="primary" className={classes.iconBtn} disabled={inputVal <= ''}>
<PhoneIcon fontSize="large" onClick={() => handleCall(inputVal)} /> <PhoneIcon fontSize="large" onClick={() => handleCall(inputVal)} />
</IconButton> </IconButton>
<IconButton className={classes.iconBtn}> <IconButton className={classes.iconBtn}>
@@ -28,6 +28,7 @@ const DialPage = () => {
add: (val: string) => setInputVal(inputVal + val), add: (val: string) => setInputVal(inputVal + val),
removeOne: () => setInputVal(inputVal.slice(0, -1)), removeOne: () => setInputVal(inputVal.slice(0, -1)),
clear: () => setInputVal(''), clear: () => setInputVal(''),
set: (val: string) => setInputVal(val),
}} }}
> >
<DialerInput /> <DialerInput />
@@ -9,11 +9,11 @@ import Nui from '../../../../os/nui-events/utils/Nui';
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard'; import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
import { useContacts } from '../../../contacts/hooks/useContacts'; import { useContacts } from '../../../contacts/hooks/useContacts';
import { ICall } from '../../../../../../typings/call'; import { ICall } from '../../../../../../typings/call';
import dayjs from 'dayjs';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Box, IconButton, ListItemIcon, ListItemText } from '@material-ui/core'; import { Box, IconButton, ListItemIcon, ListItemText } from '@material-ui/core';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { makeStyles, Theme } from '@material-ui/core/styles'; import { makeStyles, Theme } from '@material-ui/core/styles';
import dayjs from 'dayjs';
const useStyles = makeStyles((theme: Theme) => ({ const useStyles = makeStyles((theme: Theme) => ({
callForward: { callForward: {
@@ -25,7 +25,7 @@ const useStyles = makeStyles((theme: Theme) => ({
})); }));
export const DialerHistory = ({ calls }) => { export const DialerHistory = ({ calls }) => {
const { number } = useSimcard(); const { number: myNumber } = useSimcard();
const { getDisplayByNumber } = useContacts(); const { getDisplayByNumber } = useContacts();
const classes = useStyles(); const classes = useStyles();
@@ -44,9 +44,9 @@ export const DialerHistory = ({ calls }) => {
return ( return (
<Box display="flex" justifyContent="center" alignItems="center" paddingTop={35}> <Box display="flex" justifyContent="center" alignItems="center" paddingTop={35}>
<p> <p>
You got no friends! {t('APPS_DIALER_NO_HISTORY')}
<span role="img" aria-label="deal with it"> <span role="img" aria-label="sad">
😎 😞
</span> </span>
</p> </p>
</Box> </Box>
@@ -56,45 +56,57 @@ export const DialerHistory = ({ calls }) => {
return ( return (
<List disablePadding> <List disablePadding>
{calls.map((call: ICall) => {calls.map((call: ICall) =>
call.transmitter === number ? ( call.transmitter === myNumber ? (
<ListItem key={call.id} divider> <ListItem key={call.id} divider>
<ListItemIcon>{<PhoneForwardedIcon className={classes.callForward} />}</ListItemIcon> <ListItemIcon>
<PhoneForwardedIcon className={classes.callForward} />
</ListItemIcon>
<ListItemText <ListItemText
primary={getDisplayByNumber(call.receiver)} primary={getDisplayByNumber(call.receiver)}
secondary={dayjs.unix(call.start).format(t('DATE_TIME_FORMAT'))} secondary={
// TODO: Locale changes are pending #168 merge
dayjs().to(dayjs.unix(call.start))
}
/> />
<IconButton onClick={() => handleCall(call.receiver)}>{<PhoneIcon />}</IconButton> <IconButton onClick={() => handleCall(call.receiver)}>{<PhoneIcon />}</IconButton>
{getDisplayByNumber(call.transmitter) === call.transmitter ? ( {getDisplayByNumber(call.transmitter) === call.transmitter && (
<IconButton <IconButton
onClick={() => onClick={() =>
history.push(`/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts`) history.push(`/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts`)
} }
> >
{<PersonAddIcon />} <PersonAddIcon />
</IconButton> </IconButton>
) : null} )}
</ListItem> </ListItem>
) : ( ) : (
<ListItem key={call.id} divider> <ListItem key={call.id} divider>
<ListItemIcon>{<PhoneCallbackIcon className={classes.callBack} />}</ListItemIcon> <ListItemIcon>
<PhoneCallbackIcon className={classes.callBack} />
</ListItemIcon>
<ListItemText <ListItemText
primary={getDisplayByNumber(call.transmitter)} primary={getDisplayByNumber(call.transmitter)}
secondary={dayjs.unix(call.start).format(t('DATE_TIME_FORMAT'))} secondary={
// TODO: Locale changes are pending #168 merge
dayjs().to(dayjs.unix(call.start))
}
/> />
<IconButton onClick={() => handleCall(call.transmitter)}>{<PhoneIcon />}</IconButton> <IconButton onClick={() => handleCall(call.transmitter)}>
<PhoneIcon />
</IconButton>
{getDisplayByNumber(call.transmitter) === call.transmitter ? ( {getDisplayByNumber(call.transmitter) === call.transmitter && (
<IconButton <IconButton
onClick={() => onClick={() =>
history.push(`/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts`) history.push(`/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts`)
} }
> >
{<PersonAddIcon />} <PersonAddIcon />
</IconButton> </IconButton>
) : null} )}
</ListItem> </ListItem>
), ),
)} )}
@@ -5,6 +5,7 @@ export interface IDialInputCtx {
add: (char: string | number) => void; add: (char: string | number) => void;
removeOne: () => void; removeOne: () => void;
clear: () => void; clear: () => void;
set: (val) => void;
} }
export const DialInputCtx = createContext(null); export const DialInputCtx = createContext(null);
@@ -1,11 +1,7 @@
import { useRecoilValue } from 'recoil'; import { useRecoilValue } from 'recoil';
import { ICall } from '../../../../../typings/call'; import { ICall } from '../../../../../typings/call';
import { dialState } from './state'; import { dialState } from './state';
interface ICallUI {
history: ICall[];
}
export const useDialHistory = (): ICallUI[] => { export const useDialHistory = () => {
const history = useRecoilValue(dialState.history); return useRecoilValue<ICall[]>(dialState.history);
return history;
}; };
@@ -4,5 +4,5 @@ import { dialState } from './state';
export const useDialService = () => { export const useDialService = () => {
const setHistory = useSetRecoilState(dialState.history); const setHistory = useSetRecoilState(dialState.history);
useNuiEvent('DAILER', 'setHistory', setHistory); useNuiEvent('DIALER', 'setHistory', setHistory);
}; };
+6
View File
@@ -9,6 +9,12 @@ import './main.css';
import PhoneConfig from './config/default.json'; import PhoneConfig from './config/default.json';
import { PhoneContainer } from './PhoneContainer'; import { PhoneContainer } from './PhoneContainer';
import attachMockNuiEvent from './os/debug/AttachMockNuiEvent'; import attachMockNuiEvent from './os/debug/AttachMockNuiEvent';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import updateLocale from 'dayjs/plugin/updateLocale';
dayjs.extend(relativeTime);
dayjs.extend(updateLocale);
// Enable Sentry when config setting is true and when in prod // Enable Sentry when config setting is true and when in prod
if (PhoneConfig.SentryErrorMetrics && process.env.NODE_ENV !== 'development') { if (PhoneConfig.SentryErrorMetrics && process.env.NODE_ENV !== 'development') {
+16
View File
@@ -11,6 +11,21 @@
"LANGUAGE": "Language" "LANGUAGE": "Language"
} }
}, },
"RELATIVE_TIME": {
"future": "in %s",
"past": "%s ago",
"s": "a few seconds",
"m": "a minute",
"mm": "%d minutes",
"h": "an hour",
"hh": "%d hours",
"d": "a day",
"dd": "%d days",
"M": "a month",
"MM": "%d months",
"y": "a year",
"yy": "%d years"
},
"COMING_SOON": "Coming soon...", "COMING_SOON": "Coming soon...",
"INITIALIZING": "Initializing", "INITIALIZING": "Initializing",
@@ -34,6 +49,7 @@
"APPS_DIALER_ACCEPT_CALL": "Accept", "APPS_DIALER_ACCEPT_CALL": "Accept",
"APPS_DIALER_REJECT_CALL": "Reject", "APPS_DIALER_REJECT_CALL": "Reject",
"APPS_DIALER_END_CALL": "End", "APPS_DIALER_END_CALL": "End",
"APPS_DIALER_NO_HISTORY": "You have no call history",
"APPS_TWITTER_TWEET": "Tweet", "APPS_TWITTER_TWEET": "Tweet",
"APPS_TWITTER_TWEET_MESSAGE_PLACEHOLDER": "What's happening?", "APPS_TWITTER_TWEET_MESSAGE_PLACEHOLDER": "What's happening?",
+1 -1
View File
@@ -121,7 +121,7 @@ function openCallModal(show: boolean) {
onNet(events.PHONE_CALL_SEND_HISTORY, (calls: ICall) => { onNet(events.PHONE_CALL_SEND_HISTORY, (calls: ICall) => {
SendNuiMessage( SendNuiMessage(
JSON.stringify({ JSON.stringify({
app: 'DAILER', app: 'DIALER',
method: 'setHistory', method: 'setHistory',
data: calls, data: calls,
}), }),