Skip to content
Merged
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: 0 additions & 16 deletions src/api/home.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
import { buildUrl } from './utils'

export const getActiveUserCount = async (): Promise<number> => {
try {
const response = await fetch('/api/active-users')

const data = await response.json()

if (data.success && typeof data.activeUsers === 'number') {
return data.activeUsers
}
} catch (error) {
console.error('Failed to fetch active user count:', error)
}

return 0
}

export const getGlobalStats = async () => {
const res = await fetch(buildUrl('auth/global_stats'))
const data = await res.json()
Expand Down
44 changes: 8 additions & 36 deletions src/components/Home/HomeHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'src/lib/analytics'

import { PlayType } from 'src/types'
import { getGlobalStats, getActiveUserCount } from 'src/api'
import { getGlobalStats } from 'src/api'
import { AuthContext, ModalContext } from 'src/contexts'
import { AnimatedNumber } from 'src/components/Common/AnimatedNumber'

Expand Down Expand Up @@ -112,7 +112,6 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
puzzle_games_total: number
turing_games_total: number
}>()
const [activeUsers, setActiveUsers] = useState<number>(0)
const { setPlaySetupModalProps } = useContext(ModalContext)
const { user, connectLichess } = useContext(AuthContext)

Expand All @@ -139,22 +138,6 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
return () => clearInterval(interval)
}, [])

// Fetch active users count and set up periodic updates
useEffect(() => {
const fetchActiveUsers = async () => {
const count = await getActiveUserCount()
setActiveUsers(count)
}

// Fetch immediately
fetchActiveUsers()

// Update every 5 minutes
const interval = setInterval(fetchActiveUsers, 5 * 60 * 1000)

return () => clearInterval(interval)
}, [])

return (
<Fragment>
<BetaBlurb />
Expand Down Expand Up @@ -263,15 +246,6 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
</div>
</div>
<motion.div className="flex flex-wrap justify-center gap-6 px-2">
{activeUsers > 0 && (
<p className="text-center text-base text-white/80">
<AnimatedNumber
value={activeUsers}
className="font-bold text-white"
/>{' '}
recent users
</p>
)}
<p className="text-center text-base text-white/80">
<AnimatedNumber
value={globalStats?.play_moves_total || 0}
Expand All @@ -286,15 +260,13 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
/>{' '}
puzzles solved
</p>
{activeUsers <= 0 && (
<p className="text-center text-base text-white/80">
<AnimatedNumber
value={globalStats?.turing_games_total || 0}
className="font-bold text-white"
/>{' '}
turing games played
</p>
)}
<p className="text-center text-base text-white/80">
<AnimatedNumber
value={globalStats?.turing_games_total || 0}
className="font-bold text-white"
/>{' '}
turing games played
</p>
</motion.div>
</div>
</Fragment>
Expand Down
117 changes: 0 additions & 117 deletions src/pages/api/active-users.ts

This file was deleted.

Loading