mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 05:19:13 +00:00
added isSelected property to make isselected checking cleaner
This commit is contained in:
@@ -22,6 +22,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
||||
}
|
||||
|
||||
func loadThemes() {
|
||||
userDefaults.synchronize()
|
||||
guard let dataTheme = userDefaults.data(forKey: "themes") else { return }
|
||||
|
||||
guard let decodedThemes = try? JSONDecoder().decode([ThemeCodable].self, from: dataTheme) else { return }
|
||||
|
||||
@@ -23,6 +23,7 @@ class KeyManager: ObservableObject {
|
||||
var tags: [String] = []
|
||||
|
||||
func loadTags() {
|
||||
userdefaults.synchronize()
|
||||
let decoder = JSONDecoder()
|
||||
guard let data = userdefaults.data(forKey: "keyTags") else { return }
|
||||
guard let decoded = try? decoder.decode([String].self, from: data) else { return }
|
||||
|
||||
@@ -92,13 +92,14 @@ struct ThemeManagerView: View {
|
||||
.navigationTitle("Themes")
|
||||
.alert("Enter URL", isPresented: $showAlert) {
|
||||
TextField("", text: $importURL, prompt: Text("URL"))
|
||||
Button("Cancel") {}
|
||||
Button() {
|
||||
hostsManager.downloadTheme(fromUrl: URL(string: importURL))
|
||||
importURL = ""
|
||||
} label: {
|
||||
Label("Import", systemImage: "square.and.arrow.down")
|
||||
.bold()
|
||||
}
|
||||
Button("Cancel") {}
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem() {
|
||||
|
||||
@@ -11,6 +11,10 @@ struct ThemePreview: View {
|
||||
@ObservedObject var hostsManager: HostsManager
|
||||
@State var theme: Theme
|
||||
|
||||
var isSelected: Bool {
|
||||
return hostsManager.isThemeSelected(theme)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .center) {
|
||||
Rectangle()
|
||||
@@ -19,12 +23,12 @@ struct ThemePreview: View {
|
||||
Rectangle()
|
||||
.fill(theme.background.suiColor)
|
||||
.frame(
|
||||
width: hostsManager.isThemeSelected(theme) ? 190 : 200,
|
||||
height: hostsManager.isThemeSelected(theme) ? 80 : 90
|
||||
width: isSelected ? 190 : 200,
|
||||
height: isSelected ? 80 : 90
|
||||
)
|
||||
.clipShape(
|
||||
RoundedRectangle(
|
||||
cornerRadius: hostsManager.isThemeSelected(theme) ? 5 : 10
|
||||
cornerRadius: isSelected ? 5 : 10
|
||||
)
|
||||
)
|
||||
VStack(alignment: .leading) {
|
||||
@@ -51,6 +55,7 @@ struct ThemePreview: View {
|
||||
}
|
||||
.frame(maxWidth: 200, maxHeight: 90)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 10))
|
||||
.animation(.spring, value: isSelected)
|
||||
.onTapGesture {
|
||||
hostsManager.selectTheme(theme)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user