Clean up free market countdown bugfix
This commit is contained in:
parent
2b13b1adb7
commit
fb33f829cc
|
@ -21,7 +21,7 @@ import { ManifoldLogo } from './manifold-logo'
|
|||
import { MenuButton } from './menu'
|
||||
import { getNavigationOptions, ProfileSummary } from './profile-menu'
|
||||
import {
|
||||
getUtcFreeMarketResetTimeToday,
|
||||
getUtcFreeMarketResetTime,
|
||||
useHasCreatedContractToday,
|
||||
} from 'web/hooks/use-has-created-contract-today'
|
||||
import { Row } from '../layout/row'
|
||||
|
@ -127,7 +127,7 @@ export default function Sidebar(props: { className?: string }) {
|
|||
const currentPage = router.pathname
|
||||
const [countdown, setCountdown] = useState('...')
|
||||
useEffect(() => {
|
||||
const utcMidnightToLocalDate = new Date(getUtcFreeMarketResetTimeToday())
|
||||
const utcMidnightToLocalDate = new Date(getUtcFreeMarketResetTime(false))
|
||||
const interval = setInterval(() => {
|
||||
const timeUntil = utcMidnightToLocalDate.getTime() - new Date().getTime()
|
||||
const hoursUntil = 24 + timeUntil / 1000 / 60 / 60
|
||||
|
|
|
@ -4,18 +4,12 @@ import { User } from 'common/user'
|
|||
|
||||
let sessionCreatedContractToday = true
|
||||
|
||||
export function getUtcFreeMarketResetTimeToday() {
|
||||
export function getUtcFreeMarketResetTime(yesterday: boolean) {
|
||||
// Uses utc time like the server.
|
||||
const utcFreeMarketResetTime = new Date()
|
||||
utcFreeMarketResetTime.setUTCDate(utcFreeMarketResetTime.getUTCDate())
|
||||
const utcFreeMarketMS = utcFreeMarketResetTime.setUTCHours(16, 0, 0, 0)
|
||||
return utcFreeMarketMS
|
||||
}
|
||||
|
||||
function getUtcFreeMarketResetTimeYesterday() {
|
||||
// Uses utc time like the server.
|
||||
const utcFreeMarketResetTime = new Date()
|
||||
utcFreeMarketResetTime.setUTCDate(utcFreeMarketResetTime.getUTCDate() - 1)
|
||||
utcFreeMarketResetTime.setUTCDate(
|
||||
utcFreeMarketResetTime.getUTCDate() - (yesterday ? 1 : 0)
|
||||
)
|
||||
const utcFreeMarketMS = utcFreeMarketResetTime.setUTCHours(16, 0, 0, 0)
|
||||
return utcFreeMarketMS
|
||||
}
|
||||
|
@ -27,13 +21,13 @@ export const useHasCreatedContractToday = (user: User | null | undefined) => {
|
|||
|
||||
useEffect(() => {
|
||||
setHasCreatedContractToday('loading')
|
||||
const todayAtMidnight = getUtcFreeMarketResetTimeYesterday()
|
||||
const previousResetTime = getUtcFreeMarketResetTime(true)
|
||||
async function listUserContractsForToday() {
|
||||
if (!user) return
|
||||
|
||||
const contracts = await listContracts(user.id)
|
||||
const todayContracts = contracts.filter(
|
||||
(contract) => contract.createdTime > todayAtMidnight
|
||||
(contract) => contract.createdTime > previousResetTime
|
||||
)
|
||||
|
||||
sessionCreatedContractToday = todayContracts.length > 0
|
||||
|
|
Loading…
Reference in New Issue
Block a user