mirror of
https://github.com/jxnblk/mdx-deck.git
synced 2024-11-26 00:35:02 +03:00
Add localStorage handlers
This commit is contained in:
parent
2258c89879
commit
45a9ce5d90
5
notes.md
5
notes.md
@ -4,11 +4,12 @@ mdx-deck v2 prototype
|
|||||||
|
|
||||||
todo:
|
todo:
|
||||||
|
|
||||||
- [ ] Emotion
|
|
||||||
- [ ] composable themes
|
- [ ] composable themes
|
||||||
- [ ] hooks
|
- [ ] hooks
|
||||||
- [ ] URL params
|
- [ ] URL params
|
||||||
- [ ] localStorage
|
- [ ] test with v1 demo deck & multiple elements per slide
|
||||||
|
- [x] localStorage
|
||||||
|
- [x] Emotion
|
||||||
- [x] Head
|
- [x] Head
|
||||||
- [x] Image
|
- [x] Image
|
||||||
- [x] Notes
|
- [x] Notes
|
||||||
|
@ -12,6 +12,9 @@ const PRESENTER = 'PRESENTER'
|
|||||||
const OVERVIEW = 'OVERVIEW'
|
const OVERVIEW = 'OVERVIEW'
|
||||||
const PRINT = 'PRINT'
|
const PRINT = 'PRINT'
|
||||||
|
|
||||||
|
const STORAGE_INDEX = 'mdx-slide'
|
||||||
|
const STORAGE_STEP = 'mdx-step'
|
||||||
|
|
||||||
const keys = {
|
const keys = {
|
||||||
right: 39,
|
right: 39,
|
||||||
left: 37,
|
left: 37,
|
||||||
@ -128,12 +131,39 @@ export class MDXDeck extends React.Component {
|
|||||||
this.setState({ slides })
|
this.setState({ slides })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleStorageChange = e => {
|
||||||
|
const { key } = e
|
||||||
|
switch (key) {
|
||||||
|
case STORAGE_INDEX:
|
||||||
|
const index = parseInt(e.newValue, 10)
|
||||||
|
this.goto(index)
|
||||||
|
break
|
||||||
|
case STORAGE_STEP:
|
||||||
|
const step = parseInt(e.newValue, 10)
|
||||||
|
this.setState({ step })
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getMode = () => {
|
||||||
|
// todo parse query params
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
document.body.addEventListener('keydown', this.handleKeyDown)
|
document.body.addEventListener('keydown', this.handleKeyDown)
|
||||||
|
window.addEventListener('storage', this.handleStorageChange)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
document.body.removeEventListener('keydown', this.handleKeyDown)
|
document.body.removeEventListener('keydown', this.handleKeyDown)
|
||||||
|
window.removeEventListener('storage', this.handleStorageChange)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
const index = this.getIndex()
|
||||||
|
const { step } = this.state
|
||||||
|
localStorage.setItem(STORAGE_INDEX, index)
|
||||||
|
localStorage.setItem(STORAGE_STEP, step)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
Loading…
Reference in New Issue
Block a user