67 lines
1.3 KiB
Swift
67 lines
1.3 KiB
Swift
//
|
|
// SearchView.swift
|
|
// Brewer
|
|
//
|
|
// Created by Cédric MAS on 09/07/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct SearchView: View {
|
|
@State private var query = ""
|
|
@State private var brew = Homebrew()
|
|
var body: some View {
|
|
VStack {
|
|
TextField("Search", text: $query)
|
|
.onSubmit {
|
|
brew.getInfo(on: query)
|
|
}
|
|
Spacer()
|
|
if brew.isLoading {
|
|
ProgressView("Loading...")
|
|
} else if let data = brew.data {
|
|
List {
|
|
if !data.casks.isEmpty {
|
|
Section("Casks") {
|
|
ForEach(data.casks, id: \.fullToken) { cask in
|
|
HStack {
|
|
Text(cask.fullToken)
|
|
Spacer()
|
|
if cask.installed != nil {
|
|
Image(
|
|
systemName: "checkmark.circle.fill"
|
|
)
|
|
.symbolRenderingMode(.palette)
|
|
.foregroundStyle(.white, .green)
|
|
} else {
|
|
DownloadButton(
|
|
name: cask.fullToken, isCask: true)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if !data.formulae.isEmpty {
|
|
|
|
Section("Formulaes") {
|
|
ForEach(data.formulae, id: \.fullName) { formulae in
|
|
HStack {
|
|
Text(formulae.fullName)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else if let errorMessage = brew.errorMessage {
|
|
Text(errorMessage)
|
|
.foregroundStyle(.red)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
#Preview {
|
|
SearchView()
|
|
}
|