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