@@ -14,6 +14,18 @@ const PingDot = styled.div<{ $on: boolean }>`
14
14
${ ( props ) => ( props . $on ? tw `visible` : tw `invisible` ) }
15
15
`
16
16
17
+ /**
18
+ * This function applies the animation flag to the flagArray based on the config.
19
+ * As a result, it controls the animation by passing the boolean values of the flagArray to each element accordingly.
20
+ * @param config is the configuration object containing the animation starting index (index) and route type (dotType)
21
+ * @param flagArray is the current animation flag array
22
+ * @returns RouteAnimationFlag : Updated animation flag array
23
+ *
24
+ * @example If flagArray is all false and config is {dotType: 'direct', index: 2},
25
+ * it should originally set true for indices 2 and 3 in the 'direct' array of flagArray,
26
+ * but since there is no index 3 in dotIndex in RouteVisual, it sets true for indices 2 and 4 and returns it.
27
+ */
28
+
17
29
export const applyDotAnimationFlag = (
18
30
config : DotAnimationConfig ,
19
31
flagArray : RouteAnimationFlag ,
@@ -29,7 +41,7 @@ export const applyDotAnimationFlag = (
29
41
newFlagArray . direct [ i >= 3 ? i + 1 : i ] = true
30
42
if ( config . dotType === 'cycle' ) newFlagArray . cycle [ i ] = true
31
43
if ( config . dotType === 'yesulin' )
32
- newFlagArray . yesulin [ i === 2 ? i + 1 : i ] = true
44
+ newFlagArray . yesulin [ i === 2 ? 3 : i ] = true
33
45
if ( config . dotType === 'jungang' ) newFlagArray . jungang [ i ] = true
34
46
}
35
47
return newFlagArray
@@ -43,18 +55,29 @@ const getDotAniTimetableConfig = (type: string, index: number) => {
43
55
else return { dotType : 'direct' , index : index }
44
56
}
45
57
58
+ /**
59
+ * This function determines which route type and starting position the animation should use based on the tab and timetable type
60
+ * @param tab is shuttle bus tabs such as 'shuttlecoke_o', 'subway'
61
+ * @param currTimetable is current shuttle bus type and departure time from the timetable
62
+ * @returns DotAnimationConfig[] : Array of configuration objects,
63
+ * each containing animation starting index (index) and route type (dotType)
64
+ *
65
+ * @example If the tab is 'shuttlecoke_o' and the current timetable is {type: 'C', time: '~~:~~'},
66
+ * then the function will return [{dotType: 'cycle', index: 1}]
67
+ */
68
+
46
69
export const getDotAnimationConfig = (
47
70
tab : string ,
48
- timetable : SingleShuttleSchedule ,
71
+ currTimetable : SingleShuttleSchedule ,
49
72
) => {
50
- if ( timetable ?. time !== '' ) {
73
+ if ( currTimetable !== undefined ) {
51
74
switch ( tab ) {
52
75
case 'shuttlecoke_o' :
53
- return [ getDotAniTimetableConfig ( timetable . type , 1 ) ]
76
+ return [ getDotAniTimetableConfig ( currTimetable . type , 1 ) ]
54
77
case 'subway' :
55
- return [ getDotAniTimetableConfig ( timetable . type , 2 ) ]
78
+ return [ getDotAniTimetableConfig ( currTimetable . type , 2 ) ]
56
79
case 'yesulin' :
57
- return [ getDotAniTimetableConfig ( timetable . type , 3 ) ]
80
+ return [ getDotAniTimetableConfig ( currTimetable . type , 3 ) ]
58
81
case 'jungang' :
59
82
return [
60
83
{
@@ -63,7 +86,7 @@ export const getDotAnimationConfig = (
63
86
} ,
64
87
]
65
88
case 'shuttlecoke_i' :
66
- if ( timetable . type === 'NA' ) return [ ]
89
+ if ( currTimetable . type === 'NA' ) return [ ]
67
90
68
91
return [
69
92
{
@@ -80,50 +103,53 @@ export const getDotAnimationConfig = (
80
103
} ,
81
104
{
82
105
dotType : 'yesulin' ,
83
- index : 3 ,
106
+ index : 4 ,
84
107
} ,
85
108
]
86
109
default :
87
- return [ getDotAniTimetableConfig ( timetable . type , 0 ) ]
110
+ return [ getDotAniTimetableConfig ( currTimetable . type , 0 ) ]
88
111
}
89
112
}
90
113
return [ ]
91
114
}
92
115
93
116
export const useDotAnimation = ( tab : string ) => {
94
117
const [ flagTable , setFlagTable ] = React . useState < RouteAnimationFlag > ( {
95
- direct : [ false , false , false , false , false ] ,
118
+ direct : [ false , false , false , false , false , false ] ,
96
119
cycle : [ false , false , false , false , false , false ] ,
97
- yesulin : [ false , false , false , false , false ] ,
120
+ yesulin : [ false , false , false , false , false , false ] ,
98
121
jungang : [ false , false , false , false , false , false ] ,
99
122
} )
100
- const timetable = useTimeTableContext ( ) . timetable
101
- const checkTimetable = React . useRef < SingleShuttleSchedule > ( )
123
+ const currTimetableArray = useTimeTableContext ( ) . currTimetable
124
+ const checkCurrTimetable = React . useRef < SingleShuttleSchedule > ( )
102
125
103
126
React . useEffect ( ( ) => {
104
- checkTimetable . current = undefined
127
+ checkCurrTimetable . current = undefined
105
128
} , [ ] )
106
129
107
130
useEffect ( ( ) => {
108
131
let tempFlagTable = {
109
- direct : [ false , false , false , false , false ] ,
132
+ direct : [ false , false , false , false , false , false ] ,
110
133
cycle : [ false , false , false , false , false , false ] ,
111
- yesulin : [ false , false , false , false , false ] ,
134
+ yesulin : [ false , false , false , false , false , false ] ,
112
135
jungang : [ false , false , false , false , false , false ] ,
113
136
}
114
137
setFlagTable ( tempFlagTable )
115
- if ( checkTimetable . current === timetable ) return
116
138
117
- checkTimetable . current = timetable
139
+ if ( checkCurrTimetable . current === currTimetableArray [ 0 ] ) return
140
+
141
+ checkCurrTimetable . current = currTimetableArray [ 0 ]
118
142
119
- const dotAnimationConfig = getDotAnimationConfig ( tab , timetable )
143
+ currTimetableArray . map ( ( currTimetable : SingleShuttleSchedule ) => {
144
+ const dotAnimationConfig = getDotAnimationConfig ( tab , currTimetable )
120
145
121
- dotAnimationConfig . forEach ( ( config ) => {
122
- tempFlagTable = applyDotAnimationFlag ( config , tempFlagTable )
146
+ dotAnimationConfig . forEach ( ( config ) => {
147
+ tempFlagTable = applyDotAnimationFlag ( config , tempFlagTable )
148
+ } )
123
149
} )
124
150
125
151
setFlagTable ( tempFlagTable )
126
- } , [ timetable , tab ] )
152
+ } , [ currTimetableArray , tab ] )
127
153
128
154
return flagTable
129
155
}
0 commit comments