mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
ArticleListに自動scroll機能追加
This commit is contained in:
@@ -18,12 +18,12 @@ class HomePage extends React.Component {
|
|||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
// React自体のKey入力はfocusされていないElementからは動かないため、
|
// React自体のKey入力はfocusされていないElementからは動かないため、
|
||||||
// `window`に直接かける
|
// `window`に直接かける
|
||||||
this.listener = (e) => this.handleKeyDown(e)
|
this.keyHandler = e => this.handleKeyDown(e)
|
||||||
window.addEventListener('keydown', this.listener)
|
window.addEventListener('keydown', this.keyHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
window.removeEventListener('keydown', this.listener)
|
window.removeEventListener('keydown', this.keyHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleKeyDown (e) {
|
handleKeyDown (e) {
|
||||||
|
|||||||
@@ -33,6 +33,14 @@ export default class ArticleDetail extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount () {
|
||||||
|
this.refreshTimer = setInterval(() => this.forceUpdate(), 60 * 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount () {
|
||||||
|
clearInterval(this.refreshTimer)
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate (prevProps) {
|
componentDidUpdate (prevProps) {
|
||||||
let isModeChanged = prevProps.status.mode !== this.props.status.mode
|
let isModeChanged = prevProps.status.mode !== this.props.status.mode
|
||||||
if (isModeChanged && this.props.status.mode !== IDLE_MODE) {
|
if (isModeChanged && this.props.status.mode !== IDLE_MODE) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { PropTypes } from 'react'
|
import React, { PropTypes } from 'react'
|
||||||
|
import ReactDOM from 'react-dom'
|
||||||
import ModeIcon from 'boost/components/ModeIcon'
|
import ModeIcon from 'boost/components/ModeIcon'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import { switchArticle, NEW } from 'boost/actions'
|
import { switchArticle, NEW } from 'boost/actions'
|
||||||
@@ -15,6 +16,26 @@ export default class ArticleList extends React.Component {
|
|||||||
clearInterval(this.refreshTimer)
|
clearInterval(this.refreshTimer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate () {
|
||||||
|
let { articles, activeArticle } = this.props
|
||||||
|
var index = articles.indexOf(activeArticle)
|
||||||
|
var el = ReactDOM.findDOMNode(this)
|
||||||
|
var li = el.querySelectorAll('.ArticleList>div')[index]
|
||||||
|
|
||||||
|
if (li == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var overflowBelow = el.clientHeight + el.scrollTop < li.offsetTop + li.clientHeight
|
||||||
|
if (overflowBelow) {
|
||||||
|
el.scrollTop = li.offsetTop + li.clientHeight - el.clientHeight
|
||||||
|
}
|
||||||
|
var overflowAbove = el.scrollTop > li.offsetTop
|
||||||
|
if (overflowAbove) {
|
||||||
|
el.scrollTop = li.offsetTop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 移動ができなかったらfalseを返す:
|
// 移動ができなかったらfalseを返す:
|
||||||
selectPriorArticle () {
|
selectPriorArticle () {
|
||||||
let { articles, activeArticle, dispatch } = this.props
|
let { articles, activeArticle, dispatch } = this.props
|
||||||
|
|||||||
Reference in New Issue
Block a user