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