Fix Status stories (#39730)

This commit is contained in:
Echo authored and GitHub committed 2026-07-06 13:47:31 +00:00
1 parent ea07161698
commit bcb47b814d
1 file changed
+77 -84
@@ -1,5 +1,4 @@
import type { FC } from 'react'; import type { FC } from 'react';
import { useMemo } from 'react';
import { Map as ImmutableMap } from 'immutable'; import { Map as ImmutableMap } from 'immutable';
@@ -7,6 +6,7 @@ import type { Meta, StoryObj } from '@storybook/react-vite';
import { fn } from 'storybook/test'; import { fn } from 'storybook/test';
import type { StatusVisibility } from '@/mastodon/api_types/statuses'; import type { StatusVisibility } from '@/mastodon/api_types/statuses';
import { useAppSelector } from '@/mastodon/store';
import { import {
accountFactoryImmutable, accountFactoryImmutable,
pollFactoryImmutable, pollFactoryImmutable,
@@ -58,108 +58,47 @@ const otherAccount = accountFactoryImmutable({
const StatusStoryComponent: FC<StatusStoryProps> = (props) => { const StatusStoryComponent: FC<StatusStoryProps> = (props) => {
const { const {
text,
visibility,
isReblog, isReblog,
isReply, isReply,
isPoll, isPoll,
isQuote, isQuote,
attachment1,
attachment2,
attachment3,
contentWarning, contentWarning,
hasFavourited,
hasReblogged,
hasBookmarked,
hasFilter, hasFilter,
hasVoted, hasVoted,
showTranslate,
disableActions = false, disableActions = false,
contextType, contextType,
showThread, showThread,
showCounters, showCounters,
favouriteCount = 0,
replyCount = 0,
reblogCount = 0,
hidden, hidden,
muted, muted,
showPrepend = true, showPrepend = true,
} = props; } = props;
const { account, status } = useMemo(() => { const account = useAppSelector((state) => state.accounts.get('1'));
const account = accountFactoryImmutable(); const status = useAppSelector((state) =>
state.statuses.get('1')?.withMutations((status) => {
status.set('account', account);
status.set('matched_filters', hasFilter ? ['test'] : false);
status.set('matched_media_filters', hasFilter ? ['test'] : false);
status.set('hidden', hidden);
return { // StatusActionBar checks specifically for null so undefined doesn't work.
account, if (!status.get('in_reply_to_id')) {
status: statusFactoryImmutable({ status.set('in_reply_to_id', null);
text, }
spoiler_text: contentWarning,
visibility,
media_attachments: attachmentFactory(
attachment1,
attachment2,
attachment3,
),
reblogged: hasReblogged,
favourited: hasFavourited,
bookmarked: hasBookmarked,
in_reply_to_account_id: isReply ? '2' : undefined,
in_reply_to_id: isReply ? '2' : undefined,
quote: isQuote
? {
state: 'accepted',
quoted_status: { ...statusFactoryAPI(), quote: undefined },
}
: undefined,
favourites_count: favouriteCount,
reblogs_count: reblogCount,
replies_count: replyCount,
language: showTranslate ? 'xx' : undefined,
}).withMutations((status) => {
status.set('account', account);
status.set('matched_filters', hasFilter ? ['test'] : false);
status.set('matched_media_filters', hasFilter ? ['test'] : false);
status.set('hidden', hidden);
// StatusActionBar checks specifically for null so undefined doesn't work. if (isReblog) {
if (!status.get('in_reply_to_id')) { status.set(
status.set('in_reply_to_id', null); 'reblog',
} statusFactoryImmutable({ id: '2' }).set('account', otherAccount),
);
if (isReblog) { }
status.set( if (isPoll) {
'reblog', status.set('poll', hasVoted ? '2' : '1');
statusFactoryImmutable({ id: '2' }).set('account', otherAccount), }
); }),
} );
if (isPoll) {
status.set('poll', hasVoted ? '2' : '1');
}
}),
};
}, [
text,
contentWarning,
visibility,
attachment1,
attachment2,
attachment3,
hasReblogged,
hasFavourited,
hasBookmarked,
isReply,
isQuote,
favouriteCount,
reblogCount,
replyCount,
showTranslate,
hasFilter,
hidden,
isReblog,
isPoll,
hasVoted,
]);
return ( return (
<div style={{ width: 'min(600px, 80vw)' }}> <div style={{ width: 'min(600px, 80vw)' }}>
@@ -374,6 +313,60 @@ const meta = {
}, },
}, },
}, },
stateFn({
text,
contentWarning,
visibility,
attachment1,
attachment2,
attachment3,
hasBookmarked,
hasFavourited,
hasReblogged,
isQuote,
isReply,
favouriteCount,
reblogCount,
replyCount,
showTranslate,
}: StatusStoryProps) {
const account = accountFactoryImmutable();
const status = statusFactoryImmutable({
text,
spoiler_text: contentWarning,
visibility,
media_attachments: attachmentFactory(
attachment1,
attachment2,
attachment3,
),
reblogged: hasReblogged,
favourited: hasFavourited,
bookmarked: hasBookmarked,
in_reply_to_account_id: isReply ? '2' : undefined,
in_reply_to_id: isReply ? '2' : undefined,
quote: isQuote
? {
state: 'accepted',
quoted_status: { ...statusFactoryAPI(), quote: undefined },
}
: undefined,
favourites_count: favouriteCount,
reblogs_count: reblogCount,
replies_count: replyCount,
language: showTranslate ? 'xx' : undefined,
});
return {
statuses: {
'1': status,
},
accounts: {
'1': account,
},
};
},
controls: { controls: {
disableSaveFromUI: true, disableSaveFromUI: true,
}, },