Show all notifs types

This commit is contained in:
MartinBraquet
2025-10-23 01:46:57 +02:00
parent dc54ed46f8
commit e07cb7fca9
4 changed files with 30 additions and 37 deletions

View File

@@ -1,8 +1,6 @@
import {getPrivateUser} from 'shared/utils'
import {createSupabaseDirectClient, SupabaseDirectClient} from 'shared/supabase/init'
import {Notification} from 'common/notifications'
import {insertNotificationToSupabase} from 'shared/supabase/notifications'
import {getProfile} from 'shared/profiles/supabase'
import {tryCatch} from "common/util/try-catch";
import {Row} from "common/supabase/utils";
@@ -36,11 +34,6 @@ export const createVoteNotificationAll = async () => {
}
export const createVoteNotification = async (user: Row<'users'>, pg: SupabaseDirectClient) => {
const targetPrivateUser = await getPrivateUser(user.id)
const profile = await getProfile(user.id)
if (!targetPrivateUser || !profile) return
const id = `vote-${Date.now()}`
const notification: Notification = {
id,

View File

@@ -30,12 +30,12 @@ export type Notification = {
isSeenOnHref?: string
}
export const NOTIFICATION_TYPES_TO_SELECT = [
'new_match', // new match markets
'comment_on_profile', // endorsements
'profile_like',
'profile_ship',
]
// export const NOTIFICATION_TYPES_TO_SELECT = [
// 'new_match', // new match markets
// 'comment_on_profile', // endorsements
// 'profile_like',
// 'profile_ship',
// ]
export const NOTIFICATIONS_PER_PAGE = 30

View File

@@ -1,48 +1,47 @@
'use client'
import { BellIcon } from '@heroicons/react/outline'
import { BellIcon as SolidBellIcon } from '@heroicons/react/solid'
import { Row } from 'web/components/layout/row'
import { useEffect, useState } from 'react'
import { usePrivateUser } from 'web/hooks/use-user'
import { useGroupedUnseenNotifications } from 'web/hooks/use-notifications'
import { PrivateUser } from 'common/user'
import {
NOTIFICATIONS_PER_PAGE,
NOTIFICATION_TYPES_TO_SELECT,
} from 'common/notifications'
import { usePathname } from 'next/navigation'
import {BellIcon} from '@heroicons/react/outline'
import {BellIcon as SolidBellIcon} from '@heroicons/react/solid'
import {Row} from 'web/components/layout/row'
import {useEffect, useState} from 'react'
import {usePrivateUser} from 'web/hooks/use-user'
import {useGroupedUnseenNotifications} from 'web/hooks/use-notifications'
import {PrivateUser} from 'common/user'
import {NOTIFICATIONS_PER_PAGE,} from 'common/notifications'
import {usePathname} from 'next/navigation'
export function NotificationsIcon(props: { className?: string }) {
const privateUser = usePrivateUser()
const { className } = props
const {className} = props
return (
<Row className="relative justify-center">
{privateUser && <UnseenNotificationsBubble privateUser={privateUser} />}
<BellIcon className={className} />
{privateUser && <UnseenNotificationsBubble privateUser={privateUser}/>}
<BellIcon className={className}/>
</Row>
)
}
export function SolidNotificationsIcon(props: { className?: string }) {
const privateUser = usePrivateUser()
const { className } = props
const {className} = props
return (
<Row className="relative justify-center">
{privateUser && <UnseenNotificationsBubble privateUser={privateUser} />}
<SolidBellIcon className={className} />
{privateUser && <UnseenNotificationsBubble privateUser={privateUser}/>}
<SolidBellIcon className={className}/>
</Row>
)
}
function UnseenNotificationsBubble(props: { privateUser: PrivateUser }) {
const pathname = usePathname()
const { privateUser } = props
const selectTypes = NOTIFICATION_TYPES_TO_SELECT
const {privateUser} = props
const [seen, setSeen] = useState(false)
const unseenSourceIdsToNotificationIds =
useGroupedUnseenNotifications(privateUser.id, selectTypes) ?? []
useGroupedUnseenNotifications(
privateUser.id,
// NOTIFICATION_TYPES_TO_SELECT
) ?? []
const unseenNotifs = Object.keys(unseenSourceIdsToNotificationIds).length
@@ -57,7 +56,8 @@ function UnseenNotificationsBubble(props: { privateUser: PrivateUser }) {
}
return (
<div className="-mt-0.75 text-ink-0 bg-primary-500 absolute ml-3.5 min-w-[15px] rounded-full p-[2px] text-center text-[10px] leading-3 lg:left-0 lg:-mt-1 lg:ml-2">
<div
className="-mt-0.75 text-ink-0 bg-primary-500 absolute ml-3.5 min-w-[15px] rounded-full p-[2px] text-center text-[10px] leading-3 lg:left-0 lg:-mt-1 lg:ml-2">
{unseenNotifs > NOTIFICATIONS_PER_PAGE
? `${NOTIFICATIONS_PER_PAGE}+`
: unseenNotifs}

View File

@@ -8,10 +8,10 @@ import { usePersistentLocalState } from './use-persistent-local-state'
export function useGroupedUnseenNotifications(
userId: string,
selectTypes: string[]
selectTypes?: string[]
) {
const notifications = useUnseenNotifications(userId)?.filter((n) =>
selectTypes.includes(n.sourceType)
selectTypes? selectTypes.includes(n.sourceType) : true
)
return useMemo(() => {
return notifications ? groupNotificationsForIcon(notifications) : undefined