Fix settings reacting to language change

This commit is contained in:
Christoph Hagen 2025-02-05 21:21:41 +01:00
parent d556a51228
commit 41171c31db
8 changed files with 70 additions and 49 deletions

View File

@ -211,11 +211,9 @@ struct MainView: App {
switch content.saveState {
case .storageNotInitialized:
showInitialSheet()
case .isSaved:
case .isSaved, .needsSave:
content.saveUnconditionally()
case .needsSave:
content.saveUnconditionally()
case .failedToSave:
case .failedToSave, .savingPausedDueToLoadErrors:
showStorageErrorSheet = true
}
}

View File

@ -2,9 +2,9 @@ import SwiftUI
struct AudioSettingsDetailView: View {
@Environment(\.language)
private var language
@Binding
var language: ContentLanguage
@ObservedObject
var audioPlayer: AudioPlayerSettings

View File

@ -3,8 +3,8 @@ import SFSafeSymbols
struct NavigationBarSettingsView: View {
@Environment(\.language)
private var language
@Binding
var language: ContentLanguage
@EnvironmentObject
private var content: Content
@ -30,16 +30,17 @@ struct NavigationBarSettingsView: View {
}
.buttonStyle(.plain)
}
ForEach(content.settings.navigation.navigationItems) { tag in
TagView(text: tag.title(in: language))
.foregroundStyle(.white)
FlowHStack {
ForEach(content.settings.navigation.navigationItems) { tag in
TagView(text: tag.title(in: language))
.foregroundStyle(.white)
}
}
Text("Select the tags to show in the navigation bar. The number should be even.")
Text("Select the tags to show in the navigation bar.")
.foregroundStyle(.secondary)
. padding(.bottom)
LocalizedNavigationBarSettingsView(settings: content.settings.navigation.localized(in: language))
let localized = content.settings.navigation.localized(in: language)
LocalizedNavigationBarSettingsView(settings: localized)
}
.padding()
}
@ -48,11 +49,14 @@ struct NavigationBarSettingsView: View {
isPresented: $showItemPicker,
selectedItems: $content.settings.navigation.navigationItems)
}
.onChange(of: language) { oldValue, newValue in
print("Language changed from \(oldValue) to \(newValue)")
}
}
}
#Preview {
NavigationBarSettingsView()
NavigationBarSettingsView(language: .constant(.english))
.environmentObject(Content.mock)
.padding()
}

View File

@ -2,8 +2,8 @@ import SwiftUI
struct PageSettingsDetailView: View {
@Environment(\.language)
private var language
@Binding
var language: ContentLanguage
@ObservedObject
var pageSettings: PageSettings
@ -67,6 +67,8 @@ struct PageSettingsDetailView: View {
#Preview {
PageSettingsDetailView(pageSettings: .default)
PageSettingsDetailView(
language: .constant(.english),
pageSettings: .default)
.padding()
}

View File

@ -2,8 +2,8 @@ import SwiftUI
struct PostFeedSettingsView: View {
@Environment(\.language)
private var language
@Binding
var language: ContentLanguage
@ObservedObject
var postSettings: PostSettings
@ -54,6 +54,8 @@ struct PostFeedSettingsView: View {
#Preview {
PostFeedSettingsView(postSettings: .default)
.padding()
PostFeedSettingsView(
language: .constant(.english),
postSettings: .default)
.padding()
}

View File

@ -2,7 +2,11 @@ import SwiftUI
struct SettingsContentView: View {
let section: SettingsSection
@Binding
var language: ContentLanguage
@Binding
var section: SettingsSection
@EnvironmentObject
private var content: Content
@ -14,19 +18,21 @@ struct SettingsContentView: View {
case .paths:
PathSettingsView()
case .navigationBar:
NavigationBarSettingsView()
NavigationBarSettingsView(language: $language)
case .postFeed:
PostFeedSettingsView(postSettings: content.settings.posts)
PostFeedSettingsView(language: $language, postSettings: content.settings.posts)
case .pages:
PageSettingsDetailView(pageSettings: content.settings.pages)
PageSettingsDetailView(language: $language, pageSettings: content.settings.pages)
case .tagOverview:
TagOverviewDetailView()
TagOverviewDetailView(language: $language)
case .audioPlayer:
AudioSettingsDetailView(audioPlayer: content.settings.audioPlayer)
AudioSettingsDetailView(language: $language, audioPlayer: content.settings.audioPlayer)
}
}
}
#Preview {
SettingsContentView(section: .paths)
SettingsContentView(
language: .constant(.english),
section: .constant(.paths))
}

View File

@ -41,30 +41,39 @@ struct SettingsSheet: View {
var body: some View {
VStack(spacing: 0) {
HStack(alignment: .top) {
DetailTitle(
title: title,
text: text)
Spacer()
Picker("", selection: $language) {
Text("English")
.tag(ContentLanguage.english)
Text("German")
.tag(ContentLanguage.german)
}
.pickerStyle(.segmented)
Button(action: { dismiss() }) {
Text("Close")
VStack(alignment: .leading) {
HStack(alignment: .top) {
Text(title)
.font(.largeTitle)
.bold()
Spacer()
HStack(alignment: .center) {
Picker("", selection: $language) {
Text("English")
.tag(ContentLanguage.english)
Text("German")
.tag(ContentLanguage.german)
}
.pickerStyle(.segmented)
Button(action: { dismiss() }) {
Text("Close")
}
}.frame(width: 200)
}
Text(text)
.foregroundStyle(.secondary)
.padding(.bottom, 30)
}
.frame(height: 100)
.padding()
.background(Color(NSColor.windowBackgroundColor))
NavigationSplitView {
SettingsListView(section: $section)
.navigationSplitViewColumnWidth(min: sidebarWidth, ideal: sidebarWidth, max: sidebarWidth)
} detail: {
SettingsContentView(section: section)
SettingsContentView(language: $language, section: $section)
}
}.frame(width: 550, height: 600)
}.frame(width: 600, height: 600)
}
}

View File

@ -2,8 +2,8 @@ import SwiftUI
struct TagOverviewDetailView: View {
@Environment(\.language)
private var language
@Binding
var language: ContentLanguage
@EnvironmentObject
private var content: Content