This commit is contained in:
mantikoros 2022-07-17 15:17:31 -05:00
parent 07bfdadd25
commit b5f0b58898
2 changed files with 20 additions and 11 deletions

View File

@ -13,7 +13,7 @@ import clsx from 'clsx'
import Link from 'next/link' import Link from 'next/link'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { usePrivateUser, useUser } from 'web/hooks/use-user' import { usePrivateUser, useUser } from 'web/hooks/use-user'
import { firebaseLogout, updateUser, User } from 'web/lib/firebase/users' import { firebaseLogout, User } from 'web/lib/firebase/users'
import { ManifoldLogo } from './manifold-logo' import { ManifoldLogo } from './manifold-logo'
import { MenuButton } from './menu' import { MenuButton } from './menu'
import { ProfileSummary } from './profile-menu' import { ProfileSummary } from './profile-menu'
@ -193,10 +193,13 @@ export default function Sidebar(props: { className?: string }) {
const user = useUser() const user = useUser()
const privateUser = usePrivateUser(user?.id) const privateUser = usePrivateUser(user?.id)
// usePing(user?.id)
const navigationOptions = !user ? signedOutNavigation : getNavigation() const navigationOptions = !user ? signedOutNavigation : getNavigation()
const mobileNavigationOptions = !user const mobileNavigationOptions = !user
? signedOutMobileNavigation ? signedOutMobileNavigation
: signedInMobileNavigation : signedInMobileNavigation
const memberItems = ( const memberItems = (
useMemberGroups( useMemberGroups(
user?.id, user?.id,
@ -208,16 +211,6 @@ export default function Sidebar(props: { className?: string }) {
href: `${groupPath(group.slug)}/${GROUP_CHAT_SLUG}`, href: `${groupPath(group.slug)}/${GROUP_CHAT_SLUG}`,
})) }))
useEffect(() => {
if (!user) return
const pingInterval = setInterval(() => {
updateUser(user.id, {
lastPingTime: Date.now(),
})
}, 1000 * 30)
return () => clearInterval(pingInterval)
}, [user])
return ( return (
<nav aria-label="Sidebar" className={className}> <nav aria-label="Sidebar" className={className}>
<ManifoldLogo className="py-6" twoLine /> <ManifoldLogo className="py-6" twoLine />

16
web/hooks/use-ping.ts Normal file
View File

@ -0,0 +1,16 @@
import { useEffect } from 'react'
import { updateUser } from 'web/lib/firebase/users'
export const usePing = (userId: string | undefined) => {
useEffect(() => {
if (!userId) return
const pingInterval = setInterval(() => {
updateUser(userId, {
lastPingTime: Date.now(),
})
}, 1000 * 30)
return () => clearInterval(pingInterval)
}, [userId])
}