@@ -11,50 +11,49 @@ import "./index.css";
11
11
const fb = new FastbootManager ( ) ;
12
12
fb . init ( ) ;
13
13
14
- const linearProgressCtnEl = document . getElementById ( "linear-progress-ctn" ) ! ;
15
- const linearProgressEl = document . getElementById ( "linear-progress" ) ! ;
16
- const titleEl = document . getElementById ( "title" ) ! ;
17
- const iconCtnEl = document . getElementById ( "icon-ctn" ) ! ;
18
-
19
- fb . addEventListener ( "step" , ( ( event : CustomEvent < FastbootManagerStateType > ) => {
20
- const state = event . detail ;
21
- updateIcon ( iconCtnEl , state ) ;
22
- updateTitle ( titleEl , state ) ;
23
- } ) as EventListener ) ;
24
-
25
- fb . addEventListener ( "progress" , ( (
26
- event : CustomEvent < FastbootManagerStateType > ,
27
- ) => {
28
- const state = event . detail ;
29
- console . log ( "progress" , state ) ;
30
- updateLinearProgress ( linearProgressEl , state ) ;
31
- } ) as EventListener ) ;
32
-
33
- fb . addEventListener ( "message" , ( (
34
- event : CustomEvent < FastbootManagerStateType > ,
35
- ) => {
36
- const state = event . detail ;
37
- updateTitle ( titleEl , state ) ;
38
- } ) as EventListener ) ;
39
-
40
- fb . addEventListener ( "error" , ( (
41
- event : CustomEvent < FastbootManagerStateType > ,
42
- ) => {
43
- const state = event . detail ;
44
- updateIcon ( iconCtnEl , state ) ;
45
- } ) as EventListener ) ;
46
-
47
- function updateLinearProgress (
48
- element : HTMLElement ,
49
- state : FastbootManagerStateType ,
50
- ) {
14
+ function setupProgressIndicatorView ( initialState : FastbootManagerStateType ) {
15
+ renderProgressIndicator ( initialState ) ;
16
+ fb . on ( "progress" , renderProgressIndicator ) ;
17
+ }
18
+
19
+ function setupStatusView ( initialState : FastbootManagerStateType ) {
20
+ renderStatusView ( initialState ) ;
21
+ fb . on ( "message" , renderStatusView ) ;
22
+ fb . on ( "step" , renderStatusView ) ;
23
+ fb . on ( "error" , renderStatusView ) ;
24
+ }
25
+
26
+ function setupIconView ( initialState : FastbootManagerStateType ) {
27
+ renderIconView ( initialState ) ;
28
+ fb . on ( "step" , renderIconView ) ;
29
+ fb . on ( "error" , renderIconView ) ;
30
+ }
31
+
32
+ function setupRetryButtonView ( initialState : FastbootManagerStateType ) {
33
+ renderRetryButtonView ( initialState ) ;
34
+ fb . on ( "error" , renderRetryButtonView ) ;
35
+ }
36
+
37
+ function setupDeviceStatusView ( initialState : FastbootManagerStateType ) {
38
+ renderDeviceStateView ( initialState ) ;
39
+ fb . on ( "connected" , renderDeviceStateView ) ;
40
+ fb . on ( "serial" , renderDeviceStateView ) ;
41
+ }
42
+
43
+ function renderProgressIndicator ( state : FastbootManagerStateType ) {
44
+ const el = document . getElementById ( "linear-progress" ) ! ;
45
+ const ctnEl = document . getElementById ( "linear-progress-ctn" ) ! ;
46
+
51
47
const { progress, step } = state ;
52
- element . style . transform = `translateX(${ progress - 100 } %)` ;
53
- element . className = `absolute top-0 bottom-0 left-0 w-full transition-all ${ fbSteps [ step ] . bgColor } ` ;
54
- linearProgressCtnEl . style . opacity = progress === - 1 ? "0" : "1" ;
48
+ el . style . transform = `translateX(${ progress - 100 } %)` ;
49
+ el . className = `absolute top-0 bottom-0 left-0 w-full transition-all ${ fbSteps [ step ] . bgColor } ` ;
50
+ ctnEl . style . opacity = progress === - 1 ? "0" : "1" ;
55
51
}
56
52
57
- function updateTitle ( el : HTMLElement , state : FastbootManagerStateType ) {
53
+ function renderStatusView ( state : FastbootManagerStateType ) {
54
+ const el = document . getElementById ( "title" ) ! ;
55
+ const subtitleEl = document . getElementById ( "subtitle" ) ! ;
56
+
58
57
const { message, error, progress, step } = state ;
59
58
let title ;
60
59
if ( message && ! error ) {
@@ -66,23 +65,23 @@ function updateTitle(el: HTMLElement, state: FastbootManagerStateType) {
66
65
title = fbSteps [ step ] . status ;
67
66
}
68
67
el . innerHTML = title ;
69
- const subtitleEl = document . getElementById ( "subtitle" ) ! ;
70
68
subtitleEl . innerHTML = fbSteps [ step ] . description ?? "" ;
71
69
}
72
70
73
- function updateIcon ( el : HTMLElement , state : FastbootManagerStateType ) {
71
+ function renderIconView ( state : FastbootManagerStateType ) {
72
+ const el = document . getElementById ( "icon-ctn" ) ! ;
73
+ const img = el . getElementsByTagName ( "img" ) [ 0 ] ;
74
74
const { step, error, onContinue } = state ;
75
75
el . className = `p-8 rounded-full ${ fbSteps [ step ] . bgColor } ` ;
76
76
if ( onContinue ) {
77
77
el . style . cursor = "pointer" ;
78
78
el . addEventListener ( "click" , onContinue ) ;
79
79
}
80
- const img = el . getElementsByTagName ( "img" ) [ 0 ] ;
81
80
img . src = fbSteps [ step ] . icon ;
82
81
img . className = `${ ! error && step !== FastbootStep . DONE ? "animate-pulse" : "" } ` ;
83
82
}
84
83
85
- function updateRetryButton ( state : FastbootManagerStateType ) {
84
+ function renderRetryButtonView ( state : FastbootManagerStateType ) {
86
85
const { error } = state ;
87
86
if ( error !== FastbootError . NONE ) {
88
87
const el = document . getElementById ( "subtitle" ) ! ;
@@ -108,7 +107,7 @@ function updateRetryButton(state: FastbootManagerStateType) {
108
107
}
109
108
}
110
109
111
- function updateDeviceState ( state : FastbootManagerStateType ) {
110
+ function renderDeviceStateView ( state : FastbootManagerStateType ) {
112
111
const { serial, connected } = state ;
113
112
if ( ! connected ) {
114
113
const deviceStateEl = document . getElementById ( "device-state" ) ;
@@ -214,8 +213,8 @@ const fbSteps: Record<
214
213
} ,
215
214
} ;
216
215
217
- updateIcon ( iconCtnEl , fb . state ) ;
218
- updateTitle ( titleEl , fb . state ) ;
219
- updateLinearProgress ( linearProgressEl , fb . state ) ;
220
- updateRetryButton ( fb . state ) ;
221
- updateDeviceState ( fb . state ) ;
216
+ setupProgressIndicatorView ( fb . state ) ;
217
+ setupIconView ( fb . state ) ;
218
+ setupStatusView ( fb . state ) ;
219
+ setupDeviceStatusView ( fb . state ) ;
220
+ setupRetryButtonView ( fb . state ) ;
0 commit comments