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

Commitbe25c8a

Browse files
committed
auth service
1 parentc383d2a commitbe25c8a

File tree

3 files changed

+40
-33
lines changed

3 files changed

+40
-33
lines changed

‎web-app/src/components/Router/index.tsx

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,37 @@ const editor = acquireVsCodeApi()
2121

2222
// router finds first state match of <Route path='' />
2323
constRouter=({ children}:Props):React.ReactElement<CloneElementProps>|null=>{
24-
//const [state, send] = useMachine(createMachine({ editorSend: editor.postMessage }))
25-
26-
////event bus listener
27-
//React.useEffect(() => {
28-
// const listener = 'message'
29-
// window.addEventListener(listener, send)
30-
// return () => {
31-
// window.removeEventListener(listener, send)
32-
// }
33-
//}, [])
34-
35-
//const childArray = React.Children.toArray(children)
36-
//for (const child of childArray) {
37-
// const { path } = child.props
38-
// let pathMatch
39-
// if (typeof path === 'string') {
40-
// pathMatch = state.matches(path)
41-
// } else if (Array.isArray(path)) {
42-
// pathMatch = path.some(p => state.matches(p))
43-
// } else {
44-
// throw new Error(`Invalid route path ${JSON.stringify(path)}`)
45-
// }
46-
// if (pathMatch) {
47-
// //@ts-ignore
48-
// const element = React.cloneElement<CloneElementProps>(child.props.children, { send, context: state.context })
49-
// return debuggerWrapper(element, state)
50-
// }
51-
//}
52-
//const message = `No Route matches for ${JSON.stringify(state)}`
53-
//onError(new Error(message))
54-
//console.warn(message)
24+
const[state,send]=useMachine(createMachine({editorSend:editor.postMessage}))
25+
26+
// event bus listener
27+
React.useEffect(()=>{
28+
constlistener='message'
29+
window.addEventListener(listener,send)
30+
return()=>{
31+
window.removeEventListener(listener,send)
32+
}
33+
},[])
34+
35+
constchildArray=React.Children.toArray(children)
36+
for(constchildofchildArray){
37+
const{ path}=child.props
38+
letpathMatch
39+
if(typeofpath==='string'){
40+
pathMatch=state.matches(path)
41+
}elseif(Array.isArray(path)){
42+
pathMatch=path.some(p=>state.matches(p))
43+
}else{
44+
thrownewError(`Invalid route path${JSON.stringify(path)}`)
45+
}
46+
if(pathMatch){
47+
//@ts-ignore
48+
constelement=React.cloneElement<CloneElementProps>(child.props.children,{ send,context:state.context})
49+
returndebuggerWrapper(element,state)
50+
}
51+
}
52+
constmessage=`No Route matches for${JSON.stringify(state)}`
53+
onError(newError(message))
54+
console.warn(message)
5555
returnnull
5656
}
5757

‎web-app/src/services/state/machine.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ export const createMachine = (options: any) =>
5353
onDone:'NewOrContinue',
5454
onError:{
5555
target:'Error',
56-
actions:assign({error:(context,event)=>event.data}),
56+
actions:assign({
57+
error:(context,event)=>{
58+
console.log('ERROR')
59+
console.log(JSON.stringify(event))
60+
returnevent.data
61+
},
62+
}),
5763
},
5864
},
5965
},

‎web-app/src/services/state/services/authenticate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface AuthenticateVariables {
1818
editor:'VSCODE'
1919
}
2020

21-
exportasyncfunctionauthenticate(context:CR.MachineContext):Promise<void>{
21+
exportasyncfunctionauthenticate(context:CR.MachineContext):Promise<any>{
2222
constresult=awaitclient
2323
.mutate<AuthenticateData,AuthenticateVariables>({
2424
mutation:authenticateMutation,
@@ -57,6 +57,7 @@ export async function authenticate(context: CR.MachineContext): Promise<void> {
5757
return
5858
}
5959
const{ token}=result.data.editorLogin
60+
console.log(`Token:${token}`)
6061
// add token to headers
6162
setAuthToken(token)
6263
// pass authenticated action back to state machine

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp