mirror of
https://github.com/woodchen-ink/clash-and-dashboard.git
synced 2025-07-19 14:31:57 +08:00
Improve: make <Logs> responsive
This commit is contained in:
parent
5820563c1d
commit
c7ce6a1bca
@ -14,19 +14,16 @@ interface Log {
|
|||||||
interface LogsProps extends I18nProps {}
|
interface LogsProps extends I18nProps {}
|
||||||
|
|
||||||
interface LogsState {
|
interface LogsState {
|
||||||
listHeight: number
|
|
||||||
logs: Log[]
|
logs: Log[]
|
||||||
}
|
}
|
||||||
|
|
||||||
class Logs extends React.Component<LogsProps, LogsState> {
|
class Logs extends React.Component<LogsProps, LogsState> {
|
||||||
state: LogsState = {
|
state: LogsState = {
|
||||||
listHeight: 0,
|
|
||||||
logs: []
|
logs: []
|
||||||
}
|
}
|
||||||
|
|
||||||
private listRef = React.createRef<HTMLUListElement>()
|
private listRef = React.createRef<HTMLUListElement>()
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
this.setListHeight()
|
|
||||||
const logs: Log[] = Array.from(
|
const logs: Log[] = Array.from(
|
||||||
{ length: 32 },
|
{ length: 32 },
|
||||||
() => ({ type: 'info', payload: 'google.com match DomainSuffix using Proxy', time: new Date() })
|
() => ({ type: 'info', payload: 'google.com match DomainSuffix using Proxy', time: new Date() })
|
||||||
@ -34,25 +31,18 @@ class Logs extends React.Component<LogsProps, LogsState> {
|
|||||||
this.setState({ logs }, () => this.scrollToBottom())
|
this.setState({ logs }, () => this.scrollToBottom())
|
||||||
}
|
}
|
||||||
|
|
||||||
setListHeight = () => {
|
|
||||||
this.setState({
|
|
||||||
listHeight: document.querySelector('.logs-card').clientHeight - 30
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
scrollToBottom = () => {
|
scrollToBottom = () => {
|
||||||
const ul = this.listRef.current
|
const ul = this.listRef.current
|
||||||
ul.scrollTop = ul.scrollHeight
|
ul.scrollTop = ul.scrollHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const listHeight = { height: this.state.listHeight }
|
|
||||||
const { t } = this.props
|
const { t } = this.props
|
||||||
return (
|
return (
|
||||||
<div className="page">
|
<div className="page">
|
||||||
<Header title={ t('title') } />
|
<Header title={ t('title') } />
|
||||||
<Card className="logs-card">
|
<Card className="logs-card">
|
||||||
<ul className="logs-panel" style={listHeight} ref={this.listRef}>
|
<ul className="logs-panel" ref={this.listRef}>
|
||||||
{
|
{
|
||||||
this.state.logs.map(
|
this.state.logs.map(
|
||||||
log => (
|
log => (
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
.logs-card {
|
.logs-card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
margin-top: 25px;
|
margin-top: 25px;
|
||||||
}
|
}
|
||||||
@ -6,7 +8,8 @@
|
|||||||
.logs-panel {
|
.logs-panel {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
height: 0;
|
flex-grow: 1;
|
||||||
|
flex-basis: 0;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user