From c046ac5f07e3ce960f5ac1c5d80bb0248129c66a Mon Sep 17 00:00:00 2001 From: diondiondion Date: Mon, 19 May 2025 11:54:45 +0200 Subject: [PATCH] [Glitch] fix: Show Follow account modal before allowing adding to list Port 24551375cf556dbf8ef86dd508413a1b449ebde9 to glitch-soc Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Matt Jankowski Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: GitHub Actions Signed-off-by: Claire --- .../flavours/glitch/components/account.tsx | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/app/javascript/flavours/glitch/components/account.tsx b/app/javascript/flavours/glitch/components/account.tsx index 66d50c327b..8c22352c04 100644 --- a/app/javascript/flavours/glitch/components/account.tsx +++ b/app/javascript/flavours/glitch/components/account.tsx @@ -10,9 +10,12 @@ import { unblockAccount, muteAccount, unmuteAccount, + followAccountSuccess, } from 'flavours/glitch/actions/accounts'; +import { showAlertForError } from 'flavours/glitch/actions/alerts'; import { openModal } from 'flavours/glitch/actions/modal'; import { initMuteModal } from 'flavours/glitch/actions/mutes'; +import { apiFollowAccount } from 'flavours/glitch/api/accounts'; import { Avatar } from 'flavours/glitch/components/avatar'; import { Button } from 'flavours/glitch/components/button'; import { FollowersCounter } from 'flavours/glitch/components/counters'; @@ -23,6 +26,7 @@ import { RelativeTimestamp } from 'flavours/glitch/components/relative_timestamp import { ShortNumber } from 'flavours/glitch/components/short_number'; import { Skeleton } from 'flavours/glitch/components/skeleton'; import { VerifiedBadge } from 'flavours/glitch/components/verified_badge'; +import { me } from 'flavours/glitch/initial_state'; import type { MenuItem } from 'flavours/glitch/models/dropdown_menu'; import { useAppSelector, useAppDispatch } from 'flavours/glitch/store'; @@ -114,14 +118,43 @@ export const Account: React.FC<{ ]; } else if (defaultAction !== 'block') { const handleAddToLists = () => { - dispatch( - openModal({ - modalType: 'LIST_ADDER', - modalProps: { - accountId: id, - }, - }), - ); + const openAddToListModal = () => { + dispatch( + openModal({ + modalType: 'LIST_ADDER', + modalProps: { + accountId: id, + }, + }), + ); + }; + if (relationship?.following || relationship?.requested || id === me) { + openAddToListModal(); + } else { + dispatch( + openModal({ + modalType: 'CONFIRM_FOLLOW_TO_LIST', + modalProps: { + accountId: id, + onConfirm: () => { + apiFollowAccount(id) + .then((relationship) => { + dispatch( + followAccountSuccess({ + relationship, + alreadyFollowing: false, + }), + ); + openAddToListModal(); + }) + .catch((err: unknown) => { + dispatch(showAlertForError(err)); + }); + }, + }, + }), + ); + } }; arr = [