Skip to content

Commit 3084241

Browse files
committed
fix: Issue #3, serverTime ref, lastRefreshed
1 parent ea5615e commit 3084241

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pages/merchants.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const Merchants: NextPage = (props) => {
4848
false
4949
)
5050
const [mSchedules, setMSchedules] = useState<{ [k: string]: Interval[] }>({})
51+
const [mActive, setMActive] = useState(false)
5152

5253
useEffect(() => {
5354
const timer = setInterval(() => {
@@ -56,7 +57,7 @@ const Merchants: NextPage = (props) => {
5657
setServerTime(now.setZone(regionTZ))
5758
}, 1000)
5859
return () => {
59-
clearInterval(timer) // Return a funtion to clear the timer so that it will stop being called on unmount
60+
clearInterval(timer) // Return a function to clear the timer so that it will stop being called on unmount
6061
}
6162
}, [regionTZName, regionTZ])
6263

@@ -190,10 +191,16 @@ const Merchants: NextPage = (props) => {
190191
wanderingMerchants,
191192
merchantAPIData,
192193
mSchedules,
194+
mActive
193195
])
194196
useEffect(() => {
195-
if (currDate.minute < 30 || currDate.minute >= 55) setMerchantAPIData({})
196-
}, [currDate.minute])
197+
// Changed to serverTime to prevent mActive from triggering early for time zones using 30 or 45 minute offsets
198+
if (serverTime.minute < 30 || serverTime.minute >= 55) {
199+
setMerchantAPIData({})
200+
setMActive(false)
201+
}
202+
else { setMActive(true) }
203+
}, [serverTime.minute])
197204
return (
198205
<>
199206
<Head>
@@ -316,7 +323,7 @@ const Merchants: NextPage = (props) => {
316323
</a>
317324
<div className="absolute right-5 top-7">
318325
{t('last-updated')}:{' '}
319-
{dataLastRefreshed.toLocaleString(
326+
{(viewLocalizedTime ? dataLastRefreshed : dataLastRefreshed.setZone(regionTZ)).toLocaleString(
320327
view24HrTime
321328
? DateTime.TIME_24_WITH_SECONDS
322329
: DateTime.TIME_WITH_SECONDS

0 commit comments

Comments
 (0)