-
Notifications
You must be signed in to change notification settings - Fork 4
Grouped notification reactions #1864
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
91c1964
Grouped notification reactions
prxt6529 1433e68
WIP
prxt6529 6a5c9d5
WIP
prxt6529 1788c25
WIP
prxt6529 26a8b37
WIP
prxt6529 23178f0
WIP
prxt6529 558fdb0
WIP
prxt6529 877fba2
WIP
prxt6529 0c6fcfa
WIP
prxt6529 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
104 changes: 104 additions & 0 deletions
104
components/brain/notifications/NotificationsFollowAllBtn.tsx
This file contains hidden or 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,104 @@ | ||
| "use client"; | ||
|
|
||
| import { AuthContext } from "@/components/auth/Auth"; | ||
| import CircleLoader from "@/components/distribution-plan-tool/common/CircleLoader"; | ||
| import { ReactQueryWrapperContext } from "@/components/react-query-wrapper/ReactQueryWrapper"; | ||
| import { | ||
| FOLLOW_BTN_BUTTON_CLASSES, | ||
| FOLLOW_BTN_LOADER_SIZES, | ||
| UserFollowBtnSize, | ||
| } from "@/components/user/utils/UserFollowBtn"; | ||
| import type { ApiIdentitySubscriptionActions } from "@/generated/models/ApiIdentitySubscriptionActions"; | ||
| import type { ApiProfileMin } from "@/generated/models/ApiProfileMin"; | ||
| import { commonApiPost } from "@/services/api/common-api"; | ||
| import type { FC } from "react"; | ||
| import { useContext, useState } from "react"; | ||
| import { | ||
| DEFAULT_SUBSCRIPTION_BODY, | ||
| FollowBtnCheckIcon, | ||
| FollowBtnPlusIcon, | ||
| } from "./notificationsFollowShared"; | ||
|
|
||
| interface NotificationsFollowAllBtnProps { | ||
| readonly profiles: readonly ApiProfileMin[]; | ||
| readonly size?: UserFollowBtnSize | undefined; | ||
| } | ||
|
|
||
| const NotificationsFollowAllBtn: FC<NotificationsFollowAllBtnProps> = ({ | ||
| profiles, | ||
| size = UserFollowBtnSize.SMALL, | ||
| }) => { | ||
| const { onIdentityFollowChange } = useContext(ReactQueryWrapperContext); | ||
| const { setToast, requestAuth } = useContext(AuthContext); | ||
| const [mutating, setMutating] = useState(false); | ||
|
|
||
| const toFollow = profiles.filter( | ||
| (p) => p.handle && (p.subscribed_actions?.length ?? 0) === 0 | ||
| ); | ||
| const allFollowed = toFollow.length === 0; | ||
| const label = allFollowed ? "Following All" : "Follow All"; | ||
|
|
||
| const onFollowAll = async (): Promise<void> => { | ||
| if (allFollowed) return; | ||
| setMutating(true); | ||
| const { success } = await requestAuth(); | ||
| if (!success) { | ||
| setMutating(false); | ||
| return; | ||
| } | ||
| try { | ||
| const results = await Promise.allSettled( | ||
| toFollow.map((profile) => | ||
| commonApiPost< | ||
| ApiIdentitySubscriptionActions, | ||
| ApiIdentitySubscriptionActions | ||
| >({ | ||
| endpoint: `identities/${profile.handle}/subscriptions`, | ||
| body: DEFAULT_SUBSCRIPTION_BODY, | ||
| }) | ||
| ) | ||
| ); | ||
| const hasFulfilled = results.some((r) => r.status === "fulfilled"); | ||
| const rejected = results.filter( | ||
| (r): r is PromiseRejectedResult => r.status === "rejected" | ||
| ); | ||
| if (hasFulfilled) onIdentityFollowChange(); | ||
| if (rejected.length > 0) { | ||
| const messages = rejected.map((r) => | ||
| r.reason instanceof Error ? r.reason.message : String(r.reason) | ||
| ); | ||
| setToast({ | ||
| message: messages.join("; "), | ||
| type: "error", | ||
| }); | ||
| } | ||
| } finally { | ||
| setMutating(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="tw-flex tw-items-center tw-gap-x-2"> | ||
| <button | ||
| onClick={onFollowAll} | ||
| disabled={mutating || allFollowed} | ||
| type="button" | ||
| className={`${FOLLOW_BTN_BUTTON_CLASSES[size]} ${ | ||
| allFollowed | ||
| ? "tw-cursor-default tw-bg-iron-800 tw-text-iron-300 tw-ring-iron-800" | ||
| : "tw-cursor-pointer tw-bg-primary-500 tw-text-white tw-ring-primary-500 hover:tw-bg-primary-600 hover:tw-ring-primary-600" | ||
| } tw-flex tw-items-center tw-rounded-lg tw-border-0 tw-font-semibold tw-ring-1 tw-ring-inset tw-transition tw-duration-300 tw-ease-out disabled:tw-opacity-70`} | ||
| > | ||
| {(() => { | ||
| if (mutating) | ||
| return <CircleLoader size={FOLLOW_BTN_LOADER_SIZES[size]} />; | ||
| if (allFollowed) return <FollowBtnCheckIcon />; | ||
| return <FollowBtnPlusIcon size={size} />; | ||
| })()} | ||
| <span>{label}</span> | ||
| </button> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default NotificationsFollowAllBtn; | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.