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

* Refactor condition nesting by screen

* Inline indexes

* More explicit conditions
This commit is contained in:
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

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,74 +444,84 @@ function Footer({
))} ))}
</View> </View>
{items.length === 0 /* Assuming this can only happen for feeds */ ? ( {
state.currentStep === 'Profiles' ? (
<Text style={[a.text_center, textStyles]}>
{
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>
) : state.currentStep === 'Feeds' ? (
items.length === 0 ? (
<View style={[a.gap_sm]}> <View style={[a.gap_sm]}>
<Text style={[a.font_bold, a.text_center, textStyles]}> <Text style={[a.font_bold, a.text_center, textStyles]}>
<Trans>Add some feeds to your starter pack!</Trans> <Trans>Add some feeds to your starter pack!</Trans>
</Text> </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> <Trans>
Search for feeds that you want to suggest to others.
</Trans>
</Text> </Text>
</View> </View>
) : ( ) : (
<Text style={[a.text_center, textStyles]}> <Text style={[a.text_center, textStyles]}>
{ {
items.length === 1 && state.currentStep === 'Profiles' ? ( items.length === 1 ? (
<Trans>
It's just you right now! Add more people to your starter pack by
searching above.
</Trans>
) : items.length === 1 && state.currentStep === 'Feeds' ? (
<Trans> <Trans>
<Text style={[a.font_bold, textStyles]}> <Text style={[a.font_bold, textStyles]}>
{getName(items[initialNamesIndex])} {getName(items[0])}
</Text>{' '} </Text>{' '}
is included in your starter pack is included in your starter pack
</Trans> </Trans>
) : items.length === 2 && state.currentStep === 'Profiles' ? ( ) : items.length === 2 ? (
<Trans>
<Text style={[a.font_bold, textStyles]}>You</Text> and
<Text> </Text>
<Text style={[a.font_bold, textStyles]}>
{getName(items[initialNamesIndex])}{' '}
</Text>
are included in your starter pack
</Trans>
) : items.length === 2 && state.currentStep === 'Feeds' ? (
<Trans> <Trans>
<Text style={[a.font_bold, textStyles]}> <Text style={[a.font_bold, textStyles]}>
{getName(items[initialNamesIndex])} {getName(items[0])}
</Text>{' '} </Text>{' '}
and and
<Text> </Text> <Text> </Text>
<Text style={[a.font_bold, textStyles]}> <Text style={[a.font_bold, textStyles]}>
{getName(items[initialNamesIndex + 1])}{' '} {getName(items[1])}{' '}
</Text> </Text>
are included in your starter pack are included in your starter pack
</Trans> </Trans>
) : items.length > 2 && state.currentStep === 'Profiles' ? ( ) : items.length > 2 ? (
<Trans context="profiles">
<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>
) : items.length > 2 && state.currentStep === 'Feeds' ? (
<Trans context="feeds"> <Trans context="feeds">
<Text style={[a.font_bold, textStyles]}> <Text style={[a.font_bold, textStyles]}>
{getName(items[initialNamesIndex])},{' '} {getName(items[0])},{' '}
</Text> </Text>
<Text style={[a.font_bold, textStyles]}> <Text style={[a.font_bold, textStyles]}>
{getName(items[initialNamesIndex + 1])},{' '} {getName(items[1])},{' '}
</Text> </Text>
and{' '} and{' '}
<Plural <Plural
@ -522,10 +531,12 @@ function Footer({
/>{' '} />{' '}
are included in your starter pack are included in your starter pack
</Trans> </Trans>
) : null /* Should not happen */ ) : null /* Should not happen. */
} }
</Text> </Text>
)} )
) : null /* Should not happen. */
}
<View <View
style={[ style={[