-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
99 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
Mlem/Views/Tabs/Settings/Components/Views/Account/AccountDiscussionLanguagesView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// AccountDiscussionLanguagesView.swift | ||
// Mlem | ||
// | ||
// Created by Bosco Ho on 2023-12-13. | ||
// | ||
|
||
import SwiftUI | ||
import Dependencies | ||
|
||
struct AccountDiscussionLanguagesView: View { | ||
|
||
@Dependency(\.siteInformation) var siteInformation: SiteInformationTracker | ||
@Dependency(\.apiClient) var apiClient: APIClient | ||
@Dependency(\.errorHandler) var errorHandler: ErrorHandler | ||
|
||
@State private var discussionLanguages: Set<Int> = .init() | ||
|
||
init() { | ||
if let info = siteInformation.myUserInfo { | ||
_discussionLanguages = .init(wrappedValue: Set(info.discussionLanguages)) | ||
} | ||
} | ||
|
||
var body: some View { | ||
Form { | ||
Section { | ||
Toggle(isOn: Binding( | ||
get: { discussionLanguages.contains(0) }, | ||
set: { selected in | ||
if selected { | ||
discussionLanguages.insert(0) | ||
} else { | ||
discussionLanguages.remove(0) | ||
} | ||
saveDiscussionLanguages() | ||
} | ||
)) { | ||
Text("Undetermined") | ||
} | ||
} footer: { | ||
Text("If you deselect Undetermined, you won't see most content.") | ||
} | ||
Section { | ||
ForEach(siteInformation.allLanguages.dropFirst(), id: \.self) { language in | ||
Toggle(isOn: Binding( | ||
get: { discussionLanguages.contains(language.id) }, | ||
set: { selected in | ||
if selected { | ||
discussionLanguages.insert(language.id) | ||
} else { | ||
discussionLanguages.remove(language.id) | ||
} | ||
saveDiscussionLanguages() | ||
} | ||
)) { | ||
Text(language.name) | ||
} | ||
} | ||
} | ||
} | ||
.fancyTabScrollCompatible() | ||
.hoistNavigation() | ||
} | ||
|
||
private func saveDiscussionLanguages() { | ||
let newValue = Array(discussionLanguages).sorted() | ||
if newValue != siteInformation.myUserInfo?.discussionLanguages { | ||
let oldValues = siteInformation.myUserInfo?.discussionLanguages ?? [] | ||
siteInformation.myUserInfo?.discussionLanguages = newValue | ||
Task { | ||
if let info = siteInformation.myUserInfo { | ||
do { | ||
try await apiClient.saveUserSettings(myUserInfo: info) | ||
} catch { | ||
discussionLanguages = Set(oldValues) | ||
siteInformation.myUserInfo?.discussionLanguages = oldValues | ||
errorHandler.handle(error) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,5 +48,6 @@ struct AdvancedAccountSettingsView: View { | |
} | ||
} | ||
.navigationTitle("Advanced") | ||
.hoistNavigation() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,5 +110,6 @@ struct MatrixLinkView: View { | |
} | ||
} | ||
} | ||
.hoistNavigation() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,5 +106,6 @@ struct ProfileSettingsView: View { | |
} | ||
} | ||
.fancyTabScrollCompatible() | ||
.hoistNavigation() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,5 +127,6 @@ struct SignInAndSecuritySettingsView: View { | |
} | ||
} | ||
.fancyTabScrollCompatible() | ||
.hoistNavigation() | ||
} | ||
} |