mirror of
https://github.com/tooot-app/app
synced 2025-01-03 13:10:23 +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 AccountInformationPrivateNote: React.FC = () => {
|
||||||
const { relationship, pageMe } = useContext(AccountContext)
|
const { relationship, pageMe } = useContext(AccountContext)
|
||||||
if (!relationship || pageMe) return null
|
|
||||||
|
|
||||||
const { colors, mode } = useTheme()
|
const { colors, mode } = useTheme()
|
||||||
const { t } = useTranslation(['common', 'screenTabs'])
|
const { t } = useTranslation(['common', 'screenTabs'])
|
||||||
@ -22,14 +21,14 @@ const AccountInformationPrivateNote: React.FC = () => {
|
|||||||
const [editing, setEditing] = useState(false)
|
const [editing, setEditing] = useState(false)
|
||||||
const [notes, setNotes] = useState(relationship?.note)
|
const [notes, setNotes] = useState(relationship?.note)
|
||||||
|
|
||||||
const queryKey: QueryKeyRelationship = ['Relationship', { id: relationship.id }]
|
const queryKey: QueryKeyRelationship = ['Relationship', { id: relationship?.id }]
|
||||||
const mutation = useRelationshipMutation({
|
const mutation = useRelationshipMutation({
|
||||||
onMutate: async vars => {
|
onMutate: async vars => {
|
||||||
await queryClient.cancelQueries({ queryKey })
|
await queryClient.cancelQueries({ queryKey })
|
||||||
queryClient.setQueryData<Mastodon.Relationship[]>(queryKey, old => {
|
queryClient.setQueryData<Mastodon.Relationship[]>(queryKey, old => {
|
||||||
return old
|
return old
|
||||||
? vars.type === 'note'
|
? 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
|
: old
|
||||||
: undefined
|
: undefined
|
||||||
})
|
})
|
||||||
@ -39,10 +38,14 @@ const AccountInformationPrivateNote: React.FC = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
const submit = () => {
|
const submit = () => {
|
||||||
|
if (relationship) {
|
||||||
mutation.mutate({ id: relationship.id, type: 'note', payload: notes || '' })
|
mutation.mutate({ id: relationship.id, type: 'note', payload: notes || '' })
|
||||||
setEditing(!editing)
|
setEditing(!editing)
|
||||||
layoutAnimation()
|
layoutAnimation()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!relationship || pageMe) return null
|
||||||
|
|
||||||
return relationship?.following ? (
|
return relationship?.following ? (
|
||||||
editing ? (
|
editing ? (
|
||||||
|
Loading…
Reference in New Issue
Block a user