Use asPredicate
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import {$Typed, ComAtprotoLabelDefs} from '@atproto/api'
|
import {$Typed, asPredicate,ComAtprotoLabelDefs} from '@atproto/api'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
@@ -33,13 +33,14 @@ export function PwiOptOut() {
|
|||||||
profile,
|
profile,
|
||||||
updates: existing => {
|
updates: existing => {
|
||||||
// create labels attr if needed
|
// create labels attr if needed
|
||||||
const labels: $Typed<ComAtprotoLabelDefs.SelfLabels> =
|
const labels: $Typed<ComAtprotoLabelDefs.SelfLabels> = asPredicate(
|
||||||
ComAtprotoLabelDefs.isValidSelfLabels(existing.labels)
|
ComAtprotoLabelDefs.validateSelfLabels,
|
||||||
? existing.labels
|
)(existing.labels)
|
||||||
: {
|
? existing.labels
|
||||||
$type: 'com.atproto.label.defs#selfLabels',
|
: {
|
||||||
values: [],
|
$type: 'com.atproto.label.defs#selfLabels',
|
||||||
}
|
values: [],
|
||||||
|
}
|
||||||
|
|
||||||
// toggle the label
|
// toggle the label
|
||||||
const hasLabel = labels.values.some(
|
const hasLabel = labels.values.some(
|
||||||
|
|||||||
Reference in New Issue
Block a user