Cleanup
This commit is contained in:
parent
df8a5fff8b
commit
8b18cd1a26
|
@ -15,14 +15,12 @@ export default function NotificationsIcon(props: { className?: string }) {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user) {
|
if (user) {
|
||||||
const bonusChecker = setTimeout(() => {
|
const bonusChecker = setInterval(() => {
|
||||||
requestBonuses({}).catch((error) => {
|
requestBonuses({})
|
||||||
console.log("couldn't get bonuses:", error.message)
|
|
||||||
})
|
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(bonusChecker)
|
clearInterval(bonusChecker)
|
||||||
}
|
}
|
||||||
}, 1000 * 120)
|
}, 1000 * 60)
|
||||||
}
|
}
|
||||||
}, [user])
|
}, [user])
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,8 @@ export type NotificationGroup = {
|
||||||
type: 'income' | 'normal'
|
type: 'income' | 'normal'
|
||||||
}
|
}
|
||||||
|
|
||||||
// This doesn't listen for new notifications, use firebase listener for that
|
// For some reason react-query subscriptions don't actually listen for notifications
|
||||||
|
// Use useUnseenPreferredNotificationGroups to listen for new notifications
|
||||||
export function usePreferredGroupedNotifications(privateUser: PrivateUser) {
|
export function usePreferredGroupedNotifications(privateUser: PrivateUser) {
|
||||||
const [notificationGroups, setNotificationGroups] = useState<
|
const [notificationGroups, setNotificationGroups] = useState<
|
||||||
NotificationGroup[] | undefined
|
NotificationGroup[] | undefined
|
||||||
|
@ -26,11 +27,7 @@ export function usePreferredGroupedNotifications(privateUser: PrivateUser) {
|
||||||
|
|
||||||
const result = useFirestoreQuery(
|
const result = useFirestoreQuery(
|
||||||
[key],
|
[key],
|
||||||
getNotificationsQuery(privateUser.id, false),
|
getNotificationsQuery(privateUser.id, false)
|
||||||
{
|
|
||||||
// subscribe: false,
|
|
||||||
// includeMetadataChanges: true,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (result.isLoading) return
|
if (result.isLoading) return
|
||||||
|
@ -131,7 +128,10 @@ export function useUnseenPreferredNotifications(
|
||||||
const [notifications, setNotifications] = useState<Notification[]>([])
|
const [notifications, setNotifications] = useState<Notification[]>([])
|
||||||
const [userAppropriateNotifications, setUserAppropriateNotifications] =
|
const [userAppropriateNotifications, setUserAppropriateNotifications] =
|
||||||
useState<Notification[]>([])
|
useState<Notification[]>([])
|
||||||
listenForNotifications(privateUser.id, setNotifications, true)
|
|
||||||
|
useEffect(() => {
|
||||||
|
return listenForNotifications(privateUser.id, setNotifications, true)
|
||||||
|
}, [privateUser.id])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const notificationsToShow = getAppropriateNotifications(
|
const notificationsToShow = getAppropriateNotifications(
|
||||||
|
@ -154,7 +154,7 @@ const lessPriorityReasons = [
|
||||||
// 'on_contract_with_users_shares_in',
|
// 'on_contract_with_users_shares_in',
|
||||||
]
|
]
|
||||||
|
|
||||||
export function getAppropriateNotifications(
|
function getAppropriateNotifications(
|
||||||
notifications: Notification[],
|
notifications: Notification[],
|
||||||
notificationPreferences?: notification_subscribe_types
|
notificationPreferences?: notification_subscribe_types
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -39,13 +39,12 @@ export function listenForValue<T>(
|
||||||
|
|
||||||
export function listenForValues<T>(
|
export function listenForValues<T>(
|
||||||
query: Query,
|
query: Query,
|
||||||
setValues: (values: T[]) => void,
|
setValues: (values: T[]) => void
|
||||||
enableCache?: boolean
|
|
||||||
) {
|
) {
|
||||||
// Exclude cached snapshots so we only trigger on fresh data.
|
// Exclude cached snapshots so we only trigger on fresh data.
|
||||||
// includeMetadataChanges ensures listener is called even when server data is the same as cached data.
|
// includeMetadataChanges ensures listener is called even when server data is the same as cached data.
|
||||||
return onSnapshot(query, { includeMetadataChanges: true }, (snapshot) => {
|
return onSnapshot(query, { includeMetadataChanges: true }, (snapshot) => {
|
||||||
if (snapshot.metadata.fromCache && !enableCache) return
|
if (snapshot.metadata.fromCache) return
|
||||||
|
|
||||||
const values = snapshot.docs.map((doc) => doc.data() as T)
|
const values = snapshot.docs.map((doc) => doc.data() as T)
|
||||||
setValues(values)
|
setValues(values)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user