File tree Expand file tree Collapse file tree 4 files changed +39
-1
lines changed Expand file tree Collapse file tree 4 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ import BetaBadge from '../../components/BetaBadge'
66import { css , jsx } from '@emotion/core'
77import Button from '../../components/Button'
88import { Theme } from '../../styles/theme'
9+ import { ADMIN_MODE } from '../../environment'
10+ import AdminToggle from '../../services/admin/AdminToggle'
911
1012const styles = {
1113 page : ( theme : Theme ) => ( {
@@ -104,6 +106,7 @@ export const StartPage = (props: Props) => (
104106 </ div >
105107 ) }
106108 </ div >
109+ { ADMIN_MODE ? < AdminToggle /> : null }
107110 </ div >
108111)
109112
Original file line number Diff line number Diff line change 1+ import * as React from 'react'
2+ import { css , jsx } from '@emotion/core'
3+ import { Form , Switch } from '@alifd/next'
4+ import AdminContext , { AdminContextType } from './context'
5+
6+ type Props = { }
7+
8+ const AdminToggle = ( props : Props ) => {
9+ const { state, dispatch } = React . useContext < AdminContextType > ( AdminContext )
10+ return (
11+ < Form . Item label = "Admin Mode" >
12+ < Switch
13+ checked = { state . adminMode }
14+ onChange = { ( checked : boolean ) => dispatch ( { type : checked ? 'ADMIN_MODE_ON' : 'ADMIN_MODE_OFF' } ) }
15+ />
16+ </ Form . Item >
17+ )
18+ }
19+
20+ export default AdminToggle
Original file line number Diff line number Diff line change @@ -10,14 +10,19 @@ type State = {
1010
1111type Action = { type : 'ADMIN_MODE_ON' | 'ADMIN_MODE_OFF' }
1212
13- const AdminContext = React . createContext < { state : State ; dispatch : ( action : Action ) => void } > ( {
13+ export type AdminContextType = { state : State ; dispatch : ( action : Action ) => void }
14+
15+ const AdminContext = React . createContext < AdminContextType > ( {
1416 state : { adminMode : false } ,
1517 dispatch : ( ) => { } ,
1618} )
1719
20+ export default AdminContext
21+
1822export const AdminProvider = ( props : Props ) => {
1923 const [ state , dispatch ] = React . useReducer (
2024 ( state : State , action : Action ) => {
25+ console . log ( 'action.type' , action . type )
2126 switch ( action . type ) {
2227 case 'ADMIN_MODE_ON' :
2328 return { ...state , adminMode : true }
Original file line number Diff line number Diff line change 1+ import * as React from 'react'
2+ import { storiesOf } from '@storybook/react'
3+ import SideBarDecorator from '../utils/SideBarDecorator'
4+ import AdminToggle from '../../src/services/admin/AdminToggle'
5+
6+ storiesOf ( 'Admin' , module )
7+ . addDecorator ( SideBarDecorator )
8+ . add ( 'Toggle' , ( ) => {
9+ return < AdminToggle />
10+ } )
You can’t perform that action at this time.
0 commit comments