From 4134f5ed9c3d6056524c2653786c21c9594ede41 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 6 Feb 2025 16:20:03 -0600 Subject: [PATCH] Support Streaks --- src/features/ui/components/profile-stats.tsx | 14 +++++++++++++- src/locales/en.json | 1 + src/schemas/account.ts | 6 +++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/features/ui/components/profile-stats.tsx b/src/features/ui/components/profile-stats.tsx index 4e12ce16b..b1eae0b60 100644 --- a/src/features/ui/components/profile-stats.tsx +++ b/src/features/ui/components/profile-stats.tsx @@ -10,10 +10,11 @@ import type { Account } from 'soapbox/schemas/index.ts'; const messages = defineMessages({ followers: { id: 'account.followers', defaultMessage: 'Followers' }, follows: { id: 'account.follows', defaultMessage: 'Following' }, + streak: { id: 'account.streak', defaultMessage: 'Day Streak' }, }); interface IProfileStats { - account: Pick | undefined; + account: Pick | undefined; onClickHandler?: React.MouseEventHandler; } @@ -48,6 +49,17 @@ const ProfileStats: React.FC = ({ account, onClickHandler }) => { + + {account.ditto.streak.days > 0 && ( + + + {shortNumberFormat(account.ditto.streak.days)} + + + {intl.formatMessage(messages.streak)} + + + )} ); }; diff --git a/src/locales/en.json b/src/locales/en.json index 2b52b6c9e..3a531ab37 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -55,6 +55,7 @@ "account.search_self": "Search your posts", "account.share": "Share @{name}'s profile", "account.show_reblogs": "Show reposts from @{name}", + "account.streak": "Day Streak", "account.subscribe": "Subscribe to notifications from @{name}", "account.subscribe.failure": "An error occurred trying to subscribe to this account.", "account.subscribe.success": "You have subscribed to this account.", diff --git a/src/schemas/account.ts b/src/schemas/account.ts index de6fa26ef..e95518527 100644 --- a/src/schemas/account.ts +++ b/src/schemas/account.ts @@ -38,8 +38,12 @@ const baseAccountSchema = z.object({ display_name: z.string().catch(''), ditto: coerceObject({ accepts_zaps: z.boolean().catch(false), - is_registered: z.boolean().catch(false), external_url: z.string().optional().catch(undefined), + streak: coerceObject({ + days: z.number().catch(0), + start: z.string().datetime().nullable().catch(null), + end: z.string().datetime().nullable().catch(null), + }), }), domain: z.string().optional().catch(undefined), emojis: filteredArray(customEmojiSchema),