Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions pages/alarms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const Alarms: NextPage = () => {
const [serverTime, setServerTime] = useState<DateTime>(
currDate.setZone(regionTZ)
)
const [selectedDate, setSelectedDate] = useState(currDate.setZone(regionTZ))
const [selectedDate, setSelectedDate] = useState(currDate.set({hour: 0, minute: 0, second: 0, millisecond: 0}).setZone(regionTZ))

const [gameEvents, setGameEvents] = useState<Array<GameEvent> | undefined>(
undefined
Expand Down Expand Up @@ -151,8 +151,10 @@ const Alarms: NextPage = () => {
const [disabledAlarms, setDisabledAlarms] = useLocalStorage<{
[key: string]: number
}>('disabledAlarms', {})
const [desktopNotifications, setDesktopNotifications] =
useLocalStorage<boolean>('desktopNotifications', false)
const [desktopNotifications, setDesktopNotifications] = useLocalStorage<boolean>(
'desktopNotifications',
false
)
const [hideGrandPrix, setHideGrandPrix] = useLocalStorage<boolean>(
'hideGrandPrix',
false
Expand Down Expand Up @@ -185,7 +187,7 @@ const Alarms: NextPage = () => {
if (regionTZ !== undefined) {
setMounted(true)
setServerTime(currDate.setZone(regionTZ))
setSelectedDate(currDate.setZone(regionTZ))
setSelectedDate(currDate.setZone(regionTZ).set({hour: 0, minute: 0, second: 0, millisecond: 0}))
}
}, [regionTZ])

Expand All @@ -200,14 +202,14 @@ const Alarms: NextPage = () => {
useEffect(() => {
const timer = setInterval(() => {
let now = DateTime.now()
if (currDate.endOf('day').diffNow().toMillis() < 0) setSelectedDate(now)
if (serverTime.endOf('day').diffNow().toMillis() < 0) setSelectedDate(now.setZone(regionTZ).set({hour: 0, minute: 0, second: 0, millisecond: 0}))
setCurrDate(now)
setServerTime(now.setZone(regionTZ))
}, 1000)
return () => {
clearInterval(timer) // Return a function to clear the timer so that it will stop being called on unmount
}
}, [regionTZ, view24HrTime, viewLocalizedTime, selectedDate])
}, [regionTZ, view24HrTime, viewLocalizedTime, selectedDate, serverTime.day])

// clear disabled alarm when alarm expires
useEffect(() => {
Expand Down Expand Up @@ -537,7 +539,7 @@ const Alarms: NextPage = () => {
</button>
<button
className="btn relative text-2xl text-stone-200"
onClick={(e) => setSelectedDate(serverTime)}
onClick={(e) => setSelectedDate(serverTime.setZone(regionTZ).set({hour: 0, minute: 0, second: 0, millisecond: 0}))}
>
<span>
{selectedDate.monthLong} {selectedDate.day}
Expand Down
15 changes: 11 additions & 4 deletions pages/merchants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const Merchants: NextPage = (props) => {
false
)
const [mSchedules, setMSchedules] = useState<{ [k: string]: Interval[] }>({})
const [mActive, setMActive] = useState(false)

useEffect(() => {
const timer = setInterval(() => {
Expand All @@ -74,7 +75,7 @@ const Merchants: NextPage = (props) => {
setServerTime(now.setZone(regionTZ))
}, 1000)
return () => {
clearInterval(timer) // Return a funtion to clear the timer so that it will stop being called on unmount
clearInterval(timer) // Return a function to clear the timer so that it will stop being called on unmount
}
}, [regionTZName, regionTZ])

Expand Down Expand Up @@ -208,10 +209,16 @@ const Merchants: NextPage = (props) => {
wanderingMerchants,
merchantAPIData,
mSchedules,
mActive
])
useEffect(() => {
if (currDate.minute < 30 || currDate.minute >= 55) setMerchantAPIData({})
}, [currDate.minute])
// Changed to serverTime to prevent mActive from triggering early for time zones using 30 or 45 minute offsets
if (serverTime.minute < 30 || serverTime.minute >= 55) {
setMerchantAPIData({})
setMActive(false)
}
else { setMActive(true) }
}, [serverTime.minute])
return (
<>
<Head>
Expand Down Expand Up @@ -334,7 +341,7 @@ const Merchants: NextPage = (props) => {
</a>
<div className="absolute right-5 top-7">
{t('last-updated')}:{' '}
{dataLastRefreshed.toLocaleString(
{(viewLocalizedTime ? dataLastRefreshed : dataLastRefreshed.setZone(regionTZ)).toLocaleString(
view24HrTime
? DateTime.TIME_24_WITH_SECONDS
: DateTime.TIME_WITH_SECONDS
Expand Down