@@ -17,50 +17,58 @@ struct SearchResultRow: View, Sendable
1717
1818 @Environment ( BrewPackagesTracker . self) var brewPackagesTracker : BrewPackagesTracker
1919 @Environment ( TopPackagesTracker . self) var topPackagesTracker : TopPackagesTracker
20-
21- let searchedForPackage : MinimalHomebrewPackage
20+
2221 let context : Self . Context
2322
2423 @State private var description : String ?
2524 @State private var isCompatible : Bool ?
2625
2726 @State private var isLoadingDescription : Bool = true
2827 @State private var descriptionParsingFailed : Bool = false
28+
29+ /// Get the relevant package from the context
30+ var relevantPackage : MinimalHomebrewPackage
31+ {
32+ switch self . context
33+ {
34+ case . topPackage( let package , _) :
35+ return package
36+ case . searchResult( let searchedForPackage) :
37+ return searchedForPackage
38+ }
39+ }
2940
3041 var body : some View
3142 {
3243 VStack ( alignment: . leading)
3344 {
3445 HStack ( alignment: . center)
3546 {
36- searchedForPackage . nameView ( withComponents: . boundVersion)
47+ relevantPackage . nameView ( withComponents: . boundVersion)
3748
3849 switch context
3950 {
40- case . topPackages :
51+ case . topPackage ( _ , let downloadCount ) :
4152 Spacer ( )
4253
43- // TODO: Reimplement download counts
44- /*
45- if let downloadCount = searchedForPackage.downloadCount
54+ if let downloadCount
4655 {
4756 Text ( " add-package.top-packages.list-item- \( downloadCount) " )
4857 . foregroundStyle ( . secondary)
4958 . font ( . caption)
5059 }
51- */
52-
53- case . searchResults:
54- if searchedForPackage. type == . formula
60+
61+ case . searchResult( let package ) :
62+ if package . type == . formula
5563 {
56- if brewPackagesTracker. successfullyLoadedFormulae. contains ( where: { $0. getCompletePackageName ( ) == searchedForPackage . internalName } )
64+ if brewPackagesTracker. successfullyLoadedFormulae. contains ( where: { $0. getCompletePackageName ( ) == package . internalName } )
5765 {
5866 PillTextWithLocalizableText ( localizedText: " add-package.result.already-installed " )
5967 }
6068 }
6169 else
6270 {
63- if brewPackagesTracker. successfullyLoadedCasks. contains ( where: { $0. getCompletePackageName ( ) == searchedForPackage . internalName } )
71+ if brewPackagesTracker. successfullyLoadedCasks. contains ( where: { $0. getCompletePackageName ( ) == package . internalName } )
6472 {
6573 PillTextWithLocalizableText ( localizedText: " add-package.result.already-installed " )
6674 }
@@ -113,12 +121,12 @@ struct SearchResultRow: View, Sendable
113121 }
114122 }
115123 }
116- . tag ( searchedForPackage )
124+ . tag ( relevantPackage )
117125 . task
118126 {
119127 if showDescriptionsInSearchResults
120128 {
121- AppConstants . shared. logger. info ( " \( searchedForPackage . name ( withPrecision: . precise) , privacy: . auto) came into view " )
129+ AppConstants . shared. logger. info ( " \( relevantPackage . name ( withPrecision: . precise) , privacy: . auto) came into view " )
122130
123131 if description == nil
124132 {
@@ -127,11 +135,11 @@ struct SearchResultRow: View, Sendable
127135 isLoadingDescription = false
128136 }
129137
130- AppConstants . shared. logger. info ( " \( searchedForPackage . name ( withPrecision: . precise) , privacy: . auto) does not have its description loaded " )
138+ AppConstants . shared. logger. info ( " \( relevantPackage . name ( withPrecision: . precise) , privacy: . auto) does not have its description loaded " )
131139
132140 do
133141 {
134- guard let searchedForPackageConvertedForDetailLoading: BrewPackage = . init( using: searchedForPackage ) else
142+ guard let searchedForPackageConvertedForDetailLoading: BrewPackage = . init( using: relevantPackage ) else
135143 {
136144 AppConstants . shared. logger. error ( " Failed to convert minimal package to actual package " )
137145
@@ -156,14 +164,17 @@ struct SearchResultRow: View, Sendable
156164 }
157165 else
158166 {
159- AppConstants . shared. logger. info ( " \( searchedForPackage . name ( withPrecision: . precise) , privacy: . auto) already has its description loaded " )
167+ AppConstants . shared. logger. info ( " \( relevantPackage . name ( withPrecision: . precise) , privacy: . auto) already has its description loaded " )
160168 }
161169 }
162170 }
163171 }
164172
165173 enum Context {
166- case searchResults
167- case topPackages
174+ case searchResult( searchedForPackage: MinimalHomebrewPackage )
175+ case topPackage(
176+ package : MinimalHomebrewPackage ,
177+ downloadCount: Int ?
178+ )
168179 }
169180}
0 commit comments