1
1
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:
Brent Jackson 2019-03-03 11:38:40 -05:00
parent 2258c89879
commit 45a9ce5d90
2 changed files with 33 additions and 2 deletions

View File

@ -4,11 +4,12 @@ mdx-deck v2 prototype
todo:
- [ ] Emotion
- [ ] composable themes
- [ ] hooks
- [ ] URL params
- [ ] localStorage
- [ ] test with v1 demo deck & multiple elements per slide
- [x] localStorage
- [x] Emotion
- [x] Head
- [x] Image
- [x] Notes

View File

@ -12,6 +12,9 @@ const PRESENTER = 'PRESENTER'
const OVERVIEW = 'OVERVIEW'
const PRINT = 'PRINT'
const STORAGE_INDEX = 'mdx-slide'
const STORAGE_STEP = 'mdx-step'
const keys = {
right: 39,
left: 37,
@ -128,12 +131,39 @@ export class MDXDeck extends React.Component {
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() {
document.body.addEventListener('keydown', this.handleKeyDown)
window.addEventListener('storage', this.handleStorageChange)
}
componentWillUnmount() {
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() {