mirror of https://github.com/tooot-app/app
Fix #608
This commit is contained in:
parent
d3cf0edbc9
commit
e37a95408c
|
@ -1,2 +1,3 @@
|
||||||
Enjoy toooting! This version includes following improvements and fixes:
|
Enjoy toooting! This version includes following improvements and fixes:
|
||||||
- Added following remote instance
|
- Added following remote instance
|
||||||
|
- Added set note of followed users
|
|
@ -1,2 +1,3 @@
|
||||||
toooting愉快!此版本包括以下改进和修复:
|
toooting愉快!此版本包括以下改进和修复:
|
||||||
- 新增关注远程实例功能
|
- 新增关注远程实例功能
|
||||||
|
- 新增关注用户备注功能
|
|
@ -29,20 +29,20 @@ const RelationshipOutgoing: React.FC<Props> = ({ id }: Props) => {
|
||||||
const queryKeyRelationship: QueryKeyRelationship = ['Relationship', { id }]
|
const queryKeyRelationship: QueryKeyRelationship = ['Relationship', { id }]
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const mutation = useRelationshipMutation({
|
const mutation = useRelationshipMutation({
|
||||||
onSuccess: (res, { payload: { action } }) => {
|
onSuccess: (res, vars) => {
|
||||||
haptics('Success')
|
haptics('Success')
|
||||||
queryClient.setQueryData<Mastodon.Relationship[]>(queryKeyRelationship, [res])
|
queryClient.setQueryData<Mastodon.Relationship[]>(queryKeyRelationship, [res])
|
||||||
if (action === 'block') {
|
if (vars.type === 'outgoing' && vars.payload.action === 'block') {
|
||||||
const queryKey = ['Timeline', { page: 'Following' }]
|
const queryKey = ['Timeline', { page: 'Following' }]
|
||||||
queryClient.invalidateQueries({ queryKey, exact: false })
|
queryClient.invalidateQueries({ queryKey, exact: false })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError: (err: any, { payload: { action } }) => {
|
onError: (err: any, vars) => {
|
||||||
displayMessage({
|
displayMessage({
|
||||||
theme,
|
theme,
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: t('common:message.error.message', {
|
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 &&
|
...(err.status &&
|
||||||
typeof err.status === 'number' &&
|
typeof err.status === 'number' &&
|
||||||
|
|
|
@ -105,21 +105,21 @@ const menuAccount = ({
|
||||||
})
|
})
|
||||||
const queryKeyRelationship: QueryKeyRelationship = ['Relationship', { id: actualAccount?.id }]
|
const queryKeyRelationship: QueryKeyRelationship = ['Relationship', { id: actualAccount?.id }]
|
||||||
const relationshipMutation = useRelationshipMutation({
|
const relationshipMutation = useRelationshipMutation({
|
||||||
onSuccess: (res, { payload: { action } }) => {
|
onSuccess: (res, vars) => {
|
||||||
haptics('Success')
|
haptics('Success')
|
||||||
queryClient.setQueryData<Mastodon.Relationship[]>(queryKeyRelationship, [res])
|
queryClient.setQueryData<Mastodon.Relationship[]>(queryKeyRelationship, [res])
|
||||||
if (action === 'block') {
|
if (vars.type === 'outgoing' && vars.payload.action === 'block') {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ['Timeline', { page: 'Following' }],
|
queryKey: ['Timeline', { page: 'Following' }],
|
||||||
exact: false
|
exact: false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError: (err: any, { payload: { action } }) => {
|
onError: (err: any, vars) => {
|
||||||
displayMessage({
|
displayMessage({
|
||||||
type: 'danger',
|
type: 'danger',
|
||||||
message: t('common:message.error.message', {
|
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 &&
|
...(err.status &&
|
||||||
typeof err.status === 'number' &&
|
typeof err.status === 'number' &&
|
||||||
|
|
|
@ -386,6 +386,7 @@
|
||||||
"accessibilityHint": "You can mute, block, report or share this user"
|
"accessibilityHint": "You can mute, block, report or share this user"
|
||||||
},
|
},
|
||||||
"followed_by": " is following you",
|
"followed_by": " is following you",
|
||||||
|
"privateNote": "Set private note",
|
||||||
"moved": "User moved",
|
"moved": "User moved",
|
||||||
"created_at": "Joined: {{date}}",
|
"created_at": "Joined: {{date}}",
|
||||||
"summary": {
|
"summary": {
|
||||||
|
|
|
@ -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 { StyleConstants } from '@utils/styles/constants'
|
||||||
|
import layoutAnimation from '@utils/styles/layoutAnimation'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import React, { useContext } from 'react'
|
import React, { useContext, useState } from 'react'
|
||||||
import { View } from 'react-native'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { Pressable, TextInput, View } from 'react-native'
|
||||||
import AccountContext from '../Context'
|
import AccountContext from '../Context'
|
||||||
|
|
||||||
const AccountInformationPrivateNote: React.FC = () => {
|
const AccountInformationPrivateNote: React.FC = () => {
|
||||||
const { relationship, pageMe } = useContext(AccountContext)
|
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<Mastodon.Relationship[]>(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 ? (
|
||||||
<View
|
<View
|
||||||
|
style={{
|
||||||
|
marginBottom: StyleConstants.Spacing.L,
|
||||||
|
padding: StyleConstants.Spacing.Global.PagePadding,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderRadius: StyleConstants.BorderRadius,
|
||||||
|
borderColor: colors.border
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TextInput
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
borderBottomWidth: 1,
|
||||||
|
...StyleConstants.FontStyle.M,
|
||||||
|
color: colors.primaryDefault,
|
||||||
|
borderBottomColor: colors.border,
|
||||||
|
paddingVertical: StyleConstants.Spacing.S
|
||||||
|
}}
|
||||||
|
value={notes}
|
||||||
|
onChangeText={setNotes}
|
||||||
|
multiline
|
||||||
|
textAlignVertical='top'
|
||||||
|
clearButtonMode='never'
|
||||||
|
onSubmitEditing={() => submit()}
|
||||||
|
placeholder={t('screenTabs:shared.account.privateNote')}
|
||||||
|
placeholderTextColor={colors.secondary}
|
||||||
|
returnKeyType='done'
|
||||||
|
keyboardAppearance={mode}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'flex-end',
|
||||||
|
marginTop: StyleConstants.Spacing.M,
|
||||||
|
gap: StyleConstants.Spacing.S
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
type='text'
|
||||||
|
content={t('common:buttons.cancel')}
|
||||||
|
onPress={() => {
|
||||||
|
discardConfirmation({
|
||||||
|
condition: notes != relationship?.note,
|
||||||
|
action: () => {
|
||||||
|
setEditing(false)
|
||||||
|
layoutAnimation()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button type='text' content={t('common:buttons.confirm')} onPress={() => submit()} />
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<Pressable
|
||||||
style={{
|
style={{
|
||||||
marginBottom: StyleConstants.Spacing.L,
|
marginBottom: StyleConstants.Spacing.L,
|
||||||
borderLeftColor: colors.border,
|
borderLeftColor: colors.border,
|
||||||
borderLeftWidth: StyleConstants.Spacing.XS,
|
borderLeftWidth: StyleConstants.Spacing.XS,
|
||||||
paddingLeft: StyleConstants.Spacing.S
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center'
|
||||||
|
}}
|
||||||
|
onPress={() => {
|
||||||
|
setEditing(!editing)
|
||||||
|
layoutAnimation()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ParseHTML content={relationship.note} size={'S'} selectable numberOfLines={2} />
|
{!!relationship?.note.length ? (
|
||||||
</View>
|
<CustomText
|
||||||
|
fontSize='S'
|
||||||
|
style={{
|
||||||
|
color: colors.primaryDefault,
|
||||||
|
paddingHorizontal: StyleConstants.Spacing.S,
|
||||||
|
flexShrink: 1
|
||||||
|
}}
|
||||||
|
children={relationship.note}
|
||||||
|
selectable
|
||||||
|
numberOfLines={2}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<CustomText
|
||||||
|
fontSize='S'
|
||||||
|
style={{
|
||||||
|
color: colors.secondary,
|
||||||
|
paddingHorizontal: StyleConstants.Spacing.S,
|
||||||
|
flexShrink: 1
|
||||||
|
}}
|
||||||
|
children={t('screenTabs:shared.account.privateNote')}
|
||||||
|
selectable
|
||||||
|
numberOfLines={2}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<Icon name='edit' size={StyleConstants.Font.Size.M} color={colors.secondary} />
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,11 @@ type MutationVarsRelationship =
|
||||||
notify?: boolean
|
notify?: boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
| {
|
||||||
|
id: Mastodon.Account['id']
|
||||||
|
type: 'note'
|
||||||
|
payload: Mastodon.Relationship['note']
|
||||||
|
}
|
||||||
|
|
||||||
const mutationFunction = async (params: MutationVarsRelationship) => {
|
const mutationFunction = async (params: MutationVarsRelationship) => {
|
||||||
switch (params.type) {
|
switch (params.type) {
|
||||||
|
@ -83,11 +88,17 @@ const mutationFunction = async (params: MutationVarsRelationship) => {
|
||||||
url: `accounts/${params.id}/${params.payload.state ? 'un' : ''}${params.payload.action}`,
|
url: `accounts/${params.id}/${params.payload.state ? 'un' : ''}${params.payload.action}`,
|
||||||
body
|
body
|
||||||
}).then(res => res.body)
|
}).then(res => res.body)
|
||||||
|
case 'note':
|
||||||
|
return apiInstance<Mastodon.Relationship>({
|
||||||
|
method: 'post',
|
||||||
|
url: `accounts/${params.id}/note`,
|
||||||
|
body: { comment: params.payload }
|
||||||
|
}).then(res => res.body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const useRelationshipMutation = (
|
const useRelationshipMutation = (
|
||||||
options: UseMutationOptions<Mastodon.Relationship, AxiosError, MutationVarsRelationship>
|
options?: UseMutationOptions<Mastodon.Relationship, AxiosError, MutationVarsRelationship>
|
||||||
) => {
|
) => {
|
||||||
return useMutation(mutationFunction, options)
|
return useMutation(mutationFunction, options)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue