-
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.
Nickname setting and "Delete all favorites" button (#1473)
- Loading branch information
Showing
9 changed files
with
206 additions
and
5 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
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
48 changes: 48 additions & 0 deletions
48
Mlem/App/Views/Root/Tabs/Settings/AccountLocalSettingsView.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,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("This account has no favorite communities.") | ||
} else { | ||
Text("This account has \(userSession.account.favorites.count) favorite communities.") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Mlem/App/Views/Root/Tabs/Settings/AccountNicknameFieldView.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,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.") | ||
} | ||
} | ||
} |
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