From 3f20e2e3cf086664cb764da2b2886eac8b409270 Mon Sep 17 00:00:00 2001
From: dan <dan.abramov@gmail.com>
Date: Wed, 26 Jun 2024 16:08:57 +0100
Subject: [PATCH] Refactor nested conditions in the starter pack wizard (#4652)

* Refactor condition nesting by screen

* Inline indexes

* More explicit conditions
---
 src/screens/StarterPack/Wizard/index.tsx | 171 ++++++++++++-----------
 1 file changed, 91 insertions(+), 80 deletions(-)

diff --git a/src/screens/StarterPack/Wizard/index.tsx b/src/screens/StarterPack/Wizard/index.tsx
index 2f50e878..3f0499a1 100644
--- a/src/screens/StarterPack/Wizard/index.tsx
+++ b/src/screens/StarterPack/Wizard/index.tsx
@@ -393,7 +393,6 @@ function Footer({
     state.currentStep === 'Profiles'
       ? [profile, ...state.profiles]
       : state.feeds
-  const initialNamesIndex = state.currentStep === 'Profiles' ? 1 : 0
 
   const isEditEnabled =
     (state.currentStep === 'Profiles' && items.length > 1) ||
@@ -445,87 +444,99 @@ function Footer({
         ))}
       </View>
 
-      {items.length === 0 /* Assuming this can only happen for feeds */ ? (
-        <View style={[a.gap_sm]}>
-          <Text style={[a.font_bold, a.text_center, textStyles]}>
-            <Trans>Add some feeds to your starter pack!</Trans>
-          </Text>
+      {
+        state.currentStep === 'Profiles' ? (
           <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>
-        </View>
-      ) : (
-        <Text style={[a.text_center, textStyles]}>
-          {
-            items.length === 1 && state.currentStep === 'Profiles' ? (
-              <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>
-                <Text style={[a.font_bold, textStyles]}>
-                  {getName(items[initialNamesIndex])}
-                </Text>{' '}
-                is included in your starter pack
-              </Trans>
-            ) : items.length === 2 && state.currentStep === 'Profiles' ? (
-              <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>
-                <Text style={[a.font_bold, textStyles]}>
-                  {getName(items[initialNamesIndex])}
-                </Text>{' '}
-                and
-                <Text> </Text>
-                <Text style={[a.font_bold, textStyles]}>
-                  {getName(items[initialNamesIndex + 1])}{' '}
-                </Text>
-                are included in your starter pack
-              </Trans>
-            ) : items.length > 2 && state.currentStep === 'Profiles' ? (
-              <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">
-                <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>
-      )}
+        ) : state.currentStep === 'Feeds' ? (
+          items.length === 0 ? (
+            <View style={[a.gap_sm]}>
+              <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]}>
+                <Trans>
+                  Search for feeds that you want to suggest to others.
+                </Trans>
+              </Text>
+            </View>
+          ) : (
+            <Text style={[a.text_center, textStyles]}>
+              {
+                items.length === 1 ? (
+                  <Trans>
+                    <Text style={[a.font_bold, textStyles]}>
+                      {getName(items[0])}
+                    </Text>{' '}
+                    is included in your starter pack
+                  </Trans>
+                ) : items.length === 2 ? (
+                  <Trans>
+                    <Text style={[a.font_bold, textStyles]}>
+                      {getName(items[0])}
+                    </Text>{' '}
+                    and
+                    <Text> </Text>
+                    <Text style={[a.font_bold, textStyles]}>
+                      {getName(items[1])}{' '}
+                    </Text>
+                    are included in your starter pack
+                  </Trans>
+                ) : items.length > 2 ? (
+                  <Trans context="feeds">
+                    <Text style={[a.font_bold, textStyles]}>
+                      {getName(items[0])},{' '}
+                    </Text>
+                    <Text style={[a.font_bold, textStyles]}>
+                      {getName(items[1])},{' '}
+                    </Text>
+                    and{' '}
+                    <Plural
+                      value={items.length - 2}
+                      one="# other"
+                      other="# others"
+                    />{' '}
+                    are included in your starter pack
+                  </Trans>
+                ) : null /* Should not happen. */
+              }
+            </Text>
+          )
+        ) : null /* Should not happen. */
+      }
 
       <View
         style={[