From cc3d5b14e5a8092d72cf2a806f08885b34d2c04b Mon Sep 17 00:00:00 2001 From: xmflsct Date: Mon, 31 Oct 2022 23:43:42 +0100 Subject: [PATCH] Fixed #427 --- src/components/Timeline/Shared/Actions.tsx | 99 ++++++++++++++++++---- src/i18n/en/components/timeline.json | 7 +- src/utils/queryHooks/timeline.ts | 16 +++- 3 files changed, 101 insertions(+), 21 deletions(-) diff --git a/src/components/Timeline/Shared/Actions.tsx b/src/components/Timeline/Shared/Actions.tsx index ddf1fdd3..46e98e1b 100644 --- a/src/components/Timeline/Shared/Actions.tsx +++ b/src/components/Timeline/Shared/Actions.tsx @@ -2,6 +2,7 @@ import analytics from '@components/analytics' import Icon from '@components/Icon' import { displayMessage } from '@components/Message' import CustomText from '@components/Text' +import { useActionSheet } from '@expo/react-native-action-sheet' import { useNavigation } from '@react-navigation/native' import { StackNavigationProp } from '@react-navigation/stack' import { RootStackParamList } from '@utils/navigation/navigators' @@ -95,25 +96,87 @@ const TimelineActions: React.FC = ({ queryKey }) }, [status.replies_count]) + const { showActionSheetWithOptions } = useActionSheet() const onPressReblog = useCallback(() => { - analytics('timeline_shared_actions_reblog_press', { - page: queryKey[1].page, - count: status.reblogs_count, - current: status.reblogged - }) - mutation.mutate({ - type: 'updateStatusProperty', - queryKey, - rootQueryKey, - id: status.id, - reblog, - payload: { - property: 'reblogged', - currentValue: status.reblogged, - propertyCount: 'reblogs_count', - countValue: status.reblogs_count - } - }) + if (!status.reblogged) { + showActionSheetWithOptions( + { + title: t('shared.actions.reblogged.options.title'), + options: [ + t('shared.actions.reblogged.options.public'), + t('shared.actions.reblogged.options.unlisted'), + t('common:buttons.cancel') + ], + cancelButtonIndex: 2 + }, + (selectedIndex: number) => { + switch (selectedIndex) { + case 0: + analytics('timeline_shared_actions_reblog_public_press', { + page: queryKey[1].page, + count: status.reblogs_count, + current: status.reblogged + }) + mutation.mutate({ + type: 'updateStatusProperty', + queryKey, + rootQueryKey, + id: status.id, + reblog, + payload: { + property: 'reblogged', + currentValue: status.reblogged, + propertyCount: 'reblogs_count', + countValue: status.reblogs_count, + visibility: 'public' + } + }) + break + case 1: + analytics('timeline_shared_actions_reblog_unlisted_press', { + page: queryKey[1].page, + count: status.reblogs_count, + current: status.reblogged + }) + mutation.mutate({ + type: 'updateStatusProperty', + queryKey, + rootQueryKey, + id: status.id, + reblog, + payload: { + property: 'reblogged', + currentValue: status.reblogged, + propertyCount: 'reblogs_count', + countValue: status.reblogs_count, + visibility: 'unlisted' + } + }) + break + } + } + ) + } else { + analytics('timeline_shared_actions_reblog_press', { + page: queryKey[1].page, + count: status.reblogs_count, + current: status.reblogged + }) + mutation.mutate({ + type: 'updateStatusProperty', + queryKey, + rootQueryKey, + id: status.id, + reblog, + payload: { + property: 'reblogged', + currentValue: status.reblogged, + propertyCount: 'reblogs_count', + countValue: status.reblogs_count, + visibility: 'public' + } + }) + } }, [status.reblogged, status.reblogs_count]) const onPressFavourite = useCallback(() => { analytics('timeline_shared_actions_favourite_press', { diff --git a/src/i18n/en/components/timeline.json b/src/i18n/en/components/timeline.json index 066eade6..6ae14037 100644 --- a/src/i18n/en/components/timeline.json +++ b/src/i18n/en/components/timeline.json @@ -38,7 +38,12 @@ }, "reblogged": { "accessibilityLabel": "Boost this toot", - "function": "Boost toot" + "function": "Boost toot", + "options": { + "title": "Choose boost visibility", + "public": "Public boost", + "unlisted": "Unlist boost" + } }, "favourited": { "accessibilityLabel": "Add this toot to favourites", diff --git a/src/utils/queryHooks/timeline.ts b/src/utils/queryHooks/timeline.ts index d7e1b131..440969e9 100644 --- a/src/utils/queryHooks/timeline.ts +++ b/src/utils/queryHooks/timeline.ts @@ -293,11 +293,18 @@ export type MutationVarsTimelineUpdateStatusProperty = { countValue: undefined } | { - property: 'favourited' | 'reblogged' + property: 'favourited' currentValue: boolean propertyCount: 'favourites_count' | 'reblogs_count' countValue: number } + | { + property: 'reblogged' + currentValue: boolean + propertyCount: 'favourites_count' | 'reblogs_count' + countValue: number + visibility: 'public' | 'unlisted' + } | { property: 'poll' id: Mastodon.Poll['id'] @@ -371,11 +378,16 @@ const mutationFunction = async (params: MutationVarsTimeline) => { ...(params.payload.type === 'vote' && { body: formData }) }) default: + const body = new FormData() + if (params.payload.property === 'reblogged') { + body.append('visibility', params.payload.visibility) + } return apiInstance({ method: 'post', url: `statuses/${params.id}/${ params.payload.currentValue ? 'un' : '' - }${MapPropertyToUrl[params.payload.property]}` + }${MapPropertyToUrl[params.payload.property]}`, + body }) } case 'updateAccountProperty':