From ceeabffee547e165158b80b786f4688b5002c4be Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Fri, 16 Aug 2024 12:00:59 +0200 Subject: [PATCH] [Glitch] Add a follow button & follower count on follow notifications Port 32a78e56e0a9934f65b89a455f2d118642b998de to glitch-soc Signed-off-by: Claire --- .../components/notification_follow.tsx | 55 +++++++++++++++---- .../notification_follow_request.tsx | 4 +- .../notification_group_with_status.tsx | 12 +++- .../flavours/glitch/styles/components.scss | 12 ++++ 4 files changed, 68 insertions(+), 15 deletions(-) diff --git a/app/javascript/flavours/glitch/features/notifications_v2/components/notification_follow.tsx b/app/javascript/flavours/glitch/features/notifications_v2/components/notification_follow.tsx index 92d28dccbd..3bb3708255 100644 --- a/app/javascript/flavours/glitch/features/notifications_v2/components/notification_follow.tsx +++ b/app/javascript/flavours/glitch/features/notifications_v2/components/notification_follow.tsx @@ -1,7 +1,11 @@ import { FormattedMessage } from 'react-intl'; import PersonAddIcon from '@/material-icons/400-24px/person_add-fill.svg?react'; +import { FollowersCounter } from 'flavours/glitch/components/counters'; +import { FollowButton } from 'flavours/glitch/components/follow_button'; +import { ShortNumber } from 'flavours/glitch/components/short_number'; import type { NotificationGroupFollow } from 'flavours/glitch/models/notification_group'; +import { useAppSelector } from 'flavours/glitch/store'; import type { LabelRenderer } from './notification_group_with_status'; import { NotificationGroupWithStatus } from './notification_group_with_status'; @@ -14,18 +18,45 @@ const labelRenderer: LabelRenderer = (values) => ( /> ); +const FollowerCount: React.FC<{ accountId: string }> = ({ accountId }) => { + const account = useAppSelector((s) => s.accounts.get(accountId)); + + if (!account) return null; + + return ( + + ); +}; + export const NotificationFollow: React.FC<{ notification: NotificationGroupFollow; unread: boolean; -}> = ({ notification, unread }) => ( - -); +}> = ({ notification, unread }) => { + let actions: JSX.Element | undefined; + let additionalContent: JSX.Element | undefined; + + if (notification.sampleAccountIds.length === 1) { + // only display those if the group contains 1 account, otherwise it does not makes sense + const account = notification.sampleAccountIds[0]; + + if (account) { + actions = ; + additionalContent = ; + } + } + + return ( + + ); +}; diff --git a/app/javascript/flavours/glitch/features/notifications_v2/components/notification_follow_request.tsx b/app/javascript/flavours/glitch/features/notifications_v2/components/notification_follow_request.tsx index eff233152d..02fe1329e6 100644 --- a/app/javascript/flavours/glitch/features/notifications_v2/components/notification_follow_request.tsx +++ b/app/javascript/flavours/glitch/features/notifications_v2/components/notification_follow_request.tsx @@ -46,7 +46,7 @@ export const NotificationFollowRequest: React.FC<{ }, [dispatch, notification.sampleAccountIds]); const actions = ( -
+ <> -
+ ); return ( diff --git a/app/javascript/flavours/glitch/features/notifications_v2/components/notification_group_with_status.tsx b/app/javascript/flavours/glitch/features/notifications_v2/components/notification_group_with_status.tsx index a7c1170d85..7dc498f244 100644 --- a/app/javascript/flavours/glitch/features/notifications_v2/components/notification_group_with_status.tsx +++ b/app/javascript/flavours/glitch/features/notifications_v2/components/notification_group_with_status.tsx @@ -31,6 +31,7 @@ export const NotificationGroupWithStatus: React.FC<{ labelSeeMoreHref?: string; type: string; unread: boolean; + additionalContent?: JSX.Element; }> = ({ icon, iconId, @@ -43,6 +44,7 @@ export const NotificationGroupWithStatus: React.FC<{ labelSeeMoreHref, type, unread, + additionalContent, }) => { const dispatch = useAppDispatch(); @@ -92,7 +94,9 @@ export const NotificationGroupWithStatus: React.FC<{
- {actions} + {actions && ( +
{actions}
+ )}
@@ -106,6 +110,12 @@ export const NotificationGroupWithStatus: React.FC<{
)} + + {additionalContent && ( +
+ {additionalContent} +
+ )} diff --git a/app/javascript/flavours/glitch/styles/components.scss b/app/javascript/flavours/glitch/styles/components.scss index 7873d83257..ed5e1b319d 100644 --- a/app/javascript/flavours/glitch/styles/components.scss +++ b/app/javascript/flavours/glitch/styles/components.scss @@ -11043,6 +11043,13 @@ noscript { gap: 8px; flex: 1 1 auto; overflow: hidden; + container-type: inline-size; + + @container (width < 350px) { + &__header time { + display: none; + } + } &__header { display: flex; @@ -11082,6 +11089,11 @@ noscript { border-radius: 8px; padding: 8px; } + + &__additional-content { + color: $darker-text-color; + margin-top: -8px; // to offset the parent's `gap` property + } } &__avatar-group {