about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-06-26 16:08:57 +0100
committerGitHub <noreply@github.com>2024-06-26 16:08:57 +0100
commit3f20e2e3cf086664cb764da2b2886eac8b409270 (patch)
tree1229079389b24a3482f17643841dfec2e948f38a /src
parent83745c923fc0d660730f47c81159ce9b6942f616 (diff)
downloadvoidsky-3f20e2e3cf086664cb764da2b2886eac8b409270.tar.zst
Refactor nested conditions in the starter pack wizard (#4652)
* Refactor condition nesting by screen

* Inline indexes

* More explicit conditions
Diffstat (limited to 'src')
-rw-r--r--src/screens/StarterPack/Wizard/index.tsx171
1 files changed, 91 insertions, 80 deletions
diff --git a/src/screens/StarterPack/Wizard/index.tsx b/src/screens/StarterPack/Wizard/index.tsx
index 2f50e878a..3f0499a1d 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={[