From b5721dbd4a7b7bf25af3ae522d4f917e080a267f Mon Sep 17 00:00:00 2001 From: diondiondion Date: Wed, 10 Dec 2025 15:07:25 +0100 Subject: [PATCH] [Glitch] Fix Wrapstodon Storybook & other Wrapstodon issues Port 8137ce87ce40b0eff54fdb9feb06c83433ced9cc to glitch-soc Signed-off-by: Claire --- .../annual_report/annual_report.stories.tsx | 178 ++++++++---------- .../features/annual_report/archetype.tsx | 9 +- .../annual_report/highlighted_post.tsx | 7 +- .../glitch/features/annual_report/index.tsx | 23 +-- .../annual_report/most_used_hashtag.tsx | 24 ++- .../features/annual_report/shared_page.tsx | 8 +- .../flavours/glitch/models/annual_report.ts | 6 +- 7 files changed, 124 insertions(+), 131 deletions(-) diff --git a/app/javascript/flavours/glitch/features/annual_report/annual_report.stories.tsx b/app/javascript/flavours/glitch/features/annual_report/annual_report.stories.tsx index 290671c0f1..20a3735e15 100644 --- a/app/javascript/flavours/glitch/features/annual_report/annual_report.stories.tsx +++ b/app/javascript/flavours/glitch/features/annual_report/annual_report.stories.tsx @@ -2,11 +2,17 @@ import type { Meta, StoryObj } from '@storybook/react-vite'; import { accountFactoryState, - // statusFactoryState + annualReportFactory, + statusFactoryState, } from '@/testing/factories'; import { AnnualReport } from '.'; +const SAMPLE_HASHTAG = { + name: 'Mastodon', + count: 14, +}; + const meta = { title: 'Components/AnnualReport', component: AnnualReport, @@ -16,108 +22,14 @@ const meta = { parameters: { state: { accounts: { - '1': accountFactoryState(), + '1': accountFactoryState({ display_name: 'Freddie Fruitbat' }), }, - // statuses: { - // '1': statusFactoryState(), - // }, - annualReport: { - state: 'available', - report: { - schema_version: 2, - share_url: '#', - account_id: '1', - year: 2025, - data: { - archetype: 'lurker', - time_series: [ - { - month: 1, - statuses: 0, - followers: 0, - following: 0, - }, - { - month: 2, - statuses: 0, - followers: 0, - following: 0, - }, - { - month: 3, - statuses: 0, - followers: 0, - following: 0, - }, - { - month: 4, - statuses: 0, - followers: 0, - following: 0, - }, - { - month: 5, - statuses: 1, - followers: 1, - following: 3, - }, - { - month: 6, - statuses: 7, - followers: 1, - following: 0, - }, - { - month: 7, - statuses: 2, - followers: 0, - following: 0, - }, - { - month: 8, - statuses: 2, - followers: 0, - following: 0, - }, - { - month: 9, - statuses: 11, - followers: 0, - following: 1, - }, - { - month: 10, - statuses: 12, - followers: 0, - following: 1, - }, - { - month: 11, - statuses: 6, - followers: 0, - following: 1, - }, - { - month: 12, - statuses: 4, - followers: 0, - following: 0, - }, - ], - top_hashtags: [ - { - name: 'Mastodon', - count: 14, - }, - ], - top_statuses: { - by_reblogs: '1', - by_replies: '1', - by_favourites: '1', - }, - }, - }, + statuses: { + '1': statusFactoryState(), }, + annualReport: annualReportFactory({ + top_hashtag: SAMPLE_HASHTAG, + }), }, }, } satisfies Meta; @@ -126,6 +38,68 @@ export default meta; type Story = StoryObj; -export const Default: Story = { +export const Standalone: Story = { + args: { + context: 'standalone', + }, + render: (args) => , +}; + +export const InModal: Story = { + args: { + context: 'modal', + }, + render: (args) => , +}; + +export const ArchetypeOracle: Story = { + ...InModal, + parameters: { + state: { + annualReport: annualReportFactory({ + archetype: 'oracle', + top_hashtag: SAMPLE_HASHTAG, + }), + }, + }, + render: (args) => , +}; + +export const NoHashtag: Story = { + ...InModal, + parameters: { + state: { + annualReport: annualReportFactory({ + archetype: 'booster', + }), + }, + }, + render: (args) => , +}; + +export const NoNewPosts: Story = { + ...InModal, + parameters: { + state: { + annualReport: annualReportFactory({ + archetype: 'pollster', + top_hashtag: SAMPLE_HASHTAG, + without_posts: true, + }), + }, + }, + render: (args) => , +}; + +export const NoNewPostsNoHashtag: Story = { + ...InModal, + parameters: { + state: { + annualReport: annualReportFactory({ + archetype: 'replier', + without_posts: true, + }), + }, + }, render: (args) => , }; diff --git a/app/javascript/flavours/glitch/features/annual_report/archetype.tsx b/app/javascript/flavours/glitch/features/annual_report/archetype.tsx index 9bec40bf00..eb2119009e 100644 --- a/app/javascript/flavours/glitch/features/annual_report/archetype.tsx +++ b/app/javascript/flavours/glitch/features/annual_report/archetype.tsx @@ -6,7 +6,6 @@ import classNames from 'classnames'; import { Avatar } from '@/flavours/glitch/components/avatar'; import { Button } from '@/flavours/glitch/components/button'; -import { me } from '@/flavours/glitch/initial_state'; import type { Account } from '@/flavours/glitch/models/account'; import type { AnnualReport, @@ -112,11 +111,11 @@ const illustrations = { export const Archetype: React.FC<{ report: AnnualReport; account?: Account; - canShare: boolean; -}> = ({ report, account, canShare }) => { + context: 'modal' | 'standalone'; +}> = ({ report, account, context }) => { const intl = useIntl(); const wrapperRef = useRef(null); - const isSelfView = account?.id === me; + const isSelfView = context === 'modal'; const [isRevealed, setIsRevealed] = useState(!isSelfView); const reveal = useCallback(() => { @@ -209,7 +208,7 @@ export const Archetype: React.FC<{ /> )} - {isRevealed && canShare && } + {isRevealed && isSelfView && } ); }; diff --git a/app/javascript/flavours/glitch/features/annual_report/highlighted_post.tsx b/app/javascript/flavours/glitch/features/annual_report/highlighted_post.tsx index 61fa365e72..9ca64d40ba 100644 --- a/app/javascript/flavours/glitch/features/annual_report/highlighted_post.tsx +++ b/app/javascript/flavours/glitch/features/annual_report/highlighted_post.tsx @@ -19,7 +19,8 @@ const getStatus = makeGetStatus() as unknown as (arg0: any, arg1: any) => any; export const HighlightedPost: React.FC<{ data: TopStatuses; -}> = ({ data }) => { + context: 'modal' | 'standalone'; +}> = ({ data, context }) => { const { by_reblogs, by_favourites, by_replies } = data; const statusId = by_reblogs || by_favourites || by_replies; @@ -68,10 +69,10 @@ export const HighlightedPost: React.FC<{ defaultMessage='Most popular post' /> -

{label}

+ {context === 'modal' &&

{label}

} - + ); }; diff --git a/app/javascript/flavours/glitch/features/annual_report/index.tsx b/app/javascript/flavours/glitch/features/annual_report/index.tsx index 7abdd913f1..b00a8cde4d 100644 --- a/app/javascript/flavours/glitch/features/annual_report/index.tsx +++ b/app/javascript/flavours/glitch/features/annual_report/index.tsx @@ -66,10 +66,9 @@ export const AnnualReport: FC<{ context?: 'modal' | 'standalone' }> = ({ 0, ); - const newFollowerCount = report.data.time_series.reduce( - (sum, item) => sum + item.followers, - 0, - ); + const newFollowerCount = + context === 'modal' && + report.data.time_series.reduce((sum, item) => sum + item.followers, 0); const topHashtag = report.data.top_hashtags[0]; @@ -99,7 +98,7 @@ export const AnnualReport: FC<{ context?: 'modal' | 'standalone' }> = ({
- +
= ({ > {!!newFollowerCount && } {!!newPostCount && } - {topHashtag && } + {topHashtag && ( + + )}
- +
); diff --git a/app/javascript/flavours/glitch/features/annual_report/most_used_hashtag.tsx b/app/javascript/flavours/glitch/features/annual_report/most_used_hashtag.tsx index 294b7460d4..7f60db8038 100644 --- a/app/javascript/flavours/glitch/features/annual_report/most_used_hashtag.tsx +++ b/app/javascript/flavours/glitch/features/annual_report/most_used_hashtag.tsx @@ -8,7 +8,9 @@ import styles from './index.module.scss'; export const MostUsedHashtag: React.FC<{ hashtag: NameAndCount; -}> = ({ hashtag }) => { + name: string | undefined; + context: 'modal' | 'standalone'; +}> = ({ hashtag, name, context }) => { return (
#{hashtag.name}

- + {context === 'modal' ? ( + + ) : ( + name && ( + + ) + )}

); diff --git a/app/javascript/flavours/glitch/features/annual_report/shared_page.tsx b/app/javascript/flavours/glitch/features/annual_report/shared_page.tsx index 2d28740fc3..5439630a2d 100644 --- a/app/javascript/flavours/glitch/features/annual_report/shared_page.tsx +++ b/app/javascript/flavours/glitch/features/annual_report/shared_page.tsx @@ -1,5 +1,7 @@ import type { FC } from 'react'; +import { FormattedMessage } from 'react-intl'; + import { IconLogo } from '@/flavours/glitch/components/logo'; import { AnnualReport } from './index'; @@ -11,7 +13,11 @@ export const WrapstodonSharedPage: FC = () => { ); diff --git a/app/javascript/flavours/glitch/models/annual_report.ts b/app/javascript/flavours/glitch/models/annual_report.ts index 712f406310..863debfc1f 100644 --- a/app/javascript/flavours/glitch/models/annual_report.ts +++ b/app/javascript/flavours/glitch/models/annual_report.ts @@ -16,9 +16,9 @@ export interface TimeSeriesMonth { } export interface TopStatuses { - by_reblogs: number; - by_favourites: number; - by_replies: number; + by_reblogs: string; + by_favourites: string; + by_replies: string; } export type Archetype =