-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathNotificationsApp.tsx
More file actions
117 lines (105 loc) · 3.4 KB
/
NotificationsApp.tsx
File metadata and controls
117 lines (105 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { ContextModule, Intent } from "@artsy/cohesion"
import { Box, Column, FullBleed, GridColumns } from "@artsy/palette"
import {
DESKTOP_HEIGHT,
MIN_LIST_WIDTH,
} from "Apps/Notifications/notificationsutils"
import { useAuthDialog } from "Components/AuthDialog"
import { MetaTags } from "Components/MetaTags"
import { NotificationsContextProvider } from "Components/Notifications/Hooks/useNotificationsContext"
import { NotificationQueryRenderer } from "Components/Notifications/Notification"
import { Notifications } from "Components/Notifications/Notifications"
import { useSystemContext } from "System/Hooks/useSystemContext"
import { useOnce } from "Utils/Hooks/useOnce"
import { Media } from "Utils/Responsive"
import type { NotificationsApp_me$data } from "__generated__/NotificationsApp_me.graphql"
import { useRouter } from "found"
import { useEffect, useRef } from "react"
import { createFragmentContainer, graphql } from "react-relay"
interface NotificationsAppProps {
me: NotificationsApp_me$data
}
const NotificationsApp: React.FC<
React.PropsWithChildren<NotificationsAppProps>
> = ({ me }) => {
const { match } = useRouter()
const { showAuthDialog } = useAuthDialog()
const { isLoggedIn } = useSystemContext()
const contentRef = useRef<HTMLDivElement | null>(null)
useOnce(() => {
if (isLoggedIn) return
showAuthDialog({
options: {
title: "Sign up or log in to view your notifications",
},
analytics: {
contextModule: ContextModule.activity,
intent: Intent.login,
},
})
})
const pathname = match.location.pathname
const isNotificationsPage = pathname.startsWith("/notifications")
// Scroll to top of content pane when route changes
// biome-ignore lint/correctness/useExhaustiveDependencies: ignored using `--suppress`
useEffect(() => {
contentRef.current?.scrollTo(0, 0)
}, [pathname])
return (
<FullBleed>
<NotificationsContextProvider>
<MetaTags
title="Notifications | Artsy"
pathname={isNotificationsPage ? "/notifications" : "/notification"}
/>
<Media greaterThan="xs">
<GridColumns height="100%">
<Column
span={3}
borderRight="1px solid"
borderColor="mono10"
minWidth={MIN_LIST_WIDTH}
height="100%"
>
<Notifications
mode="page"
unreadCounts={me?.unreadNotificationsCount ?? 0}
/>
</Column>
<Column span={9}>
<Box
ref={contentRef as any}
maxHeight={DESKTOP_HEIGHT}
overflow="auto"
>
<Box mx={[2, 4]} my={2}>
<NotificationQueryRenderer />
</Box>
</Box>
</Column>
</GridColumns>
</Media>
<Media at="xs">
{isNotificationsPage ? (
<Notifications
mode="page"
unreadCounts={me.unreadNotificationsCount ?? 0}
/>
) : (
<NotificationQueryRenderer />
)}
</Media>
</NotificationsContextProvider>
</FullBleed>
)
}
export const NotificationsAppFragmentContainer = createFragmentContainer(
NotificationsApp,
{
me: graphql`
fragment NotificationsApp_me on Me {
unreadNotificationsCount
}
`,
},
)