Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nickname setting and "Delete all favorites" button #1473

Merged
merged 5 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@
03AB48552CBC0B8000567FF9 /* AccountAdvancedSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AB48542CBC0B8000567FF9 /* AccountAdvancedSettingsView.swift */; };
03AB48572CBC0DFC00567FF9 /* AccountSignInSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AB48562CBC0DFC00567FF9 /* AccountSignInSettingsView.swift */; };
03AB48592CBC14CE00567FF9 /* AccountEmailSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AB48582CBC14CE00567FF9 /* AccountEmailSettingsView.swift */; };
03AD0A822CFDBFA0001EF9F7 /* AccountLocalSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AD0A812CFDBFA0001EF9F7 /* AccountLocalSettingsView.swift */; };
03AD0A842CFDC557001EF9F7 /* AccountNicknameFieldView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AD0A832CFDC557001EF9F7 /* AccountNicknameFieldView.swift */; };
03AF91DD2C1B23E500E56644 /* ImageViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AF91DC2C1B23E500E56644 /* ImageViewer.swift */; };
03AF91DF2C1B243D00E56644 /* ZoomableContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AF91DE2C1B243D00E56644 /* ZoomableContainer.swift */; };
03AF91E12C1B25DE00E56644 /* UIDevice+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AF91E02C1B25DE00E56644 /* UIDevice+Extensions.swift */; };
Expand Down Expand Up @@ -608,6 +610,8 @@
03AB48542CBC0B8000567FF9 /* AccountAdvancedSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountAdvancedSettingsView.swift; sourceTree = "<group>"; };
03AB48562CBC0DFC00567FF9 /* AccountSignInSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSignInSettingsView.swift; sourceTree = "<group>"; };
03AB48582CBC14CE00567FF9 /* AccountEmailSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountEmailSettingsView.swift; sourceTree = "<group>"; };
03AD0A812CFDBFA0001EF9F7 /* AccountLocalSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountLocalSettingsView.swift; sourceTree = "<group>"; };
03AD0A832CFDC557001EF9F7 /* AccountNicknameFieldView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountNicknameFieldView.swift; sourceTree = "<group>"; };
03AF91DC2C1B23E500E56644 /* ImageViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageViewer.swift; sourceTree = "<group>"; };
03AF91DE2C1B243D00E56644 /* ZoomableContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZoomableContainer.swift; sourceTree = "<group>"; };
03AF91E02C1B25DE00E56644 /* UIDevice+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIDevice+Extensions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -901,6 +905,8 @@
03AB48542CBC0B8000567FF9 /* AccountAdvancedSettingsView.swift */,
03AB48562CBC0DFC00567FF9 /* AccountSignInSettingsView.swift */,
03AB48582CBC14CE00567FF9 /* AccountEmailSettingsView.swift */,
03AD0A812CFDBFA0001EF9F7 /* AccountLocalSettingsView.swift */,
03AD0A832CFDC557001EF9F7 /* AccountNicknameFieldView.swift */,
03134A572BEC1C46002662CC /* AccountListSettingsView.swift */,
031E2D5A2BEFC9460003BC45 /* ThemeSettingsView.swift */,
03B72B6A2C28A0190023A6C4 /* SubscriptionListSettingsView.swift */,
Expand Down Expand Up @@ -2107,6 +2113,7 @@
03AB48552CBC0B8000567FF9 /* AccountAdvancedSettingsView.swift in Sources */,
039F588A2C7B54FE00C61658 /* GeneralSettingsView.swift in Sources */,
03F967272CE218110081C9A3 /* PersonBanEditorView.swift in Sources */,
03AD0A822CFDBFA0001EF9F7 /* AccountLocalSettingsView.swift in Sources */,
039F58992C7B697D00C61658 /* Bundle+Extensions.swift in Sources */,
033F84D92C2B61FB002E3EDF /* ToastType.swift in Sources */,
03A82FA12C0D1E8500D01A5C /* ApiClient+Extensions.swift in Sources */,
Expand Down Expand Up @@ -2146,6 +2153,7 @@
03C93CF02BEFFB1A00327BFE /* LoginCredentialsView.swift in Sources */,
CD332D7C2CA71E6F00A53988 /* GifView.swift in Sources */,
CD13CC652C5D2B9D001AF428 /* CircleCroppedImageView.swift in Sources */,
03AD0A842CFDC557001EF9F7 /* AccountNicknameFieldView.swift in Sources */,
CDAA02DD2C81792500D75633 /* SolarizedPalette.swift in Sources */,
035EDF032C2ED0DE00F51144 /* PersonListRowBody.swift in Sources */,
03FD6CB02C9B719100500FD6 /* View+PopupAnchor.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Mlem/App/Models/Account/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ protocol Account: AnyObject, Codable, ActorIdentifiable, Profile1Providing, Hash
var nicknameSortKey: String { get }
var instanceSortKey: String { get }
var isActive: Bool { get }

func setNickname(_ newValue: String)
}

// Profile1Providing conformance
Expand Down
5 changes: 5 additions & 0 deletions Mlem/App/Models/Account/GuestAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ class GuestAccount: Account {
AccountsTracker.main.saveAccounts(ofType: .guest)
}
}

func setNickname(_ newValue: String) {
storedNickname = newValue.isEmpty ? nil : newValue
AccountsTracker.main.saveAccounts(ofType: .guest)
}
}

extension GuestAccount: CacheIdentifiable {
Expand Down
5 changes: 5 additions & 0 deletions Mlem/App/Models/Account/UserAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ class UserAccount: Account, CommunityOrPersonStub {
guard let host else { return nil }
return "@\(name)@\(host)"
}

func setNickname(_ newValue: String) {
storedNickname = newValue.isEmpty ? nil : newValue
AccountsTracker.main.saveAccounts(ofType: .user)
}
}

private func getKeychainId(actorId: URL) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// AccountLocalSettingsView.swift
// Mlem
//
// Created by Sjmarf on 2024-12-02.
//

import SwiftUI

struct AccountLocalSettingsView: View {
@Environment(AppState.self) var appState
@Environment(Palette.self) var palette

@State var isShowingFavoriteDeletionWarning: Bool = false

var body: some View {
Form {
AccountNicknameFieldView()
if let userSession = AppState.main.firstSession as? UserSession {
Section {
Button("Delete Community Favorites", systemImage: Icons.delete, role: .destructive) {
isShowingFavoriteDeletionWarning = true
}
.disabled(userSession.account.favorites.isEmpty)
.tint(palette.warning)
.confirmationDialog(
"Delete Community Favorites",
isPresented: $isShowingFavoriteDeletionWarning
) {
Button("Delete", role: .destructive) {
for community in userSession.subscriptions.favorites {
community.updateFavorite(false)
}
}
} message: {
Text("Are you sure you want to delete all community favorites for this account? This cannot be undone.")
}
} footer: {
if userSession.account.favorites.isEmpty {
Text("You have not favorited any communities on this account.")
} else {
Text("You have favorited \(userSession.account.favorites.count) communities on this account.")
Sjmarf marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// AccountNicknameFieldView.swift
// Mlem
//
// Created by Sjmarf on 2024-12-02.
//

import SwiftUI

struct AccountNicknameFieldView: View {
@Environment(AppState.self) var appState

@State var nickname: String

init() {
self.nickname = AppState.main.firstAccount.storedNickname ?? ""
}

var body: some View {
Section("Nickname") {
TextField(
"Nickname",
text: $nickname,
prompt: Text(appState.firstAccount.name)
)
.onSubmit {
AppState.main.firstAccount.setNickname(nickname)
}
} footer: {
Text("The name shown in the account switcher.")
}
}
}
24 changes: 20 additions & 4 deletions Mlem/App/Views/Root/Tabs/Settings/AccountSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,28 @@ struct AccountSettingsView: View {
)
.tint(palette.negative)
}
Section {
NavigationLink(
"Local Options",
systemImage: "iphone",
destination: .settings(.accountLocal)
)
.tint(palette.colorfulAccent(2))
} footer: {
Text("These options are stored locally in Mlem and not on your Lemmy account.")
}
} else {
AccountNicknameFieldView()
}

Group {
Section {
Button(signOutLabel) {
Button {
appState.firstAccount.signOut()
} label: {
Text(signOutLabel)
.frame(maxWidth: .infinity)
}
.frame(maxWidth: .infinity)
.confirmationDialog(signOutPrompt, isPresented: $showingSignOutConfirmation) {
Button(signOutLabel, role: .destructive) {
appState.firstAccount.signOut()
Expand All @@ -79,10 +93,12 @@ struct AccountSettingsView: View {

if let account = appState.firstAccount as? UserAccount {
Section {
Button("Delete Account", role: .destructive) {
Button(role: .destructive) {
navigation.openSheet(.deleteAccount(account))
} label: {
Text("Delete Account")
.frame(maxWidth: .infinity)
}
.frame(maxWidth: .infinity)
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion Mlem/App/Views/Shared/Navigation/SettingsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
enum SettingsPage: Hashable {
case root
case accounts, account
case accountGeneral, accountAdvanced, accountSignIn, accountChangeEmail
case accountGeneral, accountAdvanced, accountSignIn, accountChangeEmail, accountLocal
case general, links, sorting
case importExportSettings
case theme, icon
Expand All @@ -37,6 +37,8 @@ enum SettingsPage: Hashable {
AccountAdvancedSettingsView()
case .accountChangeEmail:
AccountEmailSettingsView()
case .accountLocal:
AccountLocalSettingsView()
case .accounts:
AccountListSettingsView()
case .general:
Expand Down
82 changes: 82 additions & 0 deletions Mlem/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@
},
"Apply to All Interaction Bars" : {

},
"Are you sure you want to delete all community favorites for this account? This cannot be undone." : {
"localizations" : {
"en-GB" : {
"stringUnit" : {
"state" : "translated",
"value" : "Are you sure you want to delete all community favourites for this account? This cannot be undone."
}
}
}
},
"Ask to confirm every time" : {

Expand Down Expand Up @@ -452,6 +462,16 @@
},
"Delete Account" : {

},
"Delete Community Favorites" : {
"localizations" : {
"en-GB" : {
"stringUnit" : {
"state" : "translated",
"value" : "Delete Community Favourites"
}
}
}
},
"Delete posts and comments" : {

Expand Down Expand Up @@ -817,6 +837,9 @@
},
"Local" : {

},
"Local Options" : {

},
"Lock" : {

Expand Down Expand Up @@ -916,6 +939,9 @@
},
"Next" : {

},
"Nickname" : {

},
"No" : {

Expand Down Expand Up @@ -1445,6 +1471,9 @@
}
}
}
},
"The name shown in the account switcher." : {

},
"The number of child comments that are shown in a chain before the \"More Replies\" button is shown." : {

Expand Down Expand Up @@ -1476,6 +1505,9 @@
},
"There were no recorded incidents today." : {

},
"These options are stored locally in Mlem and not on your Lemmy account." : {

},
"This community likely contains graphic or explicit content." : {

Expand Down Expand Up @@ -1718,6 +1750,56 @@
},
"You don't have any accounts." : {

},
"You have favorited %lld communities on this account." : {
"localizations" : {
"en" : {
"variations" : {
"plural" : {
"one" : {
"stringUnit" : {
"state" : "translated",
"value" : "You have favorited %lld community on this account."
}
},
"other" : {
"stringUnit" : {
"state" : "new",
"value" : "You have favorited %lld communities on this account."
}
}
}
}
},
"en-GB" : {
"variations" : {
"plural" : {
"one" : {
"stringUnit" : {
"state" : "translated",
"value" : "You have favourited %lld community on this account."
}
},
"other" : {
"stringUnit" : {
"state" : "translated",
"value" : "You have favourited %lld communities on this account."
}
}
}
}
}
}
},
"You have not favorited any communities on this account." : {
"localizations" : {
"en-GB" : {
"stringUnit" : {
"state" : "translated",
"value" : "You have not favourited any communities on this account."
}
}
}
},
"You may need to allow Mlem to access your Photo Library in System Settings." : {

Expand Down