From 5eb9328d3ea547fa8c95df51d26342ee3d9b5e65 Mon Sep 17 00:00:00 2001 From: Joel-David <4586209+joeldavidw@users.noreply.github.com> Date: Tue, 30 Jul 2024 17:49:30 +0700 Subject: [PATCH] feat: Implemented search function (#51) * Added search * bump version --- Chronos.xcodeproj/project.pbxproj | 6 +-- Chronos/App/MainAppView.swift | 50 ++++++++++++------------- Chronos/App/Tabs/Tokens/TokensTab.swift | 16 +++++--- 3 files changed, 38 insertions(+), 34 deletions(-) diff --git a/Chronos.xcodeproj/project.pbxproj b/Chronos.xcodeproj/project.pbxproj index fd4857c..db301a9 100644 --- a/Chronos.xcodeproj/project.pbxproj +++ b/Chronos.xcodeproj/project.pbxproj @@ -863,7 +863,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 9.0; + MARKETING_VERSION = 10.0; PRODUCT_BUNDLE_IDENTIFIER = com.joeldavidw.ChronosDevDebug; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -910,7 +910,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 9.0; + MARKETING_VERSION = 10.0; PRODUCT_BUNDLE_IDENTIFIER = com.joeldavidw.ChronosDevRelease; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1236,7 +1236,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 9.0; + MARKETING_VERSION = 10.0; PRODUCT_BUNDLE_IDENTIFIER = com.joeldavidw.Chronos; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/Chronos/App/MainAppView.swift b/Chronos/App/MainAppView.swift index 68136d5..15987bd 100644 --- a/Chronos/App/MainAppView.swift +++ b/Chronos/App/MainAppView.swift @@ -29,7 +29,9 @@ struct MainAppView: View { } var body: some View { - ZStack { + if scenePhase != .active { + PrivacyView() + } else { TabView(selection: $currentTab) { TokensTab() .tag("Tokens") @@ -43,36 +45,32 @@ struct MainAppView: View { Label("Settings", systemImage: "gearshape") } } + .onAppear { + if filteredVault.isEmpty { + stateService.resetAllStates() + loginStatus.loggedIn = false + } - if scenePhase != .active { - PrivacyView() - } - } - .onAppear { - if filteredVault.isEmpty { - stateService.resetAllStates() - loginStatus.loggedIn = false - } - - if biometricsEnabled && statePasswordReminderEnabled { - if Date().timeIntervalSince1970 >= nextPasswordReminderTimestamp { - showPasswordReminder = true + if biometricsEnabled && statePasswordReminderEnabled { + if Date().timeIntervalSince1970 >= nextPasswordReminderTimestamp { + showPasswordReminder = true + } } } - } - .onChange(of: filteredVault) { _, newValue in - if newValue.isEmpty { - stateService.resetAllStates() - loginStatus.loggedIn = false + .onChange(of: filteredVault) { _, newValue in + if newValue.isEmpty { + stateService.resetAllStates() + loginStatus.loggedIn = false + } } - } - .onChange(of: syncMonitor.syncStateSummary) { _, newValue in - if newValue == .succeeded { - iCloudSyncLastAttempt = Date().timeIntervalSince1970 + .onChange(of: syncMonitor.syncStateSummary) { _, newValue in + if newValue == .succeeded { + iCloudSyncLastAttempt = Date().timeIntervalSince1970 + } } + .sheet(isPresented: $showPasswordReminder, content: { + PasswordReminderView() + }) } - .sheet(isPresented: $showPasswordReminder, content: { - PasswordReminderView() - }) } } diff --git a/Chronos/App/Tabs/Tokens/TokensTab.swift b/Chronos/App/Tabs/Tokens/TokensTab.swift index 8ed680f..8c72a0f 100644 --- a/Chronos/App/Tabs/Tokens/TokensTab.swift +++ b/Chronos/App/Tabs/Tokens/TokensTab.swift @@ -33,6 +33,8 @@ struct TokensTab: View { @State var detentHeight: CGFloat = 0 @State var sortCriteria: TokenSortOrder = .ISSUER_ASC + @State private var searchQuery = "" + let cryptoService = Container.shared.cryptoService() let stateService = Container.shared.stateService() @@ -53,6 +55,11 @@ struct TokensTab: View { } return TokenPair(id: encToken.id, token: decryptedToken, encToken: encToken) } + .filter { tokenPair in + searchQuery.isEmpty || + tokenPair.token.issuer.localizedCaseInsensitiveContains(searchQuery) || + tokenPair.token.account.localizedCaseInsensitiveContains(searchQuery) + } .sorted(by: { token1, token2 in switch sortCriteria { case .ISSUER_ASC: @@ -71,15 +78,14 @@ struct TokensTab: View { var body: some View { NavigationStack { - ScrollViewReader { _ in - List(tokenPairs) { tokenPair in - TokenRowView(tokenPair: tokenPair) - } - .listStyle(.plain) + List(tokenPairs) { tokenPair in + TokenRowView(tokenPair: tokenPair) } + .listStyle(.plain) .background(Color(red: 0.04, green: 0, blue: 0.11)) .navigationTitle("Tokens") .navigationBarTitleDisplayMode(.inline) + .searchable(text: $searchQuery, prompt: Text("Search tokens")) .toolbar { Menu { ForEach(sortOptions, id: \.criteria) { option in