-
Notifications
You must be signed in to change notification settings - Fork 4
Reordering tabs and set profile curation #2295
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
10 commits
Select commit
Hold shift + click to select a range
913aad1
wip
ragnep f8c7a1d
wip
ragnep dcd7a89
Merge branch 'main' into reordering-tabs
ragnep 318a3ea
wip
ragnep 0723c5b
wip
ragnep 2b952b3
Merge branch 'main' into reordering-tabs
ragnep bd0cdec
wip
ragnep 308b023
wip
ragnep e18370c
wip
ragnep 391c0ce
wip
ragnep 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
425 changes: 351 additions & 74 deletions
425
components/brain/my-stream/MyStreamWaveDesktopTabs.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
150 changes: 150 additions & 0 deletions
150
components/brain/my-stream/tabs/MyStreamWaveCurationTabMenu.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,150 @@ | ||
| "use client"; | ||
|
|
||
| import { useState } from "react"; | ||
| import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
| import { EllipsisVerticalIcon } from "@heroicons/react/24/outline"; | ||
| import { CompactMenu, type CompactMenuItem } from "@/components/compact-menu"; | ||
| import { useAuth } from "@/components/auth/Auth"; | ||
| import CommonConfirmationModal from "@/components/utils/modal/CommonConfirmationModal"; | ||
| import type { ApiWave } from "@/generated/models/ApiWave"; | ||
| import type { ApiWaveCuration } from "@/generated/models/ApiWaveCuration"; | ||
| import type { DropCurationMembership } from "@/hooks/drops/useDropCurations"; | ||
| import { invalidateProfileWaveQueries } from "@/hooks/useProfileWave"; | ||
| import { getWaveCurationsQueryKey } from "@/hooks/waves/useWaveCurations"; | ||
| import { useProfileWaveMutation } from "@/hooks/useProfileWaveMutation"; | ||
| import { commonApiDelete } from "@/services/api/common-api"; | ||
| import MyStreamWaveCurationCreateDialog from "./MyStreamWaveCurationCreateDialog"; | ||
|
|
||
| interface MyStreamWaveCurationTabMenuProps { | ||
| readonly wave: ApiWave; | ||
| readonly curation: ApiWaveCuration; | ||
| readonly onDeleted?: (() => void) | undefined; | ||
| readonly canSetAsProfileCuration?: boolean | undefined; | ||
| readonly isSetAsProfileCurationPending?: boolean | undefined; | ||
| } | ||
|
|
||
| const getErrorMessage = (error: unknown): string => | ||
| error instanceof Error ? error.message : "Failed to delete curation."; | ||
|
|
||
| export default function MyStreamWaveCurationTabMenu({ | ||
| wave, | ||
| curation, | ||
| onDeleted, | ||
| canSetAsProfileCuration = false, | ||
| isSetAsProfileCurationPending = false, | ||
| }: MyStreamWaveCurationTabMenuProps) { | ||
| const queryClient = useQueryClient(); | ||
| const { connectedProfile, requestAuth, setToast } = useAuth(); | ||
| const { updateProfileWave, isPending: isProfileWavePending } = | ||
| useProfileWaveMutation(connectedProfile); | ||
| const [isEditOpen, setIsEditOpen] = useState(false); | ||
| const [isDeleteOpen, setIsDeleteOpen] = useState(false); | ||
| const isSettingProfileCuration = | ||
| isSetAsProfileCurationPending || isProfileWavePending; | ||
|
|
||
| const deleteMutation = useMutation({ | ||
| mutationFn: async () => { | ||
| const auth = await requestAuth(); | ||
| if (!auth.success) { | ||
| throw new Error("Authentication was cancelled."); | ||
| } | ||
|
|
||
| await commonApiDelete({ | ||
| endpoint: `waves/${wave.id}/curations/${curation.id}`, | ||
| }); | ||
| }, | ||
| onSuccess: async () => { | ||
| queryClient.setQueryData<ApiWaveCuration[]>( | ||
| getWaveCurationsQueryKey(wave.id), | ||
| (current) => current?.filter((item) => item.id !== curation.id) | ||
| ); | ||
| queryClient.setQueriesData<DropCurationMembership[]>( | ||
| { queryKey: ["drop-curations"] }, | ||
| (current) => current?.filter((item) => item.id !== curation.id) | ||
| ); | ||
| await queryClient.invalidateQueries({ | ||
| queryKey: getWaveCurationsQueryKey(wave.id), | ||
| }); | ||
| await queryClient.invalidateQueries({ | ||
| queryKey: ["drop-curations"], | ||
| }); | ||
| await invalidateProfileWaveQueries(queryClient, [ | ||
| connectedProfile, | ||
| wave.author, | ||
| ]); | ||
| setToast({ | ||
| type: "success", | ||
| message: "Curation deleted.", | ||
| }); | ||
| setIsDeleteOpen(false); | ||
| onDeleted?.(); | ||
| }, | ||
| onError: (error) => { | ||
| setToast({ | ||
| type: "error", | ||
| message: getErrorMessage(error), | ||
| }); | ||
| }, | ||
| }); | ||
|
|
||
| const menuItems: CompactMenuItem[] = [ | ||
| { | ||
| id: "edit", | ||
| label: "Edit curation", | ||
| onSelect: () => setIsEditOpen(true), | ||
| }, | ||
| ...(canSetAsProfileCuration | ||
| ? [ | ||
| { | ||
| id: "set-profile-curation", | ||
| label: "Set as profile curation", | ||
| onSelect: () => { | ||
| void updateProfileWave(wave.id, curation.id); | ||
| }, | ||
| disabled: isSettingProfileCuration, | ||
| }, | ||
| ] | ||
| : []), | ||
| { | ||
| id: "delete", | ||
| label: "Delete curation", | ||
| onSelect: () => setIsDeleteOpen(true), | ||
| className: "tw-text-red desktop-hover:hover:tw-text-red", | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <> | ||
| <CompactMenu | ||
| triggerClassName="tw-inline-flex tw-h-8 tw-w-4 tw-flex-shrink-0 tw-items-center tw-justify-center tw-border-0 tw-bg-transparent tw-text-iron-400 tw-transition hover:tw-text-iron-300 disabled:tw-cursor-not-allowed disabled:tw-opacity-40" | ||
| trigger={ | ||
| <EllipsisVerticalIcon className="tw-mt-0.5 tw-block tw-size-4 tw-flex-shrink-0" /> | ||
| } | ||
| aria-label="Curation options" | ||
| items={menuItems} | ||
| menuWidthClassName="tw-w-52" | ||
| disabled={deleteMutation.isPending || isSettingProfileCuration} | ||
| /> | ||
|
|
||
| {isEditOpen && ( | ||
| <MyStreamWaveCurationCreateDialog | ||
| wave={wave} | ||
| isOpen={isEditOpen} | ||
| onClose={() => setIsEditOpen(false)} | ||
| onSaved={() => undefined} | ||
| curation={curation} | ||
| /> | ||
| )} | ||
|
|
||
| <CommonConfirmationModal | ||
| isOpen={isDeleteOpen} | ||
| onClose={() => setIsDeleteOpen(false)} | ||
| onConfirm={() => deleteMutation.mutate()} | ||
| title="Delete curation" | ||
| message={`Delete "${curation.name}" from this wave?`} | ||
| confirmText="Delete" | ||
| isConfirming={deleteMutation.isPending} | ||
| /> | ||
| </> | ||
| ); | ||
| } | ||
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.
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.