Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d1e0c6

Browse files
committed
setup admin toggle
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parente370e9b commit1d1e0c6

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

‎web-app/src/containers/Start/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import BetaBadge from '../../components/BetaBadge'
66
import{css,jsx}from'@emotion/core'
77
importButtonfrom'../../components/Button'
88
import{Theme}from'../../styles/theme'
9+
import{ADMIN_MODE}from'../../environment'
10+
importAdminTogglefrom'../../services/admin/AdminToggle'
911

1012
conststyles={
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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import*asReactfrom'react'
2+
import{css,jsx}from'@emotion/core'
3+
import{Form,Switch}from'@alifd/next'
4+
importAdminContext,{AdminContextType}from'./context'
5+
6+
typeProps={}
7+
8+
constAdminToggle=(props:Props)=>{
9+
const{ state, dispatch}=React.useContext<AdminContextType>(AdminContext)
10+
return(
11+
<Form.Itemlabel="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+
exportdefaultAdminToggle

‎web-app/src/services/admin/index.tsxrenamed to‎web-app/src/services/admin/context.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@ type State = {
1010

1111
typeAction={type:'ADMIN_MODE_ON'|'ADMIN_MODE_OFF'}
1212

13-
constAdminContext=React.createContext<{state:State;dispatch:(action:Action)=>void}>({
13+
exporttypeAdminContextType={state:State;dispatch:(action:Action)=>void}
14+
15+
constAdminContext=React.createContext<AdminContextType>({
1416
state:{adminMode:false},
1517
dispatch:()=>{},
1618
})
1719

20+
exportdefaultAdminContext
21+
1822
exportconstAdminProvider=(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}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import*asReactfrom'react'
2+
import{storiesOf}from'@storybook/react'
3+
importSideBarDecoratorfrom'../utils/SideBarDecorator'
4+
importAdminTogglefrom'../../src/services/admin/AdminToggle'
5+
6+
storiesOf('Admin',module)
7+
.addDecorator(SideBarDecorator)
8+
.add('Toggle',()=>{
9+
return<AdminToggle/>
10+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp