55// Created by David Bureš on 12.03.2023.
66//
77
8- import SwiftUI
98import CorkModels
9+ import SwiftUI
1010
1111struct PackagesIncludedInTapList : View
1212{
1313 @Environment ( \. selectedTap) var selectedTap : BrewTap ?
14-
14+
1515 @Environment ( BrewPackagesTracker . self) var brewPackagesTracker : BrewPackagesTracker
1616
1717 let packages : [ MinimalHomebrewPackage ]
@@ -22,50 +22,72 @@ struct PackagesIncludedInTapList: View
2222 {
2323 if searchString. isEmpty
2424 {
25- return packages. sorted {
26- return $0. name < $1. name
25+ return packages. sorted
26+ {
27+ $0. name < $1. name
2728 }
2829 }
2930 else
3031 {
31- return packages. filter ( { $0. name. localizedCaseInsensitiveContains ( searchString) } ) . sorted {
32+ return packages. filter { $0. name. localizedCaseInsensitiveContains ( searchString) } . sorted
33+ {
3234 $0. name < $1. name
3335 }
3436 }
3537 }
36-
38+
3739 var body : some View
3840 {
3941 VStack ( spacing: 5 )
4042 {
4143 CustomSearchField ( search: $searchString, customPromptText: " tap-details.included-packages.search.prompt " )
42- ScrollView
44+ List
4345 {
44- List
45- {
46- ForEach ( packagesToDisplay )
47- { package in
48- HStack ( alignment : . center )
46+ ForEach ( packagesToDisplay )
47+ { ( minimalPackage : MinimalHomebrewPackage ) in
48+ HStack ( alignment : . center )
49+ {
50+ if let initializedBrewPackageForDisplayInList : BrewPackage = . init ( using : minimalPackage )
4951 {
50- SanitizedPackageName ( package : . init( name: package . name, type: . formula, installedOn: nil , versions: [ ] , url: nil , sizeInBytes: nil , downloadCount: nil ) , shouldShowVersion: true )
52+ SanitizedPackageName (
53+ package : initializedBrewPackageForDisplayInList,
54+ shouldShowVersion: true
55+ )
5156
52- if brewPackagesTracker. successfullyLoadedFormulae. contains ( where: { $0. name == package . getPackageName ( withPrecision: . precise) } ) || brewPackagesTracker. successfullyLoadedCasks. contains ( where: { $0. name == package . getPackageName ( withPrecision: . precise) } )
57+ var isPackageAlreadyInstalled : Bool
58+ {
59+ var packageContainedInFormulae : Bool {
60+ return brewPackagesTracker. successfullyLoadedFormulae. contains { installedPackage in
61+ installedPackage. getPackageName ( withPrecision: . precise) == minimalPackage. name
62+ }
63+ }
64+
65+ var packageContainedInCasks : Bool {
66+ return brewPackagesTracker. successfullyLoadedCasks. contains { installedPackage in
67+ installedPackage. getPackageName ( withPrecision: . precise) == minimalPackage. name
68+ }
69+ }
70+
71+ return packageContainedInFormulae || packageContainedInCasks
72+ }
73+
74+ if isPackageAlreadyInstalled
5375 {
5476 PillTextWithLocalizableText ( localizedText: " add-package.result.already-installed " )
5577 }
5678 }
57- . contextMenu
58- {
59- contextMenu ( packageToPreview : package )
60- }
79+ }
80+ . contextMenu
81+ {
82+ contextMenu ( packageToPreview : minimalPackage )
6183 }
6284 }
63- . frame ( height: 150 )
64- . listStyle ( . bordered( alternatesRowBackgrounds: true ) )
6585 }
86+ . frame ( height: 150 )
87+ . listStyle ( . bordered( alternatesRowBackgrounds: true ) )
6688 }
6789 }
68-
90+
6991 @ViewBuilder
7092 func contextMenu( packageToPreview: MinimalHomebrewPackage ) -> some View
7193 {
0 commit comments