diff --git a/src/containers/Logs/index.tsx b/src/containers/Logs/index.tsx index 9a04cda..cfac46e 100644 --- a/src/containers/Logs/index.tsx +++ b/src/containers/Logs/index.tsx @@ -1,19 +1,37 @@ import * as React from 'react' import * as dayjs from 'dayjs' +import { translate } from 'react-i18next' +import { I18nProps } from '@i18n' import { Card, Header } from '@components' import './style.scss' -interface LogsState { - listHeight: number +interface Log { + type: string + payload: string, + time: Date } -export default class Logs extends React.Component<{}, LogsState> { +interface LogsProps extends I18nProps {} + +interface LogsState { + listHeight: number + logs: Log[] +} + +class Logs extends React.Component { state: LogsState = { - listHeight: 0 + listHeight: 0, + logs: [] } + private listRef = React.createRef() componentDidMount () { this.setListHeight() + const logs: Log[] = Array.from( + { length: 32 }, + () => ({ type: 'info', payload: 'google.com match DomainSuffix using Proxy', time: new Date() }) + ) + this.setState({ logs }, () => this.scrollToBottom()) } setListHeight = () => { @@ -22,45 +40,21 @@ export default class Logs extends React.Component<{}, LogsState> { }) } - render () { - const logs = [ - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() }, - { type: 'info', payload: 'google.com match DomainSuffix using Proxy', timestamp: +new Date() } - ] + scrollToBottom = () => { + const ul = this.listRef.current + ul.scrollTop = ul.scrollHeight + } + render () { const listHeight = { height: this.state.listHeight } + const { t } = this.props return (
-
+
-
    +
      { - logs.map( + this.state.logs.map( log => (
    • { dayjs().format('YYYY-MM-DD HH:mm:ss') } @@ -75,3 +69,5 @@ export default class Logs extends React.Component<{}, LogsState> { ) } } + +export default translate(['Logs'])(Logs) diff --git a/src/i18n/en_US.ts b/src/i18n/en_US.ts index 4bbd3da..1aa0983 100644 --- a/src/i18n/en_US.ts +++ b/src/i18n/en_US.ts @@ -27,5 +27,8 @@ export default { }, versionString: 'Current ClashX is the latest version:{{version}}', checkUpdate: 'Check Update' + }, + Logs: { + title: 'Logs' } } diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 8a35a40..d9531ab 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -10,7 +10,8 @@ const options = { ns: [ 'SideBar', - 'Settings' + 'Settings', + 'Logs' ], resources: { diff --git a/src/i18n/zh_CN.ts b/src/i18n/zh_CN.ts index b534aea..07051b8 100644 --- a/src/i18n/zh_CN.ts +++ b/src/i18n/zh_CN.ts @@ -27,5 +27,8 @@ export default { }, versionString: '当前 ClashX 已是最新版本:{{version}}', checkUpdate: '检查更新' + }, + Logs: { + title: '日志' } }