Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add show unread notifications filter button #6356

Merged
merged 4 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 42 additions & 22 deletions src/Components/Notifications/NotificationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export default function NotificationsList({
const [isMarkingAllAsRead, setIsMarkingAllAsRead] = useState(false);
const [isSubscribed, setIsSubscribed] = useState("");
const [isSubscribing, setIsSubscribing] = useState(false);
const [showUnread, setShowUnread] = useState(false);
const { t } = useTranslation();

useEffect(() => {
Expand Down Expand Up @@ -351,33 +352,37 @@ export default function NotificationsList({
} else if (data?.length) {
manageResults = (
<>
{data.map((result: any) => (
<NotificationTile
key={result.id}
notification={result}
onClickCB={onClickCB}
setShowNotifications={setOpen}
/>
))}
{data
.filter((notification: any) => showUnread ? notification.read_at === null : true)
.map((result: any) => (
<NotificationTile
key={result.id}
notification={result}
onClickCB={onClickCB}
setShowNotifications={setOpen}
/>
))}
{isLoading && (
<div className="flex items-center justify-center">
<CircularProgress />
</div>
)}
{totalCount > RESULT_LIMIT && offset < totalCount - RESULT_LIMIT && (
<div className="mt-4 flex w-full justify-center px-4 py-5 lg:px-8">
<ButtonV2
className="w-full"
disabled={isLoading}
variant="secondary"
shadow
border
onClick={() => setOffset((prev) => prev + RESULT_LIMIT)}
>
{isLoading ? t("loading") : t("load_more")}
</ButtonV2>
</div>
)}
{!showUnread &&
totalCount > RESULT_LIMIT &&
offset < totalCount - RESULT_LIMIT && (
<div className="mt-4 flex w-full justify-center px-4 py-5 lg:px-8">
<ButtonV2
className="w-full"
disabled={isLoading}
variant="secondary"
shadow
border
onClick={() => setOffset((prev) => prev + RESULT_LIMIT)}
>
{isLoading ? t("loading") : t("load_more")}
</ButtonV2>
</div>
)}
</>
);
} else if (data && data.length === 0) {
Expand Down Expand Up @@ -448,6 +453,21 @@ export default function NotificationsList({
/>
<span className="text-xs">{t("mark_all_as_read")}</span>
</ButtonV2>
<ButtonV2
ghost
variant="secondary"
onClick={() => setShowUnread(!showUnread)}
>
<CareIcon
className={showUnread ? "care-l-filter-slash" : "care-l-filter"}
/>

<span className="text-xs">
{showUnread
? t("show_all_notifications")
: t("show_unread_notifications")}
</span>
</ButtonV2>
</div>

<SelectMenuV2
Expand Down
2 changes: 2 additions & 0 deletions src/Locale/en/Notifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"mark_as_read": "Mark as Read",
"subscribe": "Subscribe",
"subscribe_on_this_device": "Subscribe on this device",
"show_unread_notifications": "Show Unread",
"show_all_notifications": "Show All",
"filter_by_category": "Filter by category",
"mark_all_as_read": "Mark all as Read",
"reload": "Reload",
Expand Down
Loading