mirror of
https://github.com/tooot-app/app
synced 2024-12-22 07:34:06 +01:00
Update PrivateNotes.tsx
This commit is contained in:
parent
292fb42a22
commit
f505f78193
@ -14,7 +14,6 @@ import AccountContext from '../Context'
|
||||
|
||||
const AccountInformationPrivateNote: React.FC = () => {
|
||||
const { relationship, pageMe } = useContext(AccountContext)
|
||||
if (!relationship || pageMe) return null
|
||||
|
||||
const { colors, mode } = useTheme()
|
||||
const { t } = useTranslation(['common', 'screenTabs'])
|
||||
@ -22,14 +21,14 @@ const AccountInformationPrivateNote: React.FC = () => {
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [notes, setNotes] = useState(relationship?.note)
|
||||
|
||||
const queryKey: QueryKeyRelationship = ['Relationship', { id: relationship.id }]
|
||||
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.map(o => (o.id === relationship?.id && notes ? { ...o, note: notes } : o))
|
||||
: old
|
||||
: undefined
|
||||
})
|
||||
@ -39,11 +38,15 @@ const AccountInformationPrivateNote: React.FC = () => {
|
||||
}
|
||||
})
|
||||
const submit = () => {
|
||||
mutation.mutate({ id: relationship.id, type: 'note', payload: notes || '' })
|
||||
setEditing(!editing)
|
||||
layoutAnimation()
|
||||
if (relationship) {
|
||||
mutation.mutate({ id: relationship.id, type: 'note', payload: notes || '' })
|
||||
setEditing(!editing)
|
||||
layoutAnimation()
|
||||
}
|
||||
}
|
||||
|
||||
if (!relationship || pageMe) return null
|
||||
|
||||
return relationship?.following ? (
|
||||
editing ? (
|
||||
<View
|
||||
|
Loading…
Reference in New Issue
Block a user