1
1
import type { editor } from 'monaco-editor' ;
2
2
import { useCallback , useContext , useEffect , useMemo , useState } from 'react' ;
3
- import { Skeleton } from '@arco-design/web-react' ;
3
+ import { Button , Skeleton } from '@arco-design/web-react' ;
4
4
import localCache , { QUESTION_STATUS } from '@src/utils/local-cache' ;
5
5
import emitter from '@src/utils/emit' ;
6
6
import Context from '@src/utils/context' ;
7
7
import { monacoEditorLoaded , monacoInstance } from '@src/utils/monaco' ;
8
8
import { QuestionFiles } from '@src/utils/type-challenges' ;
9
9
import SubmitStatus from '@src/components/SubmitStatus' ;
10
+ import i18n from '@config/i18n.json' ;
11
+ import { Setting } from '@src/utils/setting' ;
10
12
import styles from './index.module.less' ;
11
13
12
14
function formatErrorFromMarkers ( markers : editor . IMarker [ ] ) {
@@ -17,12 +19,12 @@ function formatErrorFromMarkers(markers: editor.IMarker[]) {
17
19
} ) ;
18
20
}
19
21
20
- function createResultError ( status : string [ ] ) {
22
+ function createResultError ( status : string [ ] , language : Setting [ 'language' ] ) {
21
23
return (
22
24
< div className = { styles [ 'result-errors' ] } >
23
25
< div className = { styles [ 'result-error-title' ] } >
24
26
< SubmitStatus status = { QUESTION_STATUS . unAccepted } />
25
- < span style = { { marginLeft : 8 } } > Compilation Error </ span >
27
+ < span style = { { marginLeft : 8 } } > { i18n [ 'compilation_error' ] [ language ] } </ span >
26
28
</ div >
27
29
< div className = { styles [ 'result-error-info' ] } >
28
30
{ status . map ( function ( error ) {
@@ -38,29 +40,45 @@ function createResultError(status: string[]) {
38
40
}
39
41
40
42
const Results = function ( ) {
41
- const [ { currentQuestion } ] = useContext ( Context ) ;
43
+ const [ { currentQuestion, setting : { language } } ] = useContext ( Context ) ;
42
44
const [ loading , setLoading ] = useState ( true ) ;
43
45
const [ status , setStatus ] = useState < string [ ] > ( [ ] ) ;
44
46
47
+ const shareSolutionHref = useMemo ( function ( ) {
48
+ const questionNum = currentQuestion . match ( / [ 0 - 9 ] + (? = - ) / ) ?. [ 0 ] ;
49
+ return `https://tsch.js.org/${ Number ( questionNum ) } /answer/${ language === 'en' ? '' : language } ` ;
50
+ } , [ currentQuestion , language ] ) ;
51
+
45
52
const resultContent = useMemo (
46
53
function ( ) {
47
54
if ( status . length === 0 ) {
48
55
return (
49
56
< div className = { styles [ 'result-accept' ] } >
50
57
< div className = { styles [ 'result-accept-title' ] } >
51
58
< SubmitStatus status = { QUESTION_STATUS . accepted } />
52
- < span style = { { marginLeft : 8 } } > Compilation Successful </ span >
59
+ < span style = { { marginLeft : 8 } } > { i18n [ 'compilation_success' ] [ language ] } </ span >
53
60
</ div >
54
61
< div className = { styles [ 'result-accept-info' ] } >
55
- 🎉 Yay! You have finished this challenge.
62
+ { i18n [ 'compilation_success_info' ] [ language ] }
63
+ </ div >
64
+ < div className = { styles [ 'result-accept-btns' ] } >
65
+ < Button
66
+ type = { 'primary' }
67
+ status = { 'success' }
68
+ target = { '_blank' }
69
+ href = { shareSolutionHref }
70
+ style = { { borderRadius : 4 } }
71
+ >
72
+ { i18n [ 'share_solution' ] [ language ] }
73
+ </ Button >
56
74
</ div >
57
75
</ div >
58
76
) ;
59
77
} else {
60
- return createResultError ( status ) ;
78
+ return createResultError ( status , language ) ;
61
79
}
62
80
} ,
63
- [ status ] ,
81
+ [ status , language ] ,
64
82
) ;
65
83
66
84
const validate = useCallback (
0 commit comments