-
Notifications
You must be signed in to change notification settings - Fork 491
Expand file tree
/
Copy pathBoard.js
More file actions
69 lines (63 loc) · 2.43 KB
/
Copy pathBoard.js
File metadata and controls
69 lines (63 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React, {Component} from 'react'
import {Provider} from 'react-redux'
import classNames from 'classnames'
import {applyMiddleware, createStore} from 'redux'
import logger from 'redux-logger'
import uuidv1 from 'uuid/v1'
import BoardContainer from './BoardContainer'
import createTranslate from 'rt/helpers/createTranslate'
import boardReducer from 'rt/reducers/BoardReducer'
const middlewares = process.env.REDUX_LOGGING ? [logger] : []
export default class Board extends Component {
state = {isDown: false, startPos: 0, currentPos: 0, isBoardMoving: false, isBoardClicked: false}
constructor({id}) {
super()
this.store = this.getStore()
this.id = id || uuidv1()
}
getStore = () => {
//When you create multiple boards, unique stores are created for isolation
return createStore(boardReducer, applyMiddleware(...middlewares))
}
render() {
const {id, className, components} = this.props
const allClassNames = classNames('react-trello-board', className || '')
return (
<Provider store={this.store}>
<>
<components.GlobalStyle />
<BoardContainer
id={this.id}
{...this.props}
className={allClassNames}
isBoardMoving={this.state.isBoardMoving}
isBoardClicked={this.state.isBoardClicked}
interactions={{
onMouseDown: event => {
this.setState({isDown: true, startPos: event.pageX, isBoardMoving: false, isBoardClicked: true})
},
onMouseUp: event => {
const el = document.querySelector('.react-trello-board-wrapper')
this.setState({
isDown: false,
isBoardClicked: false,
currentPos: el.getBoundingClientRect().x + 8,
isBoardMoving: false
})
},
onMouseMove: event => {
if (this.state.isDown) {
this.setState({isBoardMoving: true})
const el = document.querySelector('.react-trello-board-wrapper')
// prettier-ignore
const moveX = event.pageX <= el.parentElement.getBoundingClientRect().width / 6 ? 0 : Math.abs(this.state.startPos - event.pageX + this.state.currentPos)
el.style.transform = `translateX(-${moveX}px)`
}
}
}}
/>
</>
</Provider>
)
}
}