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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
"use client"
import { useEffect, useRef } from "react"
import { Group, Panel, Separator, useDefaultLayout, useGroupRef } from "react-resizable-panels"
import { useUserInterfaceStore } from "@/lib/stores/user-interface-store"
import { useMarkAllAsRead } from "@/lib/queries/use-mark-all-as-read"
import { useSubscriptions } from "@/lib/queries/use-subscriptions"
import { useUnreadCounts } from "@/lib/queries/use-unread-counts"
import { useIsMobile } from "@/lib/hooks/use-is-mobile"
import { classNames } from "@/lib/utilities"
import { EntryList } from "./entry-list"
import { EntryDetailPanel } from "./entry-detail-panel"
import { ErrorBoundary } from "./error-boundary"
import { useRealtimeEntries } from "@/lib/hooks/use-realtime-entries"
import { useCustomFeeds } from "@/lib/queries/use-custom-feeds"
interface ReaderShellProperties {
userEmailAddress: string | null
feedFilter: "all" | "saved"
folderIdentifier?: string | null
feedIdentifier?: string | null
customFeedIdentifier?: string | null
}
export function ReaderShell({
userEmailAddress,
feedFilter,
folderIdentifier,
feedIdentifier,
customFeedIdentifier,
}: ReaderShellProperties) {
const selectedEntryIdentifier = useUserInterfaceStore(
(state) => state.selectedEntryIdentifier
)
const setSelectedEntryIdentifier = useUserInterfaceStore(
(state) => state.setSelectedEntryIdentifier
)
const entryListViewMode = useUserInterfaceStore(
(state) => state.entryListViewMode
)
const setEntryListViewMode = useUserInterfaceStore(
(state) => state.setEntryListViewMode
)
const setSearchOpen = useUserInterfaceStore((state) => state.setSearchOpen)
const markAllAsRead = useMarkAllAsRead()
const { data: subscriptionsData } = useSubscriptions()
const { data: unreadCounts } = useUnreadCounts()
const { data: customFeedsData } = useCustomFeeds()
const isMobile = useIsMobile()
const focusedPanel = useUserInterfaceStore((state) => state.focusedPanel)
const fontSize = useUserInterfaceStore((state) => state.fontSize)
const toggleShortcutsDialog = useUserInterfaceStore(
(state) => state.toggleShortcutsDialog
)
const detailLayout = useDefaultLayout({
id: "asa-detail-layout",
panelIds: ["entry-list", "detail-panel"],
storage: typeof window !== "undefined" ? localStorage : { getItem: () => null, setItem: () => {} },
})
const detailGroupRef = useGroupRef()
const detailOnLayoutChangedRef = useRef(detailLayout.onLayoutChanged)
detailOnLayoutChangedRef.current = detailLayout.onLayoutChanged
useEffect(() => {
useUserInterfaceStore.getState().setResetDetailLayout(() => {
const group = detailGroupRef.current
if (!group) return
const appliedLayout = group.setLayout({
"entry-list": 50,
"detail-panel": 50,
})
detailOnLayoutChangedRef.current?.(appliedLayout)
})
return () => useUserInterfaceStore.getState().setResetDetailLayout(null)
}, [detailGroupRef])
useRealtimeEntries()
let pageTitle = feedFilter === "saved" ? "saved" : "all entries"
if (feedFilter === "all" && customFeedIdentifier && customFeedsData) {
const matchingCustomFeed = customFeedsData.find(
(customFeed) => customFeed.identifier === customFeedIdentifier
)
if (matchingCustomFeed) {
pageTitle = matchingCustomFeed.name
}
}
if (feedFilter === "all" && feedIdentifier && subscriptionsData) {
const matchingSubscription = subscriptionsData.subscriptions.find(
(subscription) => subscription.feedIdentifier === feedIdentifier
)
if (matchingSubscription) {
pageTitle =
matchingSubscription.customTitle ||
matchingSubscription.feedTitle ||
"feed"
}
}
if (feedFilter === "all" && folderIdentifier && subscriptionsData) {
const matchingFolder = subscriptionsData.folders.find(
(folder) => folder.folderIdentifier === folderIdentifier
)
if (matchingFolder) {
pageTitle = matchingFolder.name
}
}
const totalUnreadCount = Object.values(unreadCounts ?? {}).reduce(
(sum, count) => sum + count,
0
)
const allAreRead = totalUnreadCount === 0
return (
<div className={classNames(
"flex h-full flex-col",
fontSize === "small" ? "text-sm" : fontSize === "large" ? "text-lg" : "text-base"
)}>
<header className="flex items-center justify-between border-b border-border px-4 py-3">
{isMobile && selectedEntryIdentifier ? (
<button
type="button"
onClick={() => setSelectedEntryIdentifier(null)}
className="text-text-secondary transition-colors hover:text-text-primary"
>
← back
</button>
) : (
<h1 className="text-text-primary">{pageTitle}</h1>
)}
<div className="flex items-center gap-3">
{!(isMobile && selectedEntryIdentifier) && (
<>
<button
type="button"
onClick={() => setSearchOpen(true)}
className="text-text-dim transition-colors hover:text-text-secondary"
>
search
</button>
{feedFilter === "all" && (
<button
type="button"
onClick={() =>
markAllAsRead.mutate({ readState: !allAreRead })
}
disabled={markAllAsRead.isPending}
className="text-text-dim transition-colors hover:text-text-secondary disabled:opacity-50"
>
{allAreRead ? "mark all unread" : "mark all read"}
</button>
)}
<select
value={entryListViewMode}
onChange={(event) =>
setEntryListViewMode(
event.target.value as "compact" | "comfortable" | "expanded"
)
}
className="hidden border border-border bg-background-primary px-2 py-1 text-text-secondary outline-none sm:block"
>
<option value="compact">compact</option>
<option value="comfortable">comfortable</option>
<option value="expanded">expanded</option>
</select>
<button
type="button"
onClick={() => toggleShortcutsDialog()}
className="hidden text-text-dim transition-colors hover:text-text-secondary sm:block"
>
shortcuts
</button>
</>
)}
</div>
</header>
<ErrorBoundary>
{isMobile ? (
selectedEntryIdentifier ? (
<div className="flex-1 overflow-hidden">
<ErrorBoundary>
<EntryDetailPanel
entryIdentifier={selectedEntryIdentifier}
/>
</ErrorBoundary>
</div>
) : (
<div className="flex-1 overflow-hidden">
<ErrorBoundary>
<EntryList
feedFilter={feedFilter}
folderIdentifier={folderIdentifier}
feedIdentifier={feedIdentifier}
customFeedIdentifier={customFeedIdentifier}
/>
</ErrorBoundary>
</div>
)
) : (
<Group
orientation="horizontal"
className="min-h-0 flex-1"
defaultLayout={detailLayout.defaultLayout}
onLayoutChanged={detailLayout.onLayoutChanged}
groupRef={detailGroupRef}
>
<Panel id="entry-list" defaultSize={selectedEntryIdentifier ? "40%" : "100%"} minSize="25%">
<div data-panel-zone="entryList" className={classNames(
"h-full",
focusedPanel === "entryList" ? "border-t-2 border-t-text-dim" : "border-t-2 border-t-transparent"
)}>
<ErrorBoundary>
<EntryList
feedFilter={feedFilter}
folderIdentifier={folderIdentifier}
feedIdentifier={feedIdentifier}
customFeedIdentifier={customFeedIdentifier}
/>
</ErrorBoundary>
</div>
</Panel>
{selectedEntryIdentifier && (
<>
<Separator className="w-px bg-border transition-colors hover:bg-text-dim" />
<Panel id="detail-panel" defaultSize="60%" minSize="30%">
<div data-panel-zone="detailPanel" className={classNames(
"h-full overflow-hidden",
focusedPanel === "detailPanel" ? "border-t-2 border-t-text-dim" : "border-t-2 border-t-transparent"
)}>
<ErrorBoundary>
<EntryDetailPanel
entryIdentifier={selectedEntryIdentifier}
/>
</ErrorBoundary>
</div>
</Panel>
</>
)}
</Group>
)}
</ErrorBoundary>
</div>
)
}
|