Skip to content

Commit c724cb5

Browse files
committed
Add search bar in item list view
- Add search bar and list to list view - Separate search bar and search list
1 parent d0f97d7 commit c724cb5

File tree

6 files changed

+729
-608
lines changed

6 files changed

+729
-608
lines changed

Trio.xcodeproj/project.pbxproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
09A169792EE302EB0026711D /* OpenFoodFactsModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09A169712EE302EB0026711D /* OpenFoodFactsModels.swift */; };
2020
09A1697B2EE302EB0026711D /* ScannerPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09A169732EE302EB0026711D /* ScannerPreviewView.swift */; };
2121
09A1697C2EE302EB0026711D /* ProductViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09A169742EE302EB0026711D /* ProductViews.swift */; };
22+
09D758522F31671B00F9055E /* ProductSearchField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D758512F31671B00F9055E /* ProductSearchField.swift */; };
23+
09D758532F31671B00F9055E /* FoodSearchResultRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D758502F31671B00F9055E /* FoodSearchResultRow.swift */; };
2224
09F000722F01D6E800835F6D /* OpenFoodFactsClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09F000712F01D6E800835F6D /* OpenFoodFactsClient.swift */; };
23-
0D9A5E34A899219C5C4CDFAF /* DataTableStateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9455FA2D92E77A6C4AFED8A3 /* DataTableStateModel.swift */; };
2425
0D9A5E34A899219C5C4CDFAF /* HistoryStateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9455FA2D92E77A6C4AFED8A3 /* HistoryStateModel.swift */; };
2526
0F7A65FBD2CD8D6477ED4539 /* GlucoseNotificationSettingsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = E625985B47742D498CB1681A /* GlucoseNotificationSettingsProvider.swift */; };
2627
110AEDE32C5193D200615CC9 /* BolusIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110AEDE02C5193D100615CC9 /* BolusIntent.swift */; };
@@ -862,6 +863,8 @@
862863
09A169712EE302EB0026711D /* OpenFoodFactsModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenFoodFactsModels.swift; sourceTree = "<group>"; };
863864
09A169732EE302EB0026711D /* ScannerPreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScannerPreviewView.swift; sourceTree = "<group>"; };
864865
09A169742EE302EB0026711D /* ProductViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductViews.swift; sourceTree = "<group>"; };
866+
09D758502F31671B00F9055E /* FoodSearchResultRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodSearchResultRow.swift; sourceTree = "<group>"; };
867+
09D758512F31671B00F9055E /* ProductSearchField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductSearchField.swift; sourceTree = "<group>"; };
865868
09F000712F01D6E800835F6D /* OpenFoodFactsClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenFoodFactsClient.swift; sourceTree = "<group>"; };
866869
110AEDE02C5193D100615CC9 /* BolusIntent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BolusIntent.swift; sourceTree = "<group>"; };
867870
110AEDE12C5193D100615CC9 /* BolusIntentRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BolusIntentRequest.swift; sourceTree = "<group>"; };
@@ -1692,6 +1695,8 @@
16921695
096F54762EF21D4B00B557C1 /* NutritionEditorView.swift */,
16931696
09A169732EE302EB0026711D /* ScannerPreviewView.swift */,
16941697
09A169742EE302EB0026711D /* ProductViews.swift */,
1698+
09D758502F31671B00F9055E /* FoodSearchResultRow.swift */,
1699+
09D758512F31671B00F9055E /* ProductSearchField.swift */,
16951700
);
16961701
path = View;
16971702
sourceTree = "<group>";
@@ -4529,6 +4534,8 @@
45294534
389ECDFE2601061500D86C4F /* View+Snapshot.swift in Sources */,
45304535
38FEF3FE2738083E00574A46 /* CGMSettingsProvider.swift in Sources */,
45314536
38E98A3725F5509500C0CED0 /* String+Extensions.swift in Sources */,
4537+
09D758522F31671B00F9055E /* ProductSearchField.swift in Sources */,
4538+
09D758532F31671B00F9055E /* FoodSearchResultRow.swift in Sources */,
45324539
CC76E9512BD4812E008BEB61 /* Forecast+helper.swift in Sources */,
45334540
DD1745242C55526000211FAC /* SMBSettingsStateModel.swift in Sources */,
45344541
F90692D1274B99B60037068D /* HealthKitProvider.swift in Sources */,

Trio/Sources/Modules/BarcodeScanner/BarcodeScannerStateModel.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ extension BarcodeScanner {
3131
@Published var editingAmount: Double = 0
3232
@Published var editingIsMl: Bool = false
3333

34+
// Search State
35+
@Published var searchQuery = ""
36+
@Published var searchResults: [FoodItem] = []
37+
@Published var isSearching = false
38+
@Published var searchError: String?
39+
3440
// MARK: - Private Properties
3541

3642
private let client = OpenFoodFactsClient()
@@ -280,5 +286,29 @@ extension BarcodeScanner {
280286
hideModal()
281287
}
282288
}
289+
290+
/// Performs food search using Open Food Facts API
291+
func performFoodSearch() {
292+
searchError = nil
293+
searchResults = []
294+
295+
let query = searchQuery.trimmingCharacters(in: .whitespacesAndNewlines)
296+
guard !query.isEmpty else {
297+
isSearching = false
298+
return
299+
}
300+
301+
isSearching = true
302+
303+
Task { @MainActor in
304+
do {
305+
searchResults = try await client.searchProducts(query: query)
306+
} catch {
307+
searchError = error.localizedDescription
308+
searchResults = []
309+
}
310+
isSearching = false
311+
}
312+
}
283313
}
284314
}

0 commit comments

Comments
 (0)