Refactor nested conditions in the starter pack wizard (#4652)

* Refactor condition nesting by screen

* Inline indexes

* More explicit conditions
zio/stable
dan 2024-06-26 16:08:57 +01:00 committed by GitHub
parent 83745c923f
commit 3f20e2e3cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 91 additions and 80 deletions

View File

@ -393,7 +393,6 @@ function Footer({
state.currentStep === 'Profiles' state.currentStep === 'Profiles'
? [profile, ...state.profiles] ? [profile, ...state.profiles]
: state.feeds : state.feeds
const initialNamesIndex = state.currentStep === 'Profiles' ? 1 : 0
const isEditEnabled = const isEditEnabled =
(state.currentStep === 'Profiles' && items.length > 1) || (state.currentStep === 'Profiles' && items.length > 1) ||
@ -445,87 +444,99 @@ function Footer({
))} ))}
</View> </View>
{items.length === 0 /* Assuming this can only happen for feeds */ ? ( {
<View style={[a.gap_sm]}> state.currentStep === 'Profiles' ? (
<Text style={[a.font_bold, a.text_center, textStyles]}>
<Trans>Add some feeds to your starter pack!</Trans>
</Text>
<Text style={[a.text_center, textStyles]}> <Text style={[a.text_center, textStyles]}>
<Trans>Search for feeds that you want to suggest to others.</Trans> {
items.length < 2 ? (
<Trans>
It's just you right now! Add more people to your starter pack
by searching above.
</Trans>
) : items.length === 2 ? (
<Trans>
<Text style={[a.font_bold, textStyles]}>You</Text> and
<Text> </Text>
<Text style={[a.font_bold, textStyles]}>
{getName(items[1] /* [0] is self, skip it */)}{' '}
</Text>
are included in your starter pack
</Trans>
) : items.length > 2 ? (
<Trans context="profiles">
<Text style={[a.font_bold, textStyles]}>
{getName(items[1] /* [0] is self, skip it */)},{' '}
</Text>
<Text style={[a.font_bold, textStyles]}>
{getName(items[2])},{' '}
</Text>
and{' '}
<Plural
value={items.length - 2}
one="# other"
other="# others"
/>{' '}
are included in your starter pack
</Trans>
) : null /* Should not happen. */
}
</Text> </Text>
</View> ) : state.currentStep === 'Feeds' ? (
) : ( items.length === 0 ? (
<Text style={[a.text_center, textStyles]}> <View style={[a.gap_sm]}>
{ <Text style={[a.font_bold, a.text_center, textStyles]}>
items.length === 1 && state.currentStep === 'Profiles' ? ( <Trans>Add some feeds to your starter pack!</Trans>
<Trans> </Text>
It's just you right now! Add more people to your starter pack by <Text style={[a.text_center, textStyles]}>
searching above. <Trans>
</Trans> Search for feeds that you want to suggest to others.
) : items.length === 1 && state.currentStep === 'Feeds' ? ( </Trans>
<Trans> </Text>
<Text style={[a.font_bold, textStyles]}> </View>
{getName(items[initialNamesIndex])} ) : (
</Text>{' '} <Text style={[a.text_center, textStyles]}>
is included in your starter pack {
</Trans> items.length === 1 ? (
) : items.length === 2 && state.currentStep === 'Profiles' ? ( <Trans>
<Trans> <Text style={[a.font_bold, textStyles]}>
<Text style={[a.font_bold, textStyles]}>You</Text> and {getName(items[0])}
<Text> </Text> </Text>{' '}
<Text style={[a.font_bold, textStyles]}> is included in your starter pack
{getName(items[initialNamesIndex])}{' '} </Trans>
</Text> ) : items.length === 2 ? (
are included in your starter pack <Trans>
</Trans> <Text style={[a.font_bold, textStyles]}>
) : items.length === 2 && state.currentStep === 'Feeds' ? ( {getName(items[0])}
<Trans> </Text>{' '}
<Text style={[a.font_bold, textStyles]}> and
{getName(items[initialNamesIndex])} <Text> </Text>
</Text>{' '} <Text style={[a.font_bold, textStyles]}>
and {getName(items[1])}{' '}
<Text> </Text> </Text>
<Text style={[a.font_bold, textStyles]}> are included in your starter pack
{getName(items[initialNamesIndex + 1])}{' '} </Trans>
</Text> ) : items.length > 2 ? (
are included in your starter pack <Trans context="feeds">
</Trans> <Text style={[a.font_bold, textStyles]}>
) : items.length > 2 && state.currentStep === 'Profiles' ? ( {getName(items[0])},{' '}
<Trans context="profiles"> </Text>
<Text style={[a.font_bold, textStyles]}> <Text style={[a.font_bold, textStyles]}>
{getName(items[initialNamesIndex])},{' '} {getName(items[1])},{' '}
</Text> </Text>
<Text style={[a.font_bold, textStyles]}> and{' '}
{getName(items[initialNamesIndex + 1])},{' '} <Plural
</Text> value={items.length - 2}
and{' '} one="# other"
<Plural other="# others"
value={items.length - 2} />{' '}
one="# other" are included in your starter pack
other="# others" </Trans>
/>{' '} ) : null /* Should not happen. */
are included in your starter pack }
</Trans> </Text>
) : items.length > 2 && state.currentStep === 'Feeds' ? ( )
<Trans context="feeds"> ) : null /* Should not happen. */
<Text style={[a.font_bold, textStyles]}> }
{getName(items[initialNamesIndex])},{' '}
</Text>
<Text style={[a.font_bold, textStyles]}>
{getName(items[initialNamesIndex + 1])},{' '}
</Text>
and{' '}
<Plural
value={items.length - 2}
one="# other"
other="# others"
/>{' '}
are included in your starter pack
</Trans>
) : null /* Should not happen */
}
</Text>
)}
<View <View
style={[ style={[