Remove 'preferred' in variable names

This commit is contained in:
James Grugett 2022-08-28 15:17:27 -05:00
parent c034dc7abb
commit 550f0bdbf4
4 changed files with 19 additions and 20 deletions

View File

@ -19,7 +19,7 @@ import { sum } from 'lodash'
import { formatMoney } from 'common/util/format' import { formatMoney } from 'common/util/format'
import { useWindowSize } from 'web/hooks/use-window-size' import { useWindowSize } from 'web/hooks/use-window-size'
import { Content, useTextEditor } from 'web/components/editor' import { Content, useTextEditor } from 'web/components/editor'
import { useUnseenPreferredNotifications } from 'web/hooks/use-notifications' import { useUnseenNotifications } from 'web/hooks/use-notifications'
import { ChevronDownIcon, UsersIcon } from '@heroicons/react/outline' import { ChevronDownIcon, UsersIcon } from '@heroicons/react/outline'
import { setNotificationsAsSeen } from 'web/pages/notifications' import { setNotificationsAsSeen } from 'web/pages/notifications'
import { usePrivateUser } from 'web/hooks/use-user' import { usePrivateUser } from 'web/hooks/use-user'
@ -277,7 +277,7 @@ function GroupChatNotificationsIcon(props: {
hidden: boolean hidden: boolean
}) { }) {
const { privateUser, group, shouldSetAsSeen, hidden } = props const { privateUser, group, shouldSetAsSeen, hidden } = props
const preferredNotificationsForThisGroup = useUnseenPreferredNotifications( const notificationsForThisGroup = useUnseenNotifications(
privateUser privateUser
// Disabled tracking by customHref for now. // Disabled tracking by customHref for now.
// { // {
@ -286,9 +286,9 @@ function GroupChatNotificationsIcon(props: {
) )
useEffect(() => { useEffect(() => {
if (!preferredNotificationsForThisGroup) return if (!notificationsForThisGroup) return
preferredNotificationsForThisGroup.forEach((notification) => { notificationsForThisGroup.forEach((notification) => {
if ( if (
(shouldSetAsSeen && notification.isSeenOnHref?.includes('chat')) || (shouldSetAsSeen && notification.isSeenOnHref?.includes('chat')) ||
// old style chat notif that simply ended with the group slug // old style chat notif that simply ended with the group slug
@ -297,14 +297,14 @@ function GroupChatNotificationsIcon(props: {
setNotificationsAsSeen([notification]) setNotificationsAsSeen([notification])
} }
}) })
}, [group.slug, preferredNotificationsForThisGroup, shouldSetAsSeen]) }, [group.slug, notificationsForThisGroup, shouldSetAsSeen])
return ( return (
<div <div
className={ className={
!hidden && !hidden &&
preferredNotificationsForThisGroup && notificationsForThisGroup &&
preferredNotificationsForThisGroup.length > 0 && notificationsForThisGroup.length > 0 &&
!shouldSetAsSeen !shouldSetAsSeen
? 'absolute right-4 top-4 h-3 w-3 rounded-full border-2 border-white bg-red-500' ? 'absolute right-4 top-4 h-3 w-3 rounded-full border-2 border-white bg-red-500'
: 'hidden' : 'hidden'

View File

@ -4,7 +4,7 @@ import { Row } from 'web/components/layout/row'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { usePrivateUser } from 'web/hooks/use-user' import { usePrivateUser } from 'web/hooks/use-user'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { useUnseenPreferredNotificationGroups } from 'web/hooks/use-notifications' import { useUnseenGroupedNotification } from 'web/hooks/use-notifications'
import { NOTIFICATIONS_PER_PAGE } from 'web/pages/notifications' import { NOTIFICATIONS_PER_PAGE } from 'web/pages/notifications'
import { PrivateUser } from 'common/user' import { PrivateUser } from 'common/user'
@ -30,7 +30,7 @@ function UnseenNotificationsBubble(props: { privateUser: PrivateUser }) {
else setSeen(false) else setSeen(false)
}, [router.pathname]) }, [router.pathname])
const notifications = useUnseenPreferredNotificationGroups(privateUser) const notifications = useUnseenGroupedNotification(privateUser)
if (!notifications || notifications.length === 0 || seen) { if (!notifications || notifications.length === 0 || seen) {
return <div /> return <div />
} }

View File

@ -13,7 +13,7 @@ export type NotificationGroup = {
type: 'income' | 'normal' type: 'income' | 'normal'
} }
function usePreferredNotifications(privateUser: PrivateUser) { function useNotifications(privateUser: PrivateUser) {
const result = useFirestoreQueryData( const result = useFirestoreQueryData(
['notifications-all', privateUser.id], ['notifications-all', privateUser.id],
getNotificationsQuery(privateUser.id), getNotificationsQuery(privateUser.id),
@ -35,24 +35,23 @@ function usePreferredNotifications(privateUser: PrivateUser) {
return notifications return notifications
} }
export function useUnseenPreferredNotifications(privateUser: PrivateUser) { export function useUnseenNotifications(privateUser: PrivateUser) {
const notifications = usePreferredNotifications(privateUser) const notifications = useNotifications(privateUser)
const unseen = useMemo( return useMemo(
() => notifications && notifications.filter((n) => !n.isSeen), () => notifications && notifications.filter((n) => !n.isSeen),
[notifications] [notifications]
) )
return unseen
} }
export function usePreferredGroupedNotifications(privateUser: PrivateUser) { export function useGroupedNotifications(privateUser: PrivateUser) {
const notifications = usePreferredNotifications(privateUser) const notifications = useNotifications(privateUser)
return useMemo(() => { return useMemo(() => {
if (notifications) return groupNotifications(notifications) if (notifications) return groupNotifications(notifications)
}, [notifications]) }, [notifications])
} }
export function useUnseenPreferredNotificationGroups(privateUser: PrivateUser) { export function useUnseenGroupedNotification(privateUser: PrivateUser) {
const notifications = useUnseenPreferredNotifications(privateUser) const notifications = useUnseenNotifications(privateUser)
return useMemo(() => { return useMemo(() => {
if (notifications) return groupNotifications(notifications) if (notifications) return groupNotifications(notifications)
}, [notifications]) }, [notifications])

View File

@ -26,7 +26,7 @@ import {
} from 'web/components/outcome-label' } from 'web/components/outcome-label'
import { import {
NotificationGroup, NotificationGroup,
usePreferredGroupedNotifications, useGroupedNotifications,
} from 'web/hooks/use-notifications' } from 'web/hooks/use-notifications'
import { TrendingUpIcon } from '@heroicons/react/outline' import { TrendingUpIcon } from '@heroicons/react/outline'
import { formatMoney } from 'common/util/format' import { formatMoney } from 'common/util/format'
@ -124,7 +124,7 @@ function RenderNotificationGroups(props: {
function NotificationsList(props: { privateUser: PrivateUser }) { function NotificationsList(props: { privateUser: PrivateUser }) {
const { privateUser } = props const { privateUser } = props
const [page, setPage] = useState(0) const [page, setPage] = useState(0)
const allGroupedNotifications = usePreferredGroupedNotifications(privateUser) const allGroupedNotifications = useGroupedNotifications(privateUser)
const paginatedGroupedNotifications = useMemo(() => { const paginatedGroupedNotifications = useMemo(() => {
if (!allGroupedNotifications) return if (!allGroupedNotifications) return
const start = page * NOTIFICATIONS_PER_PAGE const start = page * NOTIFICATIONS_PER_PAGE