From a7aa203c30cc49d96bdd4767ab839d631171e859 Mon Sep 17 00:00:00 2001 From: nyagami Date: Thu, 14 Mar 2024 14:24:11 +0700 Subject: [PATCH] refactor: safe ternary operator rendering --- src/components/Checkbox/Checkbox.tsx | 4 +- src/components/NovelCover.tsx | 26 ++++---- src/components/ThemePicker/ThemePicker.tsx | 4 +- src/navigators/BottomNavigator.tsx | 8 +-- .../Categories/components/CategoryCard.tsx | 4 +- .../browse/migration/MigrationNovels.tsx | 4 +- src/screens/library/LibraryScreen.tsx | 62 +++++++++---------- src/screens/more/DownloadQueueScreen.tsx | 4 +- src/screens/more/DownloadsScreen.tsx | 4 +- src/screens/novel/NovelScreen.tsx | 12 ++-- src/screens/novel/components/ChapterItem.tsx | 8 +-- .../novel/components/EditInfoModal.tsx | 4 +- .../novel/components/Info/NovelInfoHeader.tsx | 8 +-- .../components/Tracker/TrackSearchDialog.js | 4 +- src/screens/reader/ReaderScreen.tsx | 4 +- .../reader/components/ReaderFooter.tsx | 4 +- .../settings/SettingsAppearanceScreen.tsx | 4 +- .../Components/GoogleDriveModal.tsx | 4 +- .../settings/SettingsTrackerScreen.tsx | 38 ++++++------ 19 files changed, 103 insertions(+), 107 deletions(-) diff --git a/src/components/Checkbox/Checkbox.tsx b/src/components/Checkbox/Checkbox.tsx index 5972dd49c..d286a5b3b 100644 --- a/src/components/Checkbox/Checkbox.tsx +++ b/src/components/Checkbox/Checkbox.tsx @@ -71,14 +71,14 @@ export const SortItem = ({ label, status, onPress, theme }: SortItemProps) => ( style={[styles.pressable, { paddingVertical: 16, paddingLeft: 64 }]} onPress={onPress} > - {status && ( + {status ? ( - )} + ) : null} {label} ); diff --git a/src/components/NovelCover.tsx b/src/components/NovelCover.tsx index 63a68f0e2..e4ab132ed 100644 --- a/src/components/NovelCover.tsx +++ b/src/components/NovelCover.tsx @@ -103,22 +103,22 @@ function NovelCover({ > {libraryStatus && } - {showDownloadBadges && item.chaptersDownloaded > 0 && ( + {showDownloadBadges && item.chaptersDownloaded > 0 ? ( - )} - {showUnreadBadges && item.chaptersUnread > 0 && ( + ) : null} + {showUnreadBadges && item.chaptersUnread > 0 ? ( - )} + ) : null} ({ ]} /> - {displayMode === DisplayModes.Compact && ( + {displayMode === DisplayModes.Compact ? ( - )} + ) : null} - {displayMode === DisplayModes.Comfortable && ( + {displayMode === DisplayModes.Comfortable ? ( - )} + ) : null} ) : ( - ) + ) : null } unreadBadge={ - showUnreadBadges && - item.chaptersUnread && ( + showUnreadBadges && item.chaptersUnread ? ( - ) + ) : null } inLibraryBadge={libraryStatus && } theme={theme} diff --git a/src/components/ThemePicker/ThemePicker.tsx b/src/components/ThemePicker/ThemePicker.tsx index 73fb15b3f..fc0518585 100644 --- a/src/components/ThemePicker/ThemePicker.tsx +++ b/src/components/ThemePicker/ThemePicker.tsx @@ -39,7 +39,7 @@ export const ThemePicker = ({ }} > - {currentTheme.id === theme.id && ( + {currentTheme.id === theme.id ? ( - )} + ) : null} { tabBarIcon: 'book-variant-multiple', }} /> - {showUpdatesTab && ( + {showUpdatesTab ? ( { tabBarIcon: 'alert-decagram-outline', }} /> - )} - {showHistoryTab && ( + ) : null} + {showHistoryTab ? ( { tabBarIcon: 'history', }} /> - )} + ) : null} = ({ onPress={showCategoryModal} theme={theme} /> - {categoryIndex !== 0 && category.id !== 2 && ( + {categoryIndex !== 0 && category.id !== 2 ? ( = ({ onPress={showDeleteCategoryModal} theme={theme} /> - )} + ) : null} diff --git a/src/screens/browse/migration/MigrationNovels.tsx b/src/screens/browse/migration/MigrationNovels.tsx index 2fbb59d93..9f601b051 100644 --- a/src/screens/browse/migration/MigrationNovels.tsx +++ b/src/screens/browse/migration/MigrationNovels.tsx @@ -130,9 +130,9 @@ const MigrationNovels = ({ navigation, route }: MigrateNovelScreenProps) => { handleGoBack={navigation.goBack} theme={theme} /> - {progress > 0 && ( + {progress > 0 ? ( - )} + ) : null} { renderLabel={({ route, color }) => ( {route.title} - {showNumberOfNovels && ( + {showNumberOfNovels ? ( { {(route as any)?.novels.length} - )} + ) : null} )} inactiveColor={theme.secondary} @@ -176,14 +176,14 @@ const LibraryScreen = ({ navigation }: LibraryScreenProps) => { } theme={theme} /> - {downloadedOnlyMode && ( + {downloadedOnlyMode ? ( - )} - {incognitoMode && ( + ) : null} + {incognitoMode ? ( { backgroundColor={theme.tertiary} textColor={theme.onTertiary} /> - )} + ) : null} { initialLayout={{ width: layout.width }} /> {useLibraryFAB && - !isHistoryLoading && - history && - history.length !== 0 && - !error && ( - { - navigation.navigate('Chapter', { - novel: { - path: history[0].novelPath, - pluginId: history[0].pluginId, - name: history[0].novelName, - } as NovelInfo, - chapter: history[0], - }); - }} - /> - )} + !isHistoryLoading && + history && + history.length !== 0 && + !error ? ( + { + navigation.navigate('Chapter', { + novel: { + path: history[0].novelPath, + pluginId: history[0].pluginId, + name: history[0].novelName, + } as NovelInfo, + chapter: history[0], + }); + }} + /> + ) : null} { /> } /> - {queue.length > 0 && ( + {queue.length > 0 ? ( { isDownloading ? pauseDownload() : resumeDowndload(); }} /> - )} + ) : null} ); }; diff --git a/src/screens/more/DownloadsScreen.tsx b/src/screens/more/DownloadsScreen.tsx index eea15f906..655183b01 100644 --- a/src/screens/more/DownloadsScreen.tsx +++ b/src/screens/more/DownloadsScreen.tsx @@ -91,13 +91,13 @@ const Downloads = ({ navigation }: DownloadsScreenProps) => { handleGoBack={navigation.goBack} theme={theme} > - {chapters.length > 0 && ( + {chapters.length > 0 ? ( - )} + ) : null} {loading ? ( diff --git a/src/screens/novel/NovelScreen.tsx b/src/screens/novel/NovelScreen.tsx index f78653461..28dd05fb7 100644 --- a/src/screens/novel/NovelScreen.tsx +++ b/src/screens/novel/NovelScreen.tsx @@ -349,7 +349,7 @@ const Novel = ({ route, navigation }: NovelScreenProps) => { onPress={() => navigation.goBack()} /> - {!novel.isLocal && ( + {!novel.isLocal ? ( { }) } /> - )} + ) : null} { }} onPress={() => showJumpToChapterModal(true)} /> - {!novel.isLocal && ( + {!novel.isLocal ? ( showDownloadMenu(false)} @@ -502,7 +502,7 @@ const Novel = ({ route, navigation }: NovelScreenProps) => { }} /> - )} + ) : null} { onScroll={onPageScroll} /> - {useFabForContinueReading && lastRead && ( + {useFabForContinueReading && lastRead ? ( { } }} /> - )} + ) : null} 0} actions={actions} /> = ({ {left} {bookmark ? : null} - {isUpdateCard && ( + {isUpdateCard ? ( = ({ > {novelName} - )} + ) : null} {unread ? ( = ({ - {!isLocal && ( + {!isLocal ? ( = ({ showDeleteChapterMenu={showMenu} deleteChapterMenuVisible={isMenuVisible} /> - )} + ) : null} ); }; diff --git a/src/screens/novel/components/EditInfoModal.tsx b/src/screens/novel/components/EditInfoModal.tsx index 75d7b637b..b348f9e5a 100644 --- a/src/screens/novel/components/EditInfoModal.tsx +++ b/src/screens/novel/components/EditInfoModal.tsx @@ -156,7 +156,7 @@ const EditInfoModal = ({ dense /> - {novel.genres !== undefined && novel.genres !== '' && ( + {novel.genres !== undefined && novel.genres !== '' ? ( - )} + ) : null}