From e37a95408c372b53db7744ed3e0325ef8b9a1348 Mon Sep 17 00:00:00 2001 From: xmflsct Date: Sun, 12 Feb 2023 19:47:28 +0100 Subject: [PATCH] Fix #608 --- fastlane/metadata/en-US/release_notes.txt | 3 +- fastlane/metadata/zh-Hans/release_notes.txt | 3 +- src/components/Relationship/Outgoing.tsx | 8 +- src/components/contextMenu/account.ts | 8 +- src/i18n/en/screens/tabs.json | 1 + .../Account/Information/PrivateNotes.tsx | 152 ++++++++++++++++-- src/utils/queryHooks/relationship.ts | 13 +- 7 files changed, 161 insertions(+), 27 deletions(-) diff --git a/fastlane/metadata/en-US/release_notes.txt b/fastlane/metadata/en-US/release_notes.txt index 9e6b2fe9..5e983aa2 100644 --- a/fastlane/metadata/en-US/release_notes.txt +++ b/fastlane/metadata/en-US/release_notes.txt @@ -1,2 +1,3 @@ Enjoy toooting! This version includes following improvements and fixes: -- Added following remote instance \ No newline at end of file +- Added following remote instance +- Added set note of followed users \ No newline at end of file diff --git a/fastlane/metadata/zh-Hans/release_notes.txt b/fastlane/metadata/zh-Hans/release_notes.txt index 05869c85..8d2d6a1b 100644 --- a/fastlane/metadata/zh-Hans/release_notes.txt +++ b/fastlane/metadata/zh-Hans/release_notes.txt @@ -1,2 +1,3 @@ toooting愉快!此版本包括以下改进和修复: -- 新增关注远程实例功能 \ No newline at end of file +- 新增关注远程实例功能 +- 新增关注用户备注功能 \ No newline at end of file diff --git a/src/components/Relationship/Outgoing.tsx b/src/components/Relationship/Outgoing.tsx index e4fabbf2..685a0518 100644 --- a/src/components/Relationship/Outgoing.tsx +++ b/src/components/Relationship/Outgoing.tsx @@ -29,20 +29,20 @@ const RelationshipOutgoing: React.FC = ({ id }: Props) => { const queryKeyRelationship: QueryKeyRelationship = ['Relationship', { id }] const queryClient = useQueryClient() const mutation = useRelationshipMutation({ - onSuccess: (res, { payload: { action } }) => { + onSuccess: (res, vars) => { haptics('Success') queryClient.setQueryData(queryKeyRelationship, [res]) - if (action === 'block') { + if (vars.type === 'outgoing' && vars.payload.action === 'block') { const queryKey = ['Timeline', { page: 'Following' }] queryClient.invalidateQueries({ queryKey, exact: false }) } }, - onError: (err: any, { payload: { action } }) => { + onError: (err: any, vars) => { displayMessage({ theme, type: 'error', message: t('common:message.error.message', { - function: t(`componentRelationship:${action}.function` as any) + function: t(`componentRelationship:${(vars.payload as any).action}.function` as any) }), ...(err.status && typeof err.status === 'number' && diff --git a/src/components/contextMenu/account.ts b/src/components/contextMenu/account.ts index 413d5e94..4da0a947 100644 --- a/src/components/contextMenu/account.ts +++ b/src/components/contextMenu/account.ts @@ -105,21 +105,21 @@ const menuAccount = ({ }) const queryKeyRelationship: QueryKeyRelationship = ['Relationship', { id: actualAccount?.id }] const relationshipMutation = useRelationshipMutation({ - onSuccess: (res, { payload: { action } }) => { + onSuccess: (res, vars) => { haptics('Success') queryClient.setQueryData(queryKeyRelationship, [res]) - if (action === 'block') { + if (vars.type === 'outgoing' && vars.payload.action === 'block') { queryClient.invalidateQueries({ queryKey: ['Timeline', { page: 'Following' }], exact: false }) } }, - onError: (err: any, { payload: { action } }) => { + onError: (err: any, vars) => { displayMessage({ type: 'danger', message: t('common:message.error.message', { - function: t(`componentContextMenu:${action}.function` as any) + function: t(`componentContextMenu:${(vars.payload as any).action}.function` as any) }), ...(err.status && typeof err.status === 'number' && diff --git a/src/i18n/en/screens/tabs.json b/src/i18n/en/screens/tabs.json index 81a85b1f..615c4db5 100644 --- a/src/i18n/en/screens/tabs.json +++ b/src/i18n/en/screens/tabs.json @@ -386,6 +386,7 @@ "accessibilityHint": "You can mute, block, report or share this user" }, "followed_by": " is following you", + "privateNote": "Set private note", "moved": "User moved", "created_at": "Joined: {{date}}", "summary": { diff --git a/src/screens/Tabs/Shared/Account/Information/PrivateNotes.tsx b/src/screens/Tabs/Shared/Account/Information/PrivateNotes.tsx index 22ba4f95..6ac8aa19 100644 --- a/src/screens/Tabs/Shared/Account/Information/PrivateNotes.tsx +++ b/src/screens/Tabs/Shared/Account/Information/PrivateNotes.tsx @@ -1,27 +1,147 @@ -import { ParseHTML } from '@components/Parse' +import Button from '@components/Button' +import { discardConfirmation } from '@components/discardConfirmation' +import Icon from '@components/Icon' +import CustomText from '@components/Text' +import { queryClient } from '@utils/queryHooks' +import { QueryKeyRelationship, useRelationshipMutation } from '@utils/queryHooks/relationship' import { StyleConstants } from '@utils/styles/constants' +import layoutAnimation from '@utils/styles/layoutAnimation' import { useTheme } from '@utils/styles/ThemeManager' -import React, { useContext } from 'react' -import { View } from 'react-native' +import React, { useContext, useState } from 'react' +import { useTranslation } from 'react-i18next' +import { Pressable, TextInput, View } from 'react-native' import AccountContext from '../Context' const AccountInformationPrivateNote: React.FC = () => { const { relationship, pageMe } = useContext(AccountContext) - if (pageMe) return null + if (!relationship || pageMe) return null - const { colors } = useTheme() + const { colors, mode } = useTheme() + const { t } = useTranslation(['common', 'screenTabs']) - return relationship?.note ? ( - - - + const [editing, setEditing] = useState(false) + const [notes, setNotes] = useState(relationship?.note) + + const queryKey: QueryKeyRelationship = ['Relationship', { id: relationship.id }] + const mutation = useRelationshipMutation({ + onMutate: async vars => { + await queryClient.cancelQueries({ queryKey }) + queryClient.setQueryData(queryKey, old => { + return old + ? vars.type === 'note' + ? old.map(o => (o.id === relationship.id ? { ...o, note: notes } : o)) + : old + : undefined + }) + }, + onError: () => { + queryClient.invalidateQueries(queryKey) + } + }) + const submit = () => { + mutation.mutate({ id: relationship.id, type: 'note', payload: notes || '' }) + setEditing(!editing) + layoutAnimation() + } + + return relationship?.following ? ( + editing ? ( + + submit()} + placeholder={t('screenTabs:shared.account.privateNote')} + placeholderTextColor={colors.secondary} + returnKeyType='done' + keyboardAppearance={mode} + autoFocus + /> + +