1
1
import { Screen } from "@keybr/pages-shared" ;
2
2
import { type LineList , makeStats } from "@keybr/textinput" ;
3
3
import { TextArea } from "@keybr/textinput-ui" ;
4
- import { type Focusable , Spacer , useView } from "@keybr/widget" ;
4
+ import { Box , type Focusable , Spacer , useView } from "@keybr/widget" ;
5
5
import { useEffect , useRef , useState } from "react" ;
6
6
import {
7
7
type TextGenerator ,
@@ -11,6 +11,7 @@ import { Session, type TestResult } from "../session/index.ts";
11
11
import { type CompositeSettings , useCompositeSettings } from "../settings.ts" ;
12
12
import { views } from "../views.tsx" ;
13
13
import { LineTemplate } from "./LineTemplate.tsx" ;
14
+ import { TestProgress } from "./TestProgress.tsx" ;
14
15
import * as styles from "./TestScreen.module.less" ;
15
16
import { Toolbar } from "./Toolbar.tsx" ;
16
17
@@ -34,10 +35,9 @@ function Controller({
34
35
const { setView } = useView ( views ) ;
35
36
const settings = useCompositeSettings ( ) ;
36
37
const focusRef = useRef < Focusable > ( null ) ;
37
- const [ session , setSession ] = useState < Session > ( ( ) =>
38
- nextTest ( settings , generator ) ,
39
- ) ;
38
+ const [ session , setSession ] = useState ( ( ) => nextTest ( settings , generator ) ) ;
40
39
const [ lines , setLines ] = useState < LineList > ( Session . emptyLines ) ;
40
+ const [ progress , setProgress ] = useState ( Session . emptyProgress ) ;
41
41
useEffect ( ( ) => {
42
42
generator . reset ( mark ) ;
43
43
const session = nextTest ( settings , generator ) ;
@@ -55,36 +55,40 @@ function Controller({
55
55
} }
56
56
/>
57
57
< Spacer size = { 10 } />
58
- < div className = { styles . text } >
59
- < TextArea
60
- focusRef = { focusRef }
61
- settings = { settings . textDisplay }
62
- lines = { lines }
63
- wrap = { false }
64
- onFocus = { ( ) => {
65
- generator . reset ( mark ) ;
66
- const session = nextTest ( settings , generator ) ;
67
- setSession ( session ) ;
68
- setLines ( session . getLines ( ) ) ;
69
- } }
70
- onKeyDown = { session . handleKeyDown }
71
- onKeyUp = { session . handleKeyUp }
72
- onInput = { ( event ) => {
73
- const { completed } = session . handleInput ( event ) ;
74
- setLines ( session . getLines ( ) ) ;
75
- if ( completed ) {
76
- setView ( "report" , { result : makeResult ( session ) } ) ;
77
- }
78
- } }
79
- lineTemplate = { LineTemplate }
80
- />
81
- </ div >
58
+ < Box alignItems = "center" justifyContent = "center" >
59
+ < div className = { styles . text } >
60
+ < TextArea
61
+ focusRef = { focusRef }
62
+ settings = { settings . textDisplay }
63
+ lines = { lines }
64
+ wrap = { false }
65
+ onFocus = { ( ) => {
66
+ generator . reset ( mark ) ;
67
+ const session = nextTest ( settings , generator ) ;
68
+ setSession ( session ) ;
69
+ setLines ( session . getLines ( ) ) ;
70
+ } }
71
+ onKeyDown = { session . handleKeyDown }
72
+ onKeyUp = { session . handleKeyUp }
73
+ onInput = { ( event ) => {
74
+ const { progress, completed } = session . handleInput ( event ) ;
75
+ setLines ( session . getLines ( ) ) ;
76
+ setProgress ( progress ) ;
77
+ if ( completed ) {
78
+ setView ( "report" , { result : makeResult ( session ) } ) ;
79
+ }
80
+ } }
81
+ lineTemplate = { LineTemplate }
82
+ />
83
+ < TestProgress progress = { progress } />
84
+ </ div >
85
+ </ Box >
82
86
</ Screen >
83
87
) ;
84
88
}
85
89
86
90
function nextTest ( settings : CompositeSettings , generator : TextGenerator ) {
87
- return new Session ( { ...settings , numLines : 7 , numCols : 55 } , generator ) ;
91
+ return new Session ( { ...settings , numLines : 5 , numCols : 55 } , generator ) ;
88
92
}
89
93
90
94
function makeResult ( session : Session ) : TestResult {
0 commit comments