Skip to content

Commit 9442d36

Browse files
committed
Fix Little Issue
1 parent 4e50370 commit 9442d36

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

src/app/components/routemap/Animation.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,24 @@ export const circleAnimation = (
2727
jungang: boolean[]
2828
},
2929
) => {
30-
const tableArray = tabArray
30+
const newTableArray = {
31+
direct: [...tabArray.direct],
32+
cycle: [...tabArray.cycle],
33+
yesulin: [...tabArray.yesulin],
34+
jungang: [...tabArray.jungang],
35+
}
3136
for (let i = type.index; i <= type.index + 1; i++) {
3237
if (type.dotType === 'direct') {
33-
tableArray.direct[i] = true
38+
newTableArray.direct[i] = true
3439
} else if (type.dotType === 'cycle') {
35-
tableArray.cycle[i] = true
40+
newTableArray.cycle[i] = true
3641
} else if (type.dotType === 'yesulin') {
37-
tableArray.yesulin[i] = true
42+
newTableArray.yesulin[i] = true
3843
} else if (type.dotType === 'jungang') {
39-
tableArray.jungang[i] = true
44+
newTableArray.jungang[i] = true
4045
}
4146
}
42-
setTableArray(tableArray)
47+
setTableArray(newTableArray)
4348
}
4449

4550
const timetableType = (type: string, index: number) => {
@@ -111,6 +116,10 @@ export const useAnimation = (tab: string) => {
111116
const timetables = useTimeTableContext().timetable
112117
const checkTable = React.useRef<SingleShuttleSchedule>()
113118

119+
React.useEffect(() => {
120+
checkTable.current = undefined
121+
}, [])
122+
114123
useEffect(() => {
115124
const tableArray = {
116125
direct: [false, false, false, false, false],
@@ -119,12 +128,12 @@ export const useAnimation = (tab: string) => {
119128
jungang: [false, false, false, false, false, false],
120129
}
121130

131+
setTimetable(tableArray)
132+
122133
if (checkTable.current === timetables) return
123134

124135
checkTable.current = timetables
125136

126-
setTimetable(tableArray)
127-
128137
const animateType = CircleAnimateType(tab, timetables)
129138

130139
animateType.forEach((item) => {
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import React, { useEffect } from 'react'
22

3-
const Responsive = () => {
3+
const useResponsive = () => {
44
const [screenWidth, setScreenWidth] = React.useState(window.innerWidth)
55

66
useEffect(() => {
7-
window.addEventListener('resize', () => setScreenWidth(window.innerWidth))
7+
const handleResize = () => {
8+
setScreenWidth(window.innerWidth)
9+
}
10+
11+
window.addEventListener('resize', handleResize)
812

913
return () => {
10-
window.removeEventListener('resize', () =>
11-
setScreenWidth(window.innerWidth),
12-
)
14+
window.removeEventListener('resize', handleResize)
1315
}
1416
}, [])
1517

1618
return screenWidth
1719
}
1820

19-
export default Responsive
21+
export default useResponsive

src/app/components/routemap/RouteVisual.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import styled from 'styled-components'
44
import tw from 'twin.macro'
55

66
import Animation, { useAnimation } from '@/components/routemap/Animation'
7-
import Responsive from '@/components/routemap/Responsive'
7+
import useResponsive from '@/components/routemap/Responsive'
88

99
const RouteLine = styled.div`
1010
${tw`absolute transition duration-150 ease-in-out z-0 h-[0.2rem] top-1 rt1:top-[0.2rem] rt1:h-[0.16rem] left-[0.6rem] max-w-[13.125rem]`}
@@ -35,7 +35,7 @@ const LineRoute = (props: {
3535
isPrevStop: (line: string, index: number) => boolean
3636
index: number
3737
}) => {
38-
const screenWidth = Responsive()
38+
const screenWidth = useResponsive()
3939

4040
if (props.rootStatus === 'direct' && props.index === 4) return
4141
else if (props.index === 5) return

src/app/components/shuttle/Shuttle.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,12 @@ export const Shuttle = ({ location }: ShuttleStop) => {
422422

423423
useEffect(() => {
424424
if (timetable.data !== undefined) {
425-
const filtered = timetable.data.filter((val) => isAfterCurrentTime(val))
426-
filtered[0] === undefined
427-
? setTimetable({ time: '', type: 'NA' })
428-
: setTimetable(filtered[0])
425+
setTimeout(() => {
426+
const filtered = timetable.data.filter((val) => isAfterCurrentTime(val))
427+
filtered[0] === undefined
428+
? setTimetable({ time: '', type: 'NA' })
429+
: setTimetable(filtered[0])
430+
}, 3000)
429431
}
430432
}, [timetable.data, setTimetable])
431433

src/app/context/TimeTableContext.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ export const TimeTableContextProvider = ({
2222
time: '',
2323
type: 'NA',
2424
})
25+
26+
const value = React.useMemo(() => ({ timetable, setTimetable }), [timetable])
27+
2528
return (
26-
<TimeTableContext.Provider value={{ timetable, setTimetable }}>
29+
<TimeTableContext.Provider value={value}>
2730
{children}
2831
</TimeTableContext.Provider>
2932
)

0 commit comments

Comments
 (0)