Skip to content

Commit

Permalink
added lookup and lookup history
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiez committed Mar 3, 2020
1 parent 91ce319 commit 33dcf42
Show file tree
Hide file tree
Showing 38 changed files with 711 additions and 341 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"css-loader": "^3.4.2",
"electron": "^8.0.2",
"electron": "^8.0.3",
"electron-devtools-installer": "^2.2.4",
"file-loader": "^5.1.0",
"fork-ts-checker-webpack-plugin": "^4.0.5",
Expand All @@ -54,7 +54,7 @@
"ts-loader": "^6.2.1",
"typeface-roboto": "^0.0.75",
"typescript": "^3.8.3",
"webpack": "^4.41.6"
"webpack": "^4.42.0"
},
"dependencies": {
"@babel/runtime": "^7.8.4",
Expand All @@ -72,7 +72,7 @@
"react-i18next": "^11.3.3",
"react-redux": "^7.2.0",
"redux": "^4.0.5",
"sms77-client": "^1.4.2",
"sms77-client": "^1.8.4",
"smshelper": "^0.1.0"
},
"optionalDependencies": {
Expand Down
14 changes: 14 additions & 0 deletions src/components/BoolChip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Chip from '@material-ui/core/Chip';
import React from 'react';
import {useTranslation} from 'react-i18next';

export type BoolChipProps = {
value: boolean
}

export const BoolChip = ({value}: BoolChipProps) => {
const {t} = useTranslation();

return <Chip style={{backgroundColor: value ? 'green' : 'red', color: '#fff'}}
label={t(Boolean(value) ? 'true' : 'false')}/>;
};
160 changes: 0 additions & 160 deletions src/components/History.tsx

This file was deleted.

36 changes: 36 additions & 0 deletions src/components/History/BaseHistory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, {useState} from 'react';
import TableContainer from '@material-ui/core/TableContainer';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import {useTranslation} from 'react-i18next';

import {ILocalStore, LocalStore} from '../../util/LocalStore';
import {Navigation} from './Navigation';

export type BaseHistoryProps = {
nsKey: string
path?: string
rowHandler: (row: any, i: number) => any
storeKey: keyof ILocalStore
}

export const BaseHistory = ({path, nsKey, storeKey, rowHandler}: BaseHistoryProps) => {
const {t} = useTranslation(nsKey);
const list = LocalStore.get(storeKey) as any[];
const [index, setIndex] = useState(list.length - 1);
const entry = list[index];

return <>
<h1>{t(storeKey)}</h1>

{entry && <Navigation index={index} list={list} onNavigation={setIndex}/>}

<TableContainer>
<Table>
<TableBody>
{entry && (path ? eval(`entry${path}`) : [entry].flat()).map(rowHandler)}
</TableBody>
</Table>
</TableContainer>
</>;
};
118 changes: 118 additions & 0 deletions src/components/History/History.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import React from 'react';
import {useTranslation} from 'react-i18next';
import {SmsMessage} from 'sms77-client';
import TableRow from '@material-ui/core/TableRow';
import TableCell from '@material-ui/core/TableCell';
import Tooltip from '@material-ui/core/Tooltip';

import {numberFormatter} from '../../util/numberFormatter';
import {BoolChip} from '../BoolChip';
import {BaseHistory} from './BaseHistory';

export const History = () => {
const {t} = useTranslation('history');

return <BaseHistory
nsKey={'history'}
path='.res.messages'
rowHandler={(row: SmsMessage, i: number) =>
<React.Fragment key={i}>
<TableRow>
<TableCell component='th' scope='row'>
{t('to')}
</TableCell>

<TableCell align='right'>
{row.recipient}
</TableCell>
</TableRow>

<TableRow>
<TableCell component='th' scope='row'>
{t('text')}
</TableCell>

<TableCell align='right'>
{row.text}
</TableCell>
</TableRow>

<TableRow>
<TableCell component='th' scope='row'>
{t('success')}
</TableCell>

<TableCell align='right'>
<BoolChip value={row.success}/>
</TableCell>
</TableRow>

<TableRow>
<TableCell component='th' scope='row'>
{t('from')}
</TableCell>

<TableCell align='right'>
{row.sender}
</TableCell>
</TableRow>

<TableRow>
<TableCell component='th' scope='row'>
{t('encoding')}
</TableCell>

<TableCell align='right'>
{row.encoding}
</TableCell>
</TableRow>

<TableRow>
<TableCell component='th' scope='row'>
{t('parts')}
</TableCell>

<TableCell align='right'>
{row.parts}
</TableCell>
</TableRow>

<TableRow>
<TableCell component='th' scope='row'>
{t('price')}
</TableCell>

<TableCell align='right'>
{numberFormatter.format(row.price)}
</TableCell>
</TableRow>

<TableRow>
<TableCell component='th' scope='row'>
<Tooltip title={t('tooltips.message')}>
<span>{t('messages')}</span>
</Tooltip>
</TableCell>

<TableCell align='right'>
{
Array.isArray(row.messages)
? row.messages.join(' ')
: JSON.stringify(row.messages)
}
</TableCell>
</TableRow>

<TableRow>
<TableCell component='th' scope='row'>
{t('id')}
</TableCell>

<TableCell align='right'>
{row.id}
</TableCell>
</TableRow>
</React.Fragment>}
storeKey={'history'}
/>;
};
30 changes: 30 additions & 0 deletions src/components/History/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';

import {PreviousListItemButton} from './PreviousListItemButton';
import {NextListItemButton} from './NextListItemButton';

export type NavigationProps = {
index: number
list: any[]
onNavigation: (i: number) => void
}

export const Navigation = ({index, list, onNavigation}: NavigationProps) => {
const handleNavigation = (operator: '+' | '-'): void => {
let newIndex: number = eval(`${index} ${operator} 1`);

if (!list[newIndex]) {
newIndex = eval(`${newIndex} ${'+' === operator ? '-' : '+'} 1`);
}

onNavigation(newIndex);
};

return <>
<PreviousListItemButton index={index} list={list}
IconButtonProps={{onClick: () => handleNavigation('-')}}/>

<NextListItemButton index={index} list={list}
IconButtonProps={{onClick: () => handleNavigation('+')}}/>
</>;
};
Loading

0 comments on commit 33dcf42

Please sign in to comment.