-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
711 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')}/>; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
</>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'} | ||
/>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('+')}}/> | ||
</>; | ||
}; |
Oops, something went wrong.