mirror of
https://github.com/jxnblk/mdx-deck.git
synced 2024-11-26 11:55:33 +03:00
Adjust querystring parsing
This commit is contained in:
parent
03ec7551ca
commit
0bef30d44d
@ -35,6 +35,7 @@
|
|||||||
"pkg-conf": "^2.1.0",
|
"pkg-conf": "^2.1.0",
|
||||||
"prop-types": "^15.6.2",
|
"prop-types": "^15.6.2",
|
||||||
"puppeteer": "^1.6.1",
|
"puppeteer": "^1.6.1",
|
||||||
|
"querystring": "^0.2.0",
|
||||||
"react": "^16.4.1",
|
"react": "^16.4.1",
|
||||||
"react-dev-utils": "^5.0.1",
|
"react-dev-utils": "^5.0.1",
|
||||||
"react-syntax-highlighter": "^8.0.1",
|
"react-syntax-highlighter": "^8.0.1",
|
||||||
|
39
src/index.js
39
src/index.js
@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
|
|||||||
import { MDXProvider } from '@mdx-js/tag'
|
import { MDXProvider } from '@mdx-js/tag'
|
||||||
import { ThemeProvider } from 'styled-components'
|
import { ThemeProvider } from 'styled-components'
|
||||||
import debounce from 'lodash.debounce'
|
import debounce from 'lodash.debounce'
|
||||||
|
import querystring from 'querystring'
|
||||||
|
|
||||||
import { Provider as ContextProvider } from './context'
|
import { Provider as ContextProvider } from './context'
|
||||||
import DefaultProvider from './Provider'
|
import DefaultProvider from './Provider'
|
||||||
@ -11,7 +12,7 @@ import Slide from './Slide'
|
|||||||
import Dots from './Dots'
|
import Dots from './Dots'
|
||||||
import Root from './Root'
|
import Root from './Root'
|
||||||
import Presenter from './Presenter'
|
import Presenter from './Presenter'
|
||||||
import Overview from './Overview'
|
import Grid from './Overview'
|
||||||
import GoogleFonts from './GoogleFonts'
|
import GoogleFonts from './GoogleFonts'
|
||||||
|
|
||||||
import defaultTheme from './themes'
|
import defaultTheme from './themes'
|
||||||
@ -49,6 +50,7 @@ export const modes = {
|
|||||||
normal: 'NORMAL',
|
normal: 'NORMAL',
|
||||||
presenter: 'PRESENTER',
|
presenter: 'PRESENTER',
|
||||||
overview: 'OVERVIEW',
|
overview: 'OVERVIEW',
|
||||||
|
grid: 'GRID',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const toggleMode = key => state => ({
|
export const toggleMode = key => state => ({
|
||||||
@ -123,6 +125,11 @@ export class SlideDeck extends React.Component {
|
|||||||
this.update(toggleMode('overview'))
|
this.update(toggleMode('overview'))
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
case keys.g:
|
||||||
|
if (alt) {
|
||||||
|
this.update(toggleMode('grid'))
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,13 +148,10 @@ export class SlideDeck extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getMode = () => {
|
getMode = () => {
|
||||||
const { search } = window.location
|
const { mode } = querystring.parse(window.location.search.replace(/^\?/, ''))
|
||||||
const presenter = search.includes('presenter')
|
this.setState({
|
||||||
if (presenter) {
|
mode: modes[mode]
|
||||||
this.setState({
|
})
|
||||||
mode: modes.presenter
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleStorageChange = e => {
|
handleStorageChange = e => {
|
||||||
@ -190,7 +194,11 @@ export class SlideDeck extends React.Component {
|
|||||||
}
|
}
|
||||||
const { index, mode, step } = this.state
|
const { index, mode, step } = this.state
|
||||||
let query = '?'
|
let query = '?'
|
||||||
if (mode === modes.presenter) query += 'presenter'
|
if (mode !== modes.normal) {
|
||||||
|
query += querystring.stringify({
|
||||||
|
mode: mode.toLowerCase()
|
||||||
|
})
|
||||||
|
}
|
||||||
const step_ = step !== -1 ? ('.' + (step + 1)) : ''
|
const step_ = step !== -1 ? ('.' + (step + 1)) : ''
|
||||||
history.pushState(null, null, query + '#' + index + step_)
|
history.pushState(null, null, query + '#' + index + step_)
|
||||||
localStorage.setItem(MDX_SLIDE_INDEX, index)
|
localStorage.setItem(MDX_SLIDE_INDEX, index)
|
||||||
@ -213,9 +221,12 @@ export class SlideDeck extends React.Component {
|
|||||||
Provider = PropsProvider
|
Provider = PropsProvider
|
||||||
} = theme
|
} = theme
|
||||||
|
|
||||||
const Wrapper = mode === modes.presenter
|
let Wrapper = Root
|
||||||
? Presenter
|
if (mode === modes.presenter) {
|
||||||
: Root
|
Wrapper = Presenter
|
||||||
|
} else if (mode === modes.overview) {
|
||||||
|
console.log('todo overview')
|
||||||
|
}
|
||||||
|
|
||||||
const context = {
|
const context = {
|
||||||
...this.state,
|
...this.state,
|
||||||
@ -233,8 +244,8 @@ export class SlideDeck extends React.Component {
|
|||||||
...components
|
...components
|
||||||
}}>
|
}}>
|
||||||
<Provider {...this.state} update={this.update}>
|
<Provider {...this.state} update={this.update}>
|
||||||
{mode === modes.overview ? (
|
{mode === modes.grid ? (
|
||||||
<Overview
|
<Grid
|
||||||
slides={slides}
|
slides={slides}
|
||||||
update={this.update}
|
update={this.update}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user