Update PrivateNotes.tsx

This commit is contained in:
xmflsct 2023-02-25 22:24:23 +01:00
parent 292fb42a22
commit f505f78193
1 changed files with 9 additions and 6 deletions

View File

@ -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,11 +38,15 @@ const AccountInformationPrivateNote: React.FC = () => {
} }
}) })
const submit = () => { const submit = () => {
mutation.mutate({ id: relationship.id, type: 'note', payload: notes || '' }) if (relationship) {
setEditing(!editing) mutation.mutate({ id: relationship.id, type: 'note', payload: notes || '' })
layoutAnimation() setEditing(!editing)
layoutAnimation()
}
} }
if (!relationship || pageMe) return null
return relationship?.following ? ( return relationship?.following ? (
editing ? ( editing ? (
<View <View