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

Commitfb2ae61

Browse files
committed
setup basic error
1 parentc600fc7 commitfb2ae61

File tree

10 files changed

+75
-30
lines changed

10 files changed

+75
-30
lines changed

‎typings/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface Environment {
4040

4141
exportinterfaceMachineContext{
4242
env:Environment
43+
error:string|null
4344
tutorial:G.Tutorial|null
4445
position:Position
4546
progress:Progress

‎web-app/src/Routes.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,24 @@ const { Route } = Router
1515
consttempSend=(action:any)=>console.log('sent')
1616

1717
constRoutes=()=>{
18+
// TODO: refactor for typescript to understand send & context passed into React.cloneElement's
1819
return(
1920
<Workspace>
2021
<Router>
2122
<Routepath={['Start.Startup','Start.Authenticate','Start.NewOrContinue']}>
22-
<LoadingPagetext="Launching..."/>
23+
<LoadingPagetext="Launching..."context={{}asCR.MachineContext}/>
2324
</Route>
2425
<Routepath="Start.SelectTutorial">
25-
<NewPagesend={tempSend}/>
26+
<NewPagesend={tempSend}context={{}asCR.MachineContext}/>
2627
</Route>
2728
<Routepath="Start.ContinueTutorial">
2829
<ContinuePagesend={tempSend}context={{}asCR.MachineContext}/>
2930
</Route>
3031
<Routepath="Tutorial.Initialize">
31-
<LoadingPagetext="Initializing..."/>
32+
<LoadingPagetext="Initializing..."context={{}asCR.MachineContext}/>
3233
</Route>
3334
<Routepath="Tutorial.LoadNext">
34-
<LoadingPagetext="Loading..."/>
35+
<LoadingPagetext="Loading..."context={{}asCR.MachineContext}/>
3536
</Route>
3637
<Routepath="Tutorial.Summary">
3738
<OverviewPagesend={tempSend}context={{}asCR.MachineContext}/>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import*asReactfrom'react'
2+
import*asTfrom'typings'
3+
import{MessageasAlifdMessage}from'@alifd/next'
4+
5+
interfaceProps{
6+
type:'error'
7+
title:string
8+
description?:string
9+
}
10+
11+
constMessage=(props:Props)=>{
12+
return(
13+
<AlifdMessagetype={props.type}title={props.title}>
14+
{props.description}
15+
</AlifdMessage>
16+
)
17+
}
18+
19+
exportdefaultMessage
Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
11
import*asReactfrom'react'
2+
import*asTfrom'typings'
23
importLoadingfrom'../components/Loading'
4+
importMessagefrom'../components/Message'
35

46
interfaceProps{
5-
text:string
7+
text:string
8+
context:T.MachineContext
69
}
710

811
conststyles={
9-
page:{
10-
position:'relative'as'relative',
11-
display:'flex',
12-
alignItems:'center',
13-
justifyContent:'center',
14-
width:'100%',
15-
},
12+
page:{
13+
position:'relative'as'relative',
14+
display:'flex',
15+
flexDirection:'column'as'column',
16+
alignItems:'center',
17+
justifyContent:'center',
18+
width:'100%',
19+
},
1620
}
1721

18-
constLoadingPage=({ text}:Props)=>(
19-
<divstyle={styles.page}>
20-
<Loadingtext={text}/>
21-
</div>
22-
)
22+
constLoadingPage=({ text, context}:Props)=>{
23+
const{ error}=context
24+
if(error){
25+
return(
26+
<divstyle={styles.page}>
27+
<Messagetype="error"title={error}/>
28+
</div>
29+
)
30+
}
31+
return(
32+
<divstyle={styles.page}>
33+
<Loadingtext={text}/>
34+
</div>
35+
)
36+
}
2337

2438
exportdefaultLoadingPage

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import*asReactfrom'react'
22
import{useQuery}from'@apollo/react-hooks'
33
import*asGfrom'typings/graphql'
4-
import*asCRfrom'typings'
4+
import*asTfrom'typings'
55

66
importqueryTutorialsfrom'../../services/apollo/queries/tutorials'
77
importNewPagefrom'./NewPage'
88
importLoadingPagefrom'../LoadingPage'
99
importErrorViewfrom'../../components/Error'
1010

11-
constLoading=()=><LoadingPagetext="Loading tutorials"/>
12-
1311
interfaceContainerProps{
14-
send(action:CR.Action):void
12+
send(action:T.Action):void
13+
context:T.MachineContext
1514
}
1615

1716
interfaceTutorialsData{
@@ -20,23 +19,20 @@ interface TutorialsData {
2019

2120
constNewPageContainer=(props:ContainerProps)=>{
2221
const{ data, loading, error}=useQuery<TutorialsData>(queryTutorials)
23-
if(loading){
24-
return<Loading/>
25-
}
2622

2723
if(error){
2824
return<ErrorViewerror={error}/>
2925
}
3026

27+
if(loading){
28+
return<LoadingPagetext="Loading tutorials"context={props.context}/>
29+
}
30+
3131
if(!data){
3232
returnnull
3333
}
3434

35-
return(
36-
<React.Suspensefallback={Loading}>
37-
<NewPagetutorialList={data.tutorials}/>
38-
</React.Suspense>
39-
)
35+
return<NewPagetutorialList={data.tutorials}/>
4036
}
4137

4238
exportdefaultNewPageContainer

‎web-app/src/services/channel/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Channel {
5757
case'COMMAND_START':
5858
case'COMMAND_SUCCESS':
5959
case'COMMAND_FAIL':
60+
case'ERROR':
6061
this.machineSend(action)
6162
return
6263
default:

‎web-app/src/services/state/actions/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default {
3434
if(!result||!result.data){
3535
// TODO: handle failed authentication
3636
console.error('ERROR: Authentication failed')
37+
channel.receive({data:{type:'ERROR',payload:{error:'Authentication Failed'}}})
3738
return
3839
}
3940
const{ token}=result.data.editorLogin

‎web-app/src/services/state/actions/context.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,10 @@ export default {
211211
returnposition
212212
},
213213
}),
214+
//@ts-ignore
215+
setError:assign({
216+
error:(context:CR.MachineContext,event:CR.MachineEvent):string|null=>{
217+
returnevent.payload.error
218+
},
219+
}),
214220
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
1212
id:'root',
1313
initial:'Start',
1414
context:{
15+
error:null,
1516
env:{machineId:'',sessionId:'',token:''},
1617
tutorial:null,
1718
position:{levelId:'',stepId:''},
@@ -22,6 +23,11 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
2223
},
2324
processes:[],
2425
},
26+
on:{
27+
ERROR:{
28+
actions:['setError'],
29+
},
30+
},
2531
states:{
2632
Start:{
2733
initial:'Startup',

‎web-app/stories/Loading.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ import LoadingPage from '../src/containers/LoadingPage'
77

88
storiesOf('Components',module)
99
.addDecorator(SideBarDecorator)
10-
.add('Loading',()=><LoadingPagetext="Content"/>)
10+
.add('Loading',()=><LoadingPagetext="Content"context={{}}/>)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp