From 5dbd514cfcf703543c65e7c2bed3e0d66e154af6 Mon Sep 17 00:00:00 2001 From: Sharlayan <118798881+sharlayan@users.noreply.github.com> Date: Wed, 12 Aug 2026 17:39:54 +0900 Subject: [PATCH] Fix selected account being lost when creating a collection (#39897) --- .../features/collection_adder/index.tsx | 32 ++++++++++++++++--- .../collection_adder/styles.module.scss | 5 +++ .../mastodon/reducers/slices/collections.ts | 7 ++-- 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 app/javascript/mastodon/features/collection_adder/styles.module.scss diff --git a/app/javascript/mastodon/features/collection_adder/index.tsx b/app/javascript/mastodon/features/collection_adder/index.tsx index b1ec2b0375..2045e55fb3 100644 --- a/app/javascript/mastodon/features/collection_adder/index.tsx +++ b/app/javascript/mastodon/features/collection_adder/index.tsx @@ -10,6 +10,7 @@ import { useCurrentAccountId } from '@/mastodon/hooks/useAccountId'; import type { Account } from '@/mastodon/models/account'; import { addCollectionItem, + collectionEditorActions, removeCollectionItem, } from '@/mastodon/reducers/slices/collections'; import CloseIcon from '@/material-icons/400-24px/close.svg?react'; @@ -23,6 +24,7 @@ import { } from '../collections/overview/created_by_account'; import { CollectionToggle } from './collection_toggle'; +import classes from './styles.module.scss'; const messages = defineMessages({ close: { @@ -107,6 +109,23 @@ export const CollectionAdder: React.FC<{ const account = useAppSelector((state) => state.accounts.get(accountId)); const currentAccountId = useCurrentAccountId(); const { collections, status } = useCollectionsCreatedBy(currentAccountId); + const dispatch = useAppDispatch(); + + const handleNewCollection = useCallback(() => { + if (account) { + dispatch( + collectionEditorActions.reset({ + account_id: account.id, + state: + account.feature_approval.current_user === 'manual' + ? 'pending' + : 'accepted', + }), + ); + } + + onClose(); + }, [account, dispatch, onClose]); return (
@@ -155,12 +174,17 @@ export const CollectionAdder: React.FC<{ /> } > - + ) : ( - collections.map((item) => ( - - )) + <> +
+ +
+ {collections.map((item) => ( + + ))} + )}
diff --git a/app/javascript/mastodon/features/collection_adder/styles.module.scss b/app/javascript/mastodon/features/collection_adder/styles.module.scss new file mode 100644 index 0000000000..99ecf1373e --- /dev/null +++ b/app/javascript/mastodon/features/collection_adder/styles.module.scss @@ -0,0 +1,5 @@ +.newCollection { + display: flex; + justify-content: center; + padding-block: 16px; +} diff --git a/app/javascript/mastodon/reducers/slices/collections.ts b/app/javascript/mastodon/reducers/slices/collections.ts index 2f54cd256d..2606e14ca6 100644 --- a/app/javascript/mastodon/reducers/slices/collections.ts +++ b/app/javascript/mastodon/reducers/slices/collections.ts @@ -111,8 +111,11 @@ const collectionSlice = createSlice({ items: getEditorCollectionItems(collection.items), }; }, - reset(state) { - state.editor = initialCollectionState.editor; + reset(state, action: PayloadAction) { + state.editor = + action.payload !== undefined + ? { ...initialCollectionState.editor, items: [action.payload] } + : initialCollectionState.editor; }, updateEditorField( state: CollectionState,