Align starter pack opt-out with AppView state
This commit is contained in:
@@ -665,22 +665,24 @@ function OverflowMenu({
|
||||
</Menu.ItemText>
|
||||
<Menu.ItemIcon icon={CircleInfo} position="right" />
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
label={
|
||||
referenceListOptOut
|
||||
? _(msg`Undo opt-out from starter pack`)
|
||||
: _(msg`Opt out of starter pack`)
|
||||
}
|
||||
disabled={isOptOutPending}
|
||||
onPress={() => optOutDialogControl.open()}>
|
||||
<Menu.ItemText>
|
||||
{referenceListOptOut ? (
|
||||
<Trans>Undo opt-out</Trans>
|
||||
) : (
|
||||
<Trans>Opt out of starter pack</Trans>
|
||||
)}
|
||||
</Menu.ItemText>
|
||||
</Menu.Item>
|
||||
{starterPack.list ? (
|
||||
<Menu.Item
|
||||
label={
|
||||
referenceListOptOut
|
||||
? _(msg`Undo opt-out from starter pack`)
|
||||
: _(msg`Opt out of starter pack`)
|
||||
}
|
||||
disabled={isOptOutPending}
|
||||
onPress={() => optOutDialogControl.open()}>
|
||||
<Menu.ItemText>
|
||||
{referenceListOptOut ? (
|
||||
<Trans>Undo opt-out</Trans>
|
||||
) : (
|
||||
<Trans>Opt out of starter pack</Trans>
|
||||
)}
|
||||
</Menu.ItemText>
|
||||
</Menu.Item>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</Menu.Outer>
|
||||
@@ -740,51 +742,53 @@ function OverflowMenu({
|
||||
</Prompt.Actions>
|
||||
</Prompt.Outer>
|
||||
|
||||
<Prompt.Outer control={optOutDialogControl}>
|
||||
<Prompt.TitleText>
|
||||
{referenceListOptOut ? (
|
||||
<Trans>Undo opt-out?</Trans>
|
||||
) : (
|
||||
<Trans>Opt out of this starter pack?</Trans>
|
||||
)}
|
||||
</Prompt.TitleText>
|
||||
<Prompt.DescriptionText>
|
||||
{referenceListOptOut ? (
|
||||
<Trans>You will appear in this starter pack again.</Trans>
|
||||
) : (
|
||||
<Trans>
|
||||
You will no longer appear in this starter pack. The creator can
|
||||
still remove you from its member list.
|
||||
</Trans>
|
||||
)}
|
||||
</Prompt.DescriptionText>
|
||||
<Prompt.Actions>
|
||||
<Button
|
||||
variant="solid"
|
||||
color={referenceListOptOut ? 'primary' : 'negative'}
|
||||
size={gtMobile ? 'small' : 'large'}
|
||||
label={
|
||||
referenceListOptOut
|
||||
? _(msg`Undo opt-out`)
|
||||
: _(msg`Opt out of starter pack`)
|
||||
}
|
||||
disabled={isOptOutPending}
|
||||
onPress={() => {
|
||||
optOutDialogControl.close()
|
||||
setReferenceListOptOut({referenceListOptOut})
|
||||
}}>
|
||||
<ButtonText>
|
||||
{referenceListOptOut ? (
|
||||
<Trans>Undo opt-out</Trans>
|
||||
) : (
|
||||
<Trans>Opt out</Trans>
|
||||
)}
|
||||
</ButtonText>
|
||||
{isOptOutPending && <ButtonIcon icon={Loader} />}
|
||||
</Button>
|
||||
<Prompt.Cancel />
|
||||
</Prompt.Actions>
|
||||
</Prompt.Outer>
|
||||
{starterPack.list ? (
|
||||
<Prompt.Outer control={optOutDialogControl}>
|
||||
<Prompt.TitleText>
|
||||
{referenceListOptOut ? (
|
||||
<Trans>Undo opt-out?</Trans>
|
||||
) : (
|
||||
<Trans>Opt out of this starter pack?</Trans>
|
||||
)}
|
||||
</Prompt.TitleText>
|
||||
<Prompt.DescriptionText>
|
||||
{referenceListOptOut ? (
|
||||
<Trans>You will appear in this starter pack again.</Trans>
|
||||
) : (
|
||||
<Trans>
|
||||
You will no longer appear in this starter pack. The creator can
|
||||
still remove you from its member list.
|
||||
</Trans>
|
||||
)}
|
||||
</Prompt.DescriptionText>
|
||||
<Prompt.Actions>
|
||||
<Button
|
||||
variant="solid"
|
||||
color={referenceListOptOut ? 'primary' : 'negative'}
|
||||
size={gtMobile ? 'small' : 'large'}
|
||||
label={
|
||||
referenceListOptOut
|
||||
? _(msg`Undo opt-out`)
|
||||
: _(msg`Opt out of starter pack`)
|
||||
}
|
||||
disabled={isOptOutPending}
|
||||
onPress={() => {
|
||||
optOutDialogControl.close()
|
||||
setReferenceListOptOut({referenceListOptOut})
|
||||
}}>
|
||||
<ButtonText>
|
||||
{referenceListOptOut ? (
|
||||
<Trans>Undo opt-out</Trans>
|
||||
) : (
|
||||
<Trans>Opt out</Trans>
|
||||
)}
|
||||
</ButtonText>
|
||||
{isOptOutPending && <ButtonIcon icon={Loader} />}
|
||||
</Button>
|
||||
<Prompt.Cancel />
|
||||
</Prompt.Actions>
|
||||
</Prompt.Outer>
|
||||
) : null}
|
||||
|
||||
<CreateListFromStarterPackDialog
|
||||
control={convertToListDialogControl}
|
||||
|
||||
@@ -113,17 +113,30 @@ export function useReferenceListOptOutMutation({
|
||||
nextOptOut = result.uri
|
||||
}
|
||||
|
||||
let didReadViewerState = false
|
||||
await until(
|
||||
5,
|
||||
1e3,
|
||||
(value, error) =>
|
||||
!error &&
|
||||
value.starterPack.list?.viewer?.referenceListOptOut === nextOptOut,
|
||||
(value, error) => {
|
||||
if (error) return false
|
||||
|
||||
didReadViewerState = true
|
||||
nextOptOut = value.starterPack.list?.viewer?.referenceListOptOut
|
||||
|
||||
// AppView ignores duplicate records and continues to expose the URI
|
||||
// of the record it indexed first. Treat that viewer state as the
|
||||
// source of truth instead of waiting for the newly-created URI.
|
||||
return referenceListOptOut ? !nextOptOut : Boolean(nextOptOut)
|
||||
},
|
||||
async () =>
|
||||
await appviewClient.call(app.bsky.graph.getStarterPack, {
|
||||
starterPack: starterPack.uri,
|
||||
}),
|
||||
)
|
||||
|
||||
if (!didReadViewerState) {
|
||||
throw new Error('Unable to read starter pack opt-out state')
|
||||
}
|
||||
return nextOptOut
|
||||
},
|
||||
onMutate: async ({referenceListOptOut}) => {
|
||||
|
||||
Reference in New Issue
Block a user