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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
|
"use client"
import { useState, useMemo } from "react"
import Link from "next/link"
import { usePathname, useSearchParams } from "next/navigation"
import {
DndContext,
DragOverlay,
PointerSensor,
useSensor,
useSensors,
closestCenter,
type DragStartEvent,
type DragEndEvent,
} from "@dnd-kit/core"
import {
SortableContext,
useSortable,
verticalListSortingStrategy,
} from "@dnd-kit/sortable"
import { CSS } from "@dnd-kit/utilities"
import { useSubscriptions } from "@/lib/queries/use-subscriptions"
import { useUnreadCounts } from "@/lib/queries/use-unread-counts"
import { useCustomFeeds } from "@/lib/queries/use-custom-feeds"
import { useMoveSubscriptionToFolder } from "@/lib/queries/use-subscription-mutations"
import {
useReorderSubscriptions,
useReorderFolders,
useReorderCustomFeeds,
} from "@/lib/queries/use-reorder-mutations"
import { computeReorderPositions } from "@/lib/reorder-positions"
import { useUserInterfaceStore } from "@/lib/stores/user-interface-store"
import { classNames } from "@/lib/utilities"
import type { Subscription, Folder } from "@/lib/types/subscription"
import type { CustomFeed } from "@/lib/types/custom-feed"
const NAVIGATION_LINK_CLASS =
"block whitespace-nowrap px-2 py-1 text-text-secondary transition-colors hover:bg-background-tertiary hover:text-text-primary"
const ACTIVE_LINK_CLASS = "bg-background-tertiary text-text-primary"
function getFaviconUrl(feedUrl: string): string | null {
try {
const hostname = new URL(feedUrl).hostname
return `https://www.google.com/s2/favicons?domain=${hostname}&sz=16`
} catch {
return null
}
}
function FeedFavicon({ feedUrl }: { feedUrl: string }) {
const faviconUrl = getFaviconUrl(feedUrl)
if (!faviconUrl) return null
return (
<img
src={faviconUrl}
alt=""
width={16}
height={16}
className="shrink-0"
loading="lazy"
/>
)
}
function displayNameForSubscription(subscription: {
customTitle: string | null
feedTitle: string
feedUrl: string
}): string {
if (subscription.customTitle) return subscription.customTitle
if (subscription.feedTitle) return subscription.feedTitle
try {
return new URL(subscription.feedUrl).hostname
} catch {
return subscription.feedUrl || "untitled feed"
}
}
function UnreadBadge({ count }: { count: number }) {
if (count === 0) return null
return (
<span className="ml-auto shrink-0 text-[0.625rem] tabular-nums text-text-dim">
{count > 999 ? "999+" : count}
</span>
)
}
function sidebarFocusClass(
focusedPanel: string,
focusedSidebarIndex: number,
navigationIndex: number
): string {
return focusedPanel === "sidebar" && focusedSidebarIndex === navigationIndex
? "bg-background-tertiary text-text-primary"
: ""
}
function SortableFeedItem({
subscription,
activeFeedIdentifier,
showFeedFavicons,
unreadCount,
focusedPanel,
focusedSidebarIndex,
navigationIndex,
indentClass,
closeSidebarOnMobile,
}: {
subscription: Subscription
activeFeedIdentifier: string | null
showFeedFavicons: boolean
unreadCount: number
focusedPanel: string
focusedSidebarIndex: number
navigationIndex: number
indentClass: string
closeSidebarOnMobile: () => void
}) {
const {
attributes,
listeners,
setNodeRef,
transform,
transition,
isDragging,
} = useSortable({ id: subscription.subscriptionIdentifier })
const style = {
transform: CSS.Transform.toString(transform),
transition,
opacity: isDragging ? 0.4 : undefined,
}
return (
<Link
ref={setNodeRef}
style={style}
{...attributes}
{...listeners}
href={`/reader?feed=${subscription.feedIdentifier}`}
data-sidebar-nav-item
{...(unreadCount > 0 ? { "data-has-unreads": "" } : {})}
onClick={closeSidebarOnMobile}
className={classNames(
NAVIGATION_LINK_CLASS,
`flex items-center truncate ${indentClass} text-[0.85em]`,
activeFeedIdentifier === subscription.feedIdentifier && ACTIVE_LINK_CLASS,
subscription.hiddenFromTimeline && "opacity-50",
sidebarFocusClass(focusedPanel, focusedSidebarIndex, navigationIndex)
)}
>
{showFeedFavicons && <FeedFavicon feedUrl={subscription.feedUrl} />}
<span
className={classNames("truncate", showFeedFavicons && "ml-2")}
>
{displayNameForSubscription(subscription)}
</span>
{subscription.feedVisibility === "authenticated" && (
<span
className="ml-1 shrink-0 text-text-dim"
title="authenticated feed"
>
🔒
</span>
)}
{subscription.feedType === "podcast" && (
<span className="ml-1 shrink-0 text-text-dim" title="podcast">
♫
</span>
)}
{subscription.consecutiveFailures > 0 && (
<span
className="ml-1 shrink-0 text-status-warning"
title={subscription.lastFetchError ?? "feed error"}
>
[!]
</span>
)}
<UnreadBadge count={unreadCount} />
</Link>
)
}
function SortableFolderItem({
folder,
isExpanded,
folderSubscriptions,
folderUnreadCount,
activeFeedIdentifier,
activeFolderIdentifier,
showFeedFavicons,
unreadCounts,
focusedPanel,
focusedSidebarIndex,
folderNavigationIndex,
feedNavigationIndexStart,
toggleFolderExpansion,
closeSidebarOnMobile,
}: {
folder: Folder
isExpanded: boolean
folderSubscriptions: Subscription[]
folderUnreadCount: number
activeFeedIdentifier: string | null
activeFolderIdentifier: string | null
showFeedFavicons: boolean
unreadCounts: Record<string, number> | undefined
focusedPanel: string
focusedSidebarIndex: number
folderNavigationIndex: number
feedNavigationIndexStart: number
toggleFolderExpansion: (identifier: string) => void
closeSidebarOnMobile: () => void
}) {
const {
attributes,
listeners,
setNodeRef,
transform,
transition,
isDragging,
} = useSortable({ id: folder.folderIdentifier })
const style = {
transform: CSS.Transform.toString(transform),
transition,
opacity: isDragging ? 0.4 : undefined,
}
const feedIdentifiers = useMemo(
() => folderSubscriptions.map((subscription) => subscription.subscriptionIdentifier),
[folderSubscriptions]
)
return (
<div
ref={setNodeRef}
style={style}
className="mt-2"
>
<div
data-sidebar-nav-item
{...(folderUnreadCount > 0 ? { "data-has-unreads": "" } : {})}
{...attributes}
{...listeners}
className={classNames(
"flex w-full items-center gap-1 px-2 py-1",
sidebarFocusClass(
focusedPanel,
focusedSidebarIndex,
folderNavigationIndex
)
)}
>
<button
type="button"
aria-expanded={isExpanded}
onClick={(event) => {
event.stopPropagation()
toggleFolderExpansion(folder.folderIdentifier)
}}
className="shrink-0 px-0.5 text-text-secondary transition-colors hover:text-text-primary"
>
{isExpanded ? "\u25BE" : "\u25B8"}
</button>
<Link
href={`/reader?folder=${folder.folderIdentifier}`}
onClick={closeSidebarOnMobile}
className={classNames(
"flex flex-1 items-center gap-2 truncate text-text-secondary transition-colors hover:text-text-primary",
activeFolderIdentifier === folder.folderIdentifier &&
"text-text-primary"
)}
>
{folder.iconUrl && (
<img
src={folder.iconUrl}
alt=""
width={16}
height={16}
className="shrink-0"
loading="lazy"
/>
)}
<span className="truncate">{folder.name}</span>
</Link>
<UnreadBadge count={folderUnreadCount} />
</div>
{isExpanded && (
<SortableContext
items={feedIdentifiers}
strategy={verticalListSortingStrategy}
>
<div className="space-y-0.5">
{folderSubscriptions.map((subscription, subscriptionIndex) => (
<SortableFeedItem
key={subscription.subscriptionIdentifier}
subscription={subscription}
activeFeedIdentifier={activeFeedIdentifier}
showFeedFavicons={showFeedFavicons}
unreadCount={
unreadCounts?.[subscription.feedIdentifier] ?? 0
}
focusedPanel={focusedPanel}
focusedSidebarIndex={focusedSidebarIndex}
navigationIndex={feedNavigationIndexStart + subscriptionIndex}
indentClass="pl-6"
closeSidebarOnMobile={closeSidebarOnMobile}
/>
))}
</div>
</SortableContext>
)}
</div>
)
}
function SortableCustomFeedItem({
customFeed,
activeCustomFeedIdentifier,
focusedPanel,
focusedSidebarIndex,
navigationIndex,
closeSidebarOnMobile,
}: {
customFeed: CustomFeed
activeCustomFeedIdentifier: string | null
focusedPanel: string
focusedSidebarIndex: number
navigationIndex: number
closeSidebarOnMobile: () => void
}) {
const {
attributes,
listeners,
setNodeRef,
transform,
transition,
isDragging,
} = useSortable({ id: customFeed.identifier })
const style = {
transform: CSS.Transform.toString(transform),
transition,
opacity: isDragging ? 0.4 : undefined,
}
return (
<Link
ref={setNodeRef}
style={style}
{...attributes}
{...listeners}
href={`/reader?custom_feed=${customFeed.identifier}`}
data-sidebar-nav-item
onClick={closeSidebarOnMobile}
className={classNames(
NAVIGATION_LINK_CLASS,
"flex items-center gap-2 truncate pl-4 text-[0.85em]",
activeCustomFeedIdentifier === customFeed.identifier &&
ACTIVE_LINK_CLASS,
sidebarFocusClass(focusedPanel, focusedSidebarIndex, navigationIndex)
)}
>
{customFeed.iconUrl && (
<img
src={customFeed.iconUrl}
alt=""
width={16}
height={16}
className="shrink-0"
loading="lazy"
/>
)}
<span className="truncate">{customFeed.name}</span>
</Link>
)
}
function FeedDragOverlay({
subscription,
showFeedFavicons,
}: {
subscription: Subscription
showFeedFavicons: boolean
}) {
return (
<div
className={classNames(
NAVIGATION_LINK_CLASS,
"flex items-center truncate text-[0.85em] bg-background-secondary shadow-lg outline outline-1 outline-border"
)}
>
{showFeedFavicons && <FeedFavicon feedUrl={subscription.feedUrl} />}
<span className={classNames("truncate", showFeedFavicons && "ml-2")}>
{displayNameForSubscription(subscription)}
</span>
</div>
)
}
function FolderDragOverlay({ folder }: { folder: Folder }) {
return (
<div className="flex items-center gap-1 px-2 py-1 bg-background-secondary shadow-lg outline outline-1 outline-border">
<span className="shrink-0 px-0.5 text-text-secondary">{"\u25B8"}</span>
<span className="truncate text-text-secondary">{folder.name}</span>
</div>
)
}
function CustomFeedDragOverlay({ customFeed }: { customFeed: CustomFeed }) {
return (
<div
className={classNames(
NAVIGATION_LINK_CLASS,
"flex items-center gap-2 truncate text-[0.85em] bg-background-secondary shadow-lg outline outline-1 outline-border"
)}
>
{customFeed.iconUrl && (
<img
src={customFeed.iconUrl}
alt=""
width={16}
height={16}
className="shrink-0"
loading="lazy"
/>
)}
<span className="truncate">{customFeed.name}</span>
</div>
)
}
type DragItemType = "feed" | "folder" | "customFeed"
export function SidebarContent() {
const pathname = usePathname()
const searchParameters = useSearchParams()
const { data } = useSubscriptions()
const { data: unreadCounts } = useUnreadCounts()
const { data: customFeedsData } = useCustomFeeds()
const setAddFeedDialogOpen = useUserInterfaceStore(
(state) => state.setAddFeedDialogOpen
)
const toggleSidebar = useUserInterfaceStore((state) => state.toggleSidebar)
const showFeedFavicons = useUserInterfaceStore(
(state) => state.showFeedFavicons
)
const expandedFolderIdentifiers = useUserInterfaceStore(
(state) => state.expandedFolderIdentifiers
)
const toggleFolderExpansion = useUserInterfaceStore(
(state) => state.toggleFolderExpansion
)
const focusedPanel = useUserInterfaceStore((state) => state.focusedPanel)
const focusedSidebarIndex = useUserInterfaceStore(
(state) => state.focusedSidebarIndex
)
const showFoldersAboveFeeds = useUserInterfaceStore(
(state) => state.showFoldersAboveFeeds
)
const moveToFolder = useMoveSubscriptionToFolder()
const reorderSubscriptions = useReorderSubscriptions()
const reorderFolders = useReorderFolders()
const reorderCustomFeeds = useReorderCustomFeeds()
const [activeDragIdentifier, setActiveDragIdentifier] = useState<string | null>(null)
const [activeDragType, setActiveDragType] = useState<DragItemType | null>(
null
)
const sensors = useSensors(
useSensor(PointerSensor, {
activationConstraint: { distance: 5 },
})
)
function closeSidebarOnMobile() {
if (typeof window !== "undefined" && window.innerWidth < 768) {
toggleSidebar()
}
}
const folders = data?.folders ?? []
const subscriptions = data?.subscriptions ?? []
const customFeeds = customFeedsData ?? []
const ungroupedSubscriptions = subscriptions.filter(
(subscription) => !subscription.folderIdentifier
)
const totalUnreadCount = subscriptions
.filter((subscription) => !subscription.hiddenFromTimeline)
.reduce(
(sum, subscription) =>
sum + (unreadCounts?.[subscription.feedIdentifier] ?? 0),
0
)
function getFolderUnreadCount(folderIdentifier: string): number {
return subscriptions
.filter(
(subscription) =>
subscription.folderIdentifier === folderIdentifier &&
!subscription.hiddenFromTimeline
)
.reduce(
(sum, subscription) =>
sum + (unreadCounts?.[subscription.feedIdentifier] ?? 0),
0
)
}
const activeFeedIdentifier = searchParameters.get("feed")
const activeFolderIdentifier = searchParameters.get("folder")
const activeCustomFeedIdentifier = searchParameters.get("custom_feed")
const subscriptionMap = useMemo(
() =>
new Map(subscriptions.map((subscription) => [subscription.subscriptionIdentifier, subscription])),
[subscriptions]
)
const folderMap = useMemo(
() => new Map(folders.map((folder) => [folder.folderIdentifier, folder])),
[folders]
)
const customFeedMap = useMemo(
() => new Map(customFeeds.map((customFeed) => [customFeed.identifier, customFeed])),
[customFeeds]
)
const folderIdentifiers = useMemo(
() => folders.map((folder) => folder.folderIdentifier),
[folders]
)
const ungroupedFeedIdentifiers = useMemo(
() => ungroupedSubscriptions.map((subscription) => subscription.subscriptionIdentifier),
[ungroupedSubscriptions]
)
const customFeedIdentifiers = useMemo(
() => customFeeds.map((customFeed) => customFeed.identifier),
[customFeeds]
)
function identifyDragType(identifier: string): DragItemType | null {
if (subscriptionMap.has(identifier)) return "feed"
if (folderMap.has(identifier)) return "folder"
if (customFeedMap.has(identifier)) return "customFeed"
return null
}
function handleDragStart(event: DragStartEvent) {
const identifier = String(event.active.id)
setActiveDragIdentifier(identifier)
setActiveDragType(identifyDragType(identifier))
}
function handleDragEnd(event: DragEndEvent) {
setActiveDragIdentifier(null)
setActiveDragType(null)
const { active, over } = event
if (!over || active.id === over.id) return
const activeIdentifier = String(active.id)
const overIdentifier = String(over.id)
const dragType = identifyDragType(activeIdentifier)
if (dragType === "folder") {
const items = folders.map((folder) => ({
identifier: folder.folderIdentifier,
position: folder.position,
}))
const result = computeReorderPositions(items, activeIdentifier, overIdentifier)
if (result) reorderFolders.mutate(result)
return
}
if (dragType === "customFeed") {
const items = customFeeds.map((customFeed) => ({
identifier: customFeed.identifier,
position: customFeed.position,
}))
const result = computeReorderPositions(items, activeIdentifier, overIdentifier)
if (result) reorderCustomFeeds.mutate(result)
return
}
if (dragType === "feed") {
const activeSubscription = subscriptionMap.get(activeIdentifier)
const overSubscription = subscriptionMap.get(overIdentifier)
if (!activeSubscription) return
if (overSubscription) {
if (activeSubscription.folderIdentifier === overSubscription.folderIdentifier) {
const containerSubscriptions = subscriptions
.filter(
(subscription) => subscription.folderIdentifier === activeSubscription.folderIdentifier
)
.map((subscription) => ({
identifier: subscription.subscriptionIdentifier,
position: subscription.position,
}))
const result = computeReorderPositions(
containerSubscriptions,
activeIdentifier,
overIdentifier
)
if (result) reorderSubscriptions.mutate(result)
} else {
const targetFolderIdentifier = overSubscription.folderIdentifier
const targetFolderName = targetFolderIdentifier
? folderMap.get(targetFolderIdentifier)?.name
: undefined
moveToFolder.mutate({
subscriptionIdentifier: activeIdentifier,
folderIdentifier: targetFolderIdentifier,
feedTitle:
activeSubscription.customTitle ?? activeSubscription.feedTitle ?? undefined,
folderName: targetFolderName,
})
}
}
}
}
function handleDragCancel() {
setActiveDragIdentifier(null)
setActiveDragType(null)
}
function renderDragOverlay() {
if (!activeDragIdentifier || !activeDragType) return null
if (activeDragType === "feed") {
const subscription = subscriptionMap.get(activeDragIdentifier)
if (!subscription) return null
return (
<FeedDragOverlay
subscription={subscription}
showFeedFavicons={showFeedFavicons}
/>
)
}
if (activeDragType === "folder") {
const folder = folderMap.get(activeDragIdentifier)
if (!folder) return null
return <FolderDragOverlay folder={folder} />
}
if (activeDragType === "customFeed") {
const customFeed = customFeedMap.get(activeDragIdentifier)
if (!customFeed) return null
return <CustomFeedDragOverlay customFeed={customFeed} />
}
return null
}
const folderData = folders.map((folder) => {
const isExpanded = expandedFolderIdentifiers.includes(
folder.folderIdentifier
)
const folderSubscriptions = subscriptions.filter(
(subscription) =>
subscription.folderIdentifier === folder.folderIdentifier
)
const folderUnreadCount = getFolderUnreadCount(folder.folderIdentifier)
return {
folder,
isExpanded,
folderSubscriptions,
folderUnreadCount,
}
})
let navigationIndex = 0
const staticNavigationStart = navigationIndex
navigationIndex += 4
const customFeedNavigationStart = navigationIndex
navigationIndex += customFeeds.length
const sections = showFoldersAboveFeeds
? (["folders", "ungrouped"] as const)
: (["ungrouped", "folders"] as const)
const folderNavigationIndices: { folderNavigationIndex: number; feedNavigationIndexStart: number }[] = []
let ungroupedNavigationStart = 0
for (const section of sections) {
if (section === "folders") {
for (const folderDatum of folderData) {
folderNavigationIndices.push({
folderNavigationIndex: navigationIndex++,
feedNavigationIndexStart: navigationIndex,
})
if (folderDatum.isExpanded) navigationIndex += folderDatum.folderSubscriptions.length
}
} else {
ungroupedNavigationStart = navigationIndex
navigationIndex += ungroupedSubscriptions.length
}
}
const addFeedNavigationIndex = navigationIndex
return (
<DndContext
sensors={sensors}
collisionDetection={closestCenter}
onDragStart={handleDragStart}
onDragEnd={handleDragEnd}
onDragCancel={handleDragCancel}
>
<nav data-sidebar-nav className="flex-1 space-y-1 overflow-auto px-2">
<Link
href="/reader"
data-sidebar-nav-item
{...(totalUnreadCount > 0 ? { "data-has-unreads": "" } : {})}
onClick={closeSidebarOnMobile}
className={classNames(
NAVIGATION_LINK_CLASS,
"flex items-center",
pathname === "/reader" &&
!activeFeedIdentifier &&
!activeFolderIdentifier &&
!activeCustomFeedIdentifier &&
ACTIVE_LINK_CLASS,
sidebarFocusClass(focusedPanel, focusedSidebarIndex, staticNavigationStart)
)}
>
<span>all entries</span>
<UnreadBadge count={totalUnreadCount} />
</Link>
<Link
href="/reader/saved"
data-sidebar-nav-item
onClick={closeSidebarOnMobile}
className={classNames(
NAVIGATION_LINK_CLASS,
pathname === "/reader/saved" && ACTIVE_LINK_CLASS,
sidebarFocusClass(focusedPanel, focusedSidebarIndex, staticNavigationStart + 1)
)}
>
saved
</Link>
<Link
href="/reader/highlights"
data-sidebar-nav-item
onClick={closeSidebarOnMobile}
className={classNames(
NAVIGATION_LINK_CLASS,
pathname === "/reader/highlights" && ACTIVE_LINK_CLASS,
sidebarFocusClass(focusedPanel, focusedSidebarIndex, staticNavigationStart + 2)
)}
>
highlights
</Link>
<Link
href="/reader/shares"
data-sidebar-nav-item
onClick={closeSidebarOnMobile}
className={classNames(
NAVIGATION_LINK_CLASS,
pathname === "/reader/shares" && ACTIVE_LINK_CLASS,
sidebarFocusClass(focusedPanel, focusedSidebarIndex, staticNavigationStart + 3)
)}
>
shares
</Link>
{customFeeds.length > 0 && (
<SortableContext
items={customFeedIdentifiers}
strategy={verticalListSortingStrategy}
>
<div className="mt-3 space-y-0.5">
{customFeeds.map((customFeed, customFeedIndex) => (
<SortableCustomFeedItem
key={customFeed.identifier}
customFeed={customFeed}
activeCustomFeedIdentifier={activeCustomFeedIdentifier}
focusedPanel={focusedPanel}
focusedSidebarIndex={focusedSidebarIndex}
navigationIndex={customFeedNavigationStart + customFeedIndex}
closeSidebarOnMobile={closeSidebarOnMobile}
/>
))}
</div>
</SortableContext>
)}
{sections.map((section) =>
section === "folders" ? (
<SortableContext
key="folders"
items={folderIdentifiers}
strategy={verticalListSortingStrategy}
>
{folderData.map((folderDatum, folderIndex) => (
<SortableFolderItem
key={folderDatum.folder.folderIdentifier}
folder={folderDatum.folder}
isExpanded={folderDatum.isExpanded}
folderSubscriptions={folderDatum.folderSubscriptions}
folderUnreadCount={folderDatum.folderUnreadCount}
activeFeedIdentifier={activeFeedIdentifier}
activeFolderIdentifier={activeFolderIdentifier}
showFeedFavicons={showFeedFavicons}
unreadCounts={unreadCounts}
focusedPanel={focusedPanel}
focusedSidebarIndex={focusedSidebarIndex}
folderNavigationIndex={folderNavigationIndices[folderIndex].folderNavigationIndex}
feedNavigationIndexStart={folderNavigationIndices[folderIndex].feedNavigationIndexStart}
toggleFolderExpansion={toggleFolderExpansion}
closeSidebarOnMobile={closeSidebarOnMobile}
/>
))}
</SortableContext>
) : (
<SortableContext
key="ungrouped"
items={ungroupedFeedIdentifiers}
strategy={verticalListSortingStrategy}
>
<div className="mt-3 space-y-0.5">
{ungroupedSubscriptions.map((subscription, subscriptionIndex) => (
<SortableFeedItem
key={subscription.subscriptionIdentifier}
subscription={subscription}
activeFeedIdentifier={activeFeedIdentifier}
showFeedFavicons={showFeedFavicons}
unreadCount={
unreadCounts?.[subscription.feedIdentifier] ?? 0
}
focusedPanel={focusedPanel}
focusedSidebarIndex={focusedSidebarIndex}
navigationIndex={ungroupedNavigationStart + subscriptionIndex}
indentClass="pl-4"
closeSidebarOnMobile={closeSidebarOnMobile}
/>
))}
</div>
</SortableContext>
)
)}
<div className="mt-3 space-y-0.5">
<button
type="button"
data-sidebar-nav-item
onClick={() => setAddFeedDialogOpen(true)}
className={classNames(
"w-full px-2 py-1 text-left text-text-dim transition-colors hover:bg-background-tertiary hover:text-text-secondary",
sidebarFocusClass(
focusedPanel,
focusedSidebarIndex,
addFeedNavigationIndex
)
)}
>
+ add feed
</button>
</div>
</nav>
<DragOverlay dropAnimation={null}>{renderDragOverlay()}</DragOverlay>
</DndContext>
)
}
|