Fix toggles

This commit is contained in:
Eric Bailey
2024-02-15 09:53:29 -06:00
parent 4d8b4cf6f7
commit 16db93d8f9
2 changed files with 6 additions and 8 deletions
+2 -4
View File
@@ -24,8 +24,7 @@ function LabelerToggle({
preferences: UsePreferencesQueryResponse preferences: UsePreferencesQueryResponse
}) { }) {
const t = useTheme() const t = useTheme()
const {mutateAsync, variables, reset} = const {mutateAsync, variables} = useModServiceLabelGroupEnableMutation()
useModServiceLabelGroupEnableMutation()
const modservicePreferences = preferences.moderationOpts.mods.find( const modservicePreferences = preferences.moderationOpts.mods.find(
({did}) => did === labeler.creator.did, ({did}) => did === labeler.creator.did,
@@ -46,12 +45,11 @@ function LabelerToggle({
group: labelGroup, group: labelGroup,
enabled: !enabled, enabled: !enabled,
}) })
reset() // Important: clears query `variables`
} catch (e: any) { } catch (e: any) {
// TODO // TODO
console.error(e) console.error(e)
} }
}, [mutateAsync, enabled, modservicePreferences, labelGroup, reset]) }, [mutateAsync, enabled, modservicePreferences, labelGroup])
return ( return (
<Toggle.Item <Toggle.Item
name={labeler.creator.did} name={labeler.creator.did}
@@ -1,6 +1,7 @@
import React from 'react' import React from 'react'
import {View} from 'react-native' import {View} from 'react-native'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {msg} from '@lingui/macro'
// import {msg} from '@lingui/macro' // import {msg} from '@lingui/macro'
import {LABEL_GROUPS} from '@atproto/api' import {LABEL_GROUPS} from '@atproto/api'
// TODO // TODO
@@ -24,7 +25,7 @@ export function PreferenceRow({
const {_} = useLingui() const {_} = useLingui()
const labelGroupStrings = useLabelGroupStrings() const labelGroupStrings = useLabelGroupStrings()
const groupInfoStrings = labelGroupStrings[labelGroup] const groupInfoStrings = labelGroupStrings[labelGroup]
const {mutateAsync, variables, reset} = useModServiceLabelGroupEnableMutation() const {mutateAsync, variables} = useModServiceLabelGroupEnableMutation()
const enabled = const enabled =
variables?.enabled ?? variables?.enabled ??
!modservicePreferences?.disabledLabelGroups?.includes(labelGroup) !modservicePreferences?.disabledLabelGroups?.includes(labelGroup)
@@ -37,12 +38,11 @@ export function PreferenceRow({
group: labelGroup, group: labelGroup,
enabled: !enabled, enabled: !enabled,
}) })
reset() // Important: clears query `variables`
} catch (e: any) { } catch (e: any) {
// TODO // TODO
console.error(e) console.error(e)
} }
}, [mutateAsync, enabled, modservicePreferences, labelGroup, reset]) }, [mutateAsync, enabled, modservicePreferences, labelGroup])
return ( return (
<View <View
@@ -65,7 +65,7 @@ export function PreferenceRow({
name="enable" name="enable"
value={enabled} value={enabled}
onChange={onToggleEnabled} onChange={onToggleEnabled}
label="Enable"> label={_(msg`Enable`)}>
<Toggle.Label>{enabled ? 'Enabled' : 'Disabled'}</Toggle.Label> <Toggle.Label>{enabled ? 'Enabled' : 'Disabled'}</Toggle.Label>
<Toggle.Switch /> <Toggle.Switch />
</Toggle.Item> </Toggle.Item>