-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
212 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/components/contentDisplay/notification/NotificationSkeleton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/containers/notifications/FilteredNotificationsContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
"use client"; | ||
|
||
import NotificationItem from "@/components/contentDisplay/notification/NotificationItem"; | ||
import NotificationSkeleton from "@/components/contentDisplay/notification/NotificationSkeleton"; | ||
import EndOfFeed from "@/components/feedback/endOfFeed/EndOfFeed"; | ||
import FeedAlert from "@/components/feedback/feedAlert/FeedAlert"; | ||
import LoadingSpinner from "@/components/status/loadingSpinner/LoadingSpinner"; | ||
import usePreferences from "@/lib/hooks/bsky/actor/usePreferences"; | ||
import useNotification from "@/lib/hooks/bsky/notification/useNotification"; | ||
import { Fragment, useEffect, useState } from "react"; | ||
import InfiniteScroll from "react-infinite-scroll-component"; | ||
|
||
interface Props { | ||
filter: NotificationReason | "all"; | ||
} | ||
|
||
export default function FilteredNotificationsContainer(props: Props) { | ||
const { filter } = props; | ||
const [isFetchingMore, setIsFetchingMore] = useState(false); | ||
const { | ||
notificationStatus, | ||
notificationData, | ||
notificationError, | ||
isLoadingNotification, | ||
isFetchingNotification, | ||
fetchNotificationNextPage, | ||
isFetchingNotificationNextPage, | ||
notificationHasNextPage, | ||
} = useNotification({ notificationType: filter }); | ||
|
||
// load next page if there are no filtered notifications on the current page | ||
useEffect(() => { | ||
if ( | ||
notificationData && | ||
notificationData.pages | ||
.flatMap((page) => page?.data.notifications) | ||
.filter((item) => (filter === "all" ? true : item.reason === filter)) | ||
.length < 10 && | ||
notificationHasNextPage | ||
) { | ||
fetchNotificationNextPage(); | ||
setIsFetchingMore(true); | ||
} else { | ||
setIsFetchingMore(false); | ||
} | ||
}, [ | ||
fetchNotificationNextPage, | ||
filter, | ||
notificationData, | ||
notificationHasNextPage, | ||
]); | ||
|
||
const { preferences } = usePreferences(); | ||
const contentFilter = preferences?.contentFilter; | ||
|
||
const dataLength = notificationData?.pages.reduce( | ||
(acc, page) => acc + (page?.data.notifications.length ?? 0), | ||
0, | ||
); | ||
|
||
const isEmpty = | ||
!isFetchingNotification && | ||
!isFetchingNotificationNextPage && | ||
notificationData && | ||
notificationData.pages | ||
.flatMap((page) => page?.data.notifications) | ||
.filter((item) => (filter === "all" ? true : item.reason === filter)) | ||
.length === 0; | ||
|
||
return ( | ||
<section> | ||
<InfiniteScroll | ||
dataLength={dataLength ?? 0} | ||
next={fetchNotificationNextPage} | ||
hasMore={notificationHasNextPage} | ||
loader={!isFetchingMore && <LoadingSpinner />} | ||
scrollThreshold={0.95} | ||
className="no-scrollbar flex flex-col" | ||
> | ||
{notificationData && | ||
contentFilter && | ||
notificationData.pages | ||
.flatMap((page) => page?.data.notifications) | ||
.filter((item) => | ||
filter === "all" ? true : item.reason === filter, | ||
) | ||
.map((notification, i) => ( | ||
<Fragment key={i}> | ||
{notification && ( | ||
<NotificationItem | ||
key={notification.uri + i} | ||
notification={notification} | ||
filter={contentFilter} | ||
/> | ||
)} | ||
</Fragment> | ||
))} | ||
</InfiniteScroll> | ||
|
||
{isFetchingNotification && !isFetchingNotificationNextPage && ( | ||
<NotificationSkeleton /> | ||
)} | ||
{notificationError && ( | ||
<div className="border-t"> | ||
<FeedAlert variant="badResponse" message="Something went wrong" /> | ||
</div> | ||
)} | ||
{isFetchingMore && <LoadingSpinner />} | ||
{isEmpty && !notificationHasNextPage && !isFetchingMore && ( | ||
<div className="border-t"> | ||
<FeedAlert | ||
variant="empty" | ||
message="There are no notifications to show... yet" | ||
/> | ||
</div> | ||
)} | ||
{!isEmpty && | ||
!notificationError && | ||
!isFetchingNotification && | ||
!notificationHasNextPage && | ||
!isFetchingNotificationNextPage && <EndOfFeed />} | ||
</section> | ||
); | ||
} |
104 changes: 28 additions & 76 deletions
104
src/containers/notifications/NotificationsContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,41 @@ | ||
"use client"; | ||
|
||
import NotificationItem from "@/components/contentDisplay/notification/NotificationItem"; | ||
import NotificationSkeleton from "@/components/contentDisplay/notification/NotificationSkeleton"; | ||
import EndOfFeed from "@/components/feedback/endOfFeed/EndOfFeed"; | ||
import FeedAlert from "@/components/feedback/feedAlert/FeedAlert"; | ||
import LoadingSpinner from "@/components/status/loadingSpinner/LoadingSpinner"; | ||
import usePreferences from "@/lib/hooks/bsky/actor/usePreferences"; | ||
import useNotification from "@/lib/hooks/bsky/notification/useNotification"; | ||
import { Fragment } from "react"; | ||
import InfiniteScroll from "react-infinite-scroll-component"; | ||
import { useState } from "react"; | ||
import FilteredNotificationsContainer from "./FilteredNotificationsContainer"; | ||
import { NOTIFICATION_FILTER } from "@/lib/consts/notification"; | ||
|
||
export default function NotificationsContainer() { | ||
const { | ||
notificationStatus, | ||
notificationData, | ||
notificationError, | ||
isLoadingNotification, | ||
isFetchingNotification, | ||
fetchNotificationNextPage, | ||
isFetchingNotificationNextPage, | ||
notificationHasNextPage, | ||
} = useNotification(); | ||
|
||
const { preferences } = usePreferences(); | ||
const contentFilter = preferences?.contentFilter; | ||
|
||
const dataLength = notificationData?.pages.reduce( | ||
(acc, page) => acc + (page?.data.notifications.length ?? 0), | ||
0, | ||
const [currentTab, setCurrentTab] = useState<"all" | NotificationReason>( | ||
"all", | ||
); | ||
|
||
const isEmpty = | ||
!isFetchingNotification && | ||
!isFetchingNotificationNextPage && | ||
dataLength === 0; | ||
const handleTabChange = (tab: "all" | NotificationReason) => { | ||
setCurrentTab(tab); | ||
}; | ||
|
||
return ( | ||
<section> | ||
<InfiniteScroll | ||
dataLength={dataLength ?? 0} | ||
next={fetchNotificationNextPage} | ||
hasMore={notificationHasNextPage} | ||
loader={<LoadingSpinner />} | ||
scrollThreshold={0.95} | ||
className="no-scrollbar flex flex-col" | ||
<div | ||
role="tablist" | ||
aria-orientation="horizontal" | ||
className="no-scrollbar mt-5 flex flex-nowrap gap-3 overflow-auto px-3 md:px-0" | ||
> | ||
{notificationData && | ||
contentFilter && | ||
notificationData.pages | ||
.flatMap((page) => page?.data.notifications) | ||
.map((notification, i) => ( | ||
<Fragment key={i}> | ||
{notification && ( | ||
<NotificationItem | ||
key={notification.uri + i} | ||
notification={notification} | ||
filter={contentFilter} | ||
/> | ||
)} | ||
</Fragment> | ||
))} | ||
</InfiniteScroll> | ||
|
||
{isFetchingNotification && !isFetchingNotificationNextPage && ( | ||
<NotificationSkeleton /> | ||
)} | ||
{notificationError && ( | ||
<FeedAlert | ||
variant="badResponse" | ||
message="Something went wrong" | ||
standalone | ||
/> | ||
)} | ||
{isEmpty && !notificationHasNextPage && ( | ||
<FeedAlert | ||
variant="empty" | ||
message="There are no notifications to show... yet" | ||
standalone | ||
/> | ||
)} | ||
{!isEmpty && | ||
!notificationError && | ||
!isFetchingNotification && | ||
!notificationHasNextPage && | ||
!isFetchingNotificationNextPage && <EndOfFeed />} | ||
{NOTIFICATION_FILTER.map((type) => ( | ||
<button | ||
key={type.label} | ||
role="tab" | ||
onClick={() => handleTabChange(type.value)} | ||
className={`border-b-3 hover:text-primary shrink-0 cursor-pointer px-3 pb-2 font-semibold ${ | ||
currentTab === type.value | ||
? "border-primary-600 text-primary border-primary" | ||
: "border-transparent text-neutral-500" | ||
}`} | ||
> | ||
{type.label} | ||
</button> | ||
))} | ||
</div> | ||
<FilteredNotificationsContainer filter={currentTab} /> | ||
</section> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
export const GROUPABLE_NOTIFICATIONS = ["like", "follow", "repost"]; | ||
|
||
export const MAX_AUTHORS_SHOWN = 6; | ||
|
||
export const NOTIFICATION_FILTER: { | ||
label: string; | ||
value: NotificationReason | "all"; | ||
}[] = [ | ||
{ label: "All", value: "all" }, | ||
{ label: "Like", value: "like" }, | ||
{ label: "Follow", value: "follow" }, | ||
{ label: "Repost", value: "repost" }, | ||
{ label: "Quote", value: "quote" }, | ||
{ label: "Reply", value: "reply" }, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.