added isSelected property to make isselected checking cleaner

This commit is contained in:
neon443 committed 2025-06-29 12:11:31 +01:00
1 parent af00ab1e7c
commit 24ca75f8c6
4 files changed
+12 -4

No files matched your search

+1
View File
@@ -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 }
+1
View File
@@ -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 }
+2 -1
View File
@@ -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() {
+8 -3
View File
@@ -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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.