Add search feature to the settings screen
Closes: https://github.com/damus-io/damus/issues/2838 Changelog-Added: Added a search interface to the settings screen Signed-off-by: SanjaySiddharth <mjsanjaysiddharth1999@gmail.com>
This commit is contained in:
@@ -18,10 +18,25 @@ struct ConfigView: View {
|
|||||||
@State var delete_account_warning: Bool = false
|
@State var delete_account_warning: Bool = false
|
||||||
@State var confirm_delete_account: Bool = false
|
@State var confirm_delete_account: Bool = false
|
||||||
@State var delete_text: String = ""
|
@State var delete_text: String = ""
|
||||||
|
@State private var searchText: String = ""
|
||||||
|
|
||||||
@ObservedObject var settings: UserSettingsStore
|
@ObservedObject var settings: UserSettingsStore
|
||||||
|
|
||||||
|
// String constants
|
||||||
private let DELETE_KEYWORD = "DELETE"
|
private let DELETE_KEYWORD = "DELETE"
|
||||||
|
private let keysTitle = NSLocalizedString("Keys", comment: "Settings section for managing keys")
|
||||||
|
private let appearanceTitle = NSLocalizedString("Appearance and filters", comment: "Section header for text, appearance, and content filter settings")
|
||||||
|
private let searchUniverseTitle = NSLocalizedString("Search / Universe", comment: "Section header for search/universe settings")
|
||||||
|
private let notificationsTitle = NSLocalizedString("Notifications", comment: "Section header for Damus notifications")
|
||||||
|
private let zapsTitle = NSLocalizedString("Zaps", comment: "Section header for zap settings")
|
||||||
|
private let translationTitle = NSLocalizedString("Translation", comment: "Section header for text and appearance settings")
|
||||||
|
private let reactionsTitle = NSLocalizedString("Reactions", comment: "Section header for reactions settings")
|
||||||
|
private let developerTitle = NSLocalizedString("Developer", comment: "Section header for developer settings")
|
||||||
|
private let firstAidTitle = NSLocalizedString("First Aid", comment: "Section header for first aid tools and settings")
|
||||||
|
private let signOutTitle = NSLocalizedString("Sign out", comment: "Sidebar menu label to sign out of the account.")
|
||||||
|
private let deleteAccountTitle = NSLocalizedString("Delete Account", comment: "Button to delete the user's account.")
|
||||||
|
private let versionTitle = NSLocalizedString("Version", comment: "Section title for displaying the version number of the Damus app.")
|
||||||
|
private let copyString = NSLocalizedString("Copy", comment: "Context menu option for copying the version of damus.")
|
||||||
|
|
||||||
init(state: DamusState) {
|
init(state: DamusState) {
|
||||||
self.state = state
|
self.state = state
|
||||||
@@ -32,90 +47,121 @@ struct ConfigView: View {
|
|||||||
colorScheme == .light ? DamusColors.black : DamusColors.white
|
colorScheme == .light ? DamusColors.black : DamusColors.white
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func showSettingsButton(title : String)->Bool{
|
||||||
|
return searchText.isEmpty || title.lowercased().contains(searchText.lowercased())
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack(alignment: .leading) {
|
ZStack(alignment: .leading) {
|
||||||
Form {
|
Form {
|
||||||
Section {
|
Section {
|
||||||
NavigationLink(value: Route.KeySettings(keypair: state.keypair)) {
|
// Keys
|
||||||
IconLabel(NSLocalizedString("Keys", comment: "Settings section for managing keys"), img_name: "Key", color: .purple)
|
if showSettingsButton(title: keysTitle){
|
||||||
}
|
NavigationLink(value:Route.KeySettings(keypair: state.keypair)){
|
||||||
|
IconLabel(keysTitle,img_name:"Key",color:.purple)
|
||||||
NavigationLink(value: Route.AppearanceSettings(settings: settings)) {
|
|
||||||
IconLabel(NSLocalizedString("Appearance and filters", comment: "Section header for text, appearance, and content filter settings"), img_name: "eye", color: .red)
|
|
||||||
}
|
|
||||||
|
|
||||||
NavigationLink(value: Route.SearchSettings(settings: settings)) {
|
|
||||||
IconLabel(NSLocalizedString("Search/Universe", comment: "Section header for search/universe settings"), img_name: "search", color: .red)
|
|
||||||
}
|
|
||||||
|
|
||||||
NavigationLink(value: Route.NotificationSettings(settings: settings)) {
|
|
||||||
IconLabel(NSLocalizedString("Notifications", comment: "Section header for Damus notifications"), img_name: "notification-bell-on", color: .blue)
|
|
||||||
}
|
|
||||||
|
|
||||||
NavigationLink(value: Route.ZapSettings(settings: settings)) {
|
|
||||||
IconLabel(NSLocalizedString("Zaps", comment: "Section header for zap settings"), img_name: "zap.fill", color: .orange)
|
|
||||||
}
|
|
||||||
|
|
||||||
NavigationLink(value: Route.TranslationSettings(settings: settings)) {
|
|
||||||
IconLabel(NSLocalizedString("Translation", comment: "Section header for text and appearance settings"), img_name: "globe", color: .green)
|
|
||||||
}
|
|
||||||
|
|
||||||
NavigationLink(value: Route.ReactionsSettings(settings: settings)) {
|
|
||||||
IconLabel(NSLocalizedString("Reactions", comment: "Section header for reactions settings"), img_name: "shaka.fill", color: .purple)
|
|
||||||
}
|
|
||||||
|
|
||||||
NavigationLink(value: Route.DeveloperSettings(settings: settings)) {
|
|
||||||
IconLabel(NSLocalizedString("Developer", comment: "Section header for developer settings"), img_name: "magic-stick2.fill", color: DamusColors.adaptableBlack)
|
|
||||||
}
|
|
||||||
|
|
||||||
NavigationLink(value: Route.FirstAidSettings(settings: settings)) {
|
|
||||||
IconLabel(NSLocalizedString("First Aid", comment: "Section header for first aid tools and settings"), img_name: "help2", color: .red)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Section(NSLocalizedString("Sign Out", comment: "Section title for signing out")) {
|
|
||||||
Button(action: {
|
|
||||||
if state.keypair.privkey == nil {
|
|
||||||
logout(state)
|
|
||||||
} else {
|
|
||||||
confirm_logout = true
|
|
||||||
}
|
}
|
||||||
}, label: {
|
}
|
||||||
Label(NSLocalizedString("Sign out", comment: "Sidebar menu label to sign out of the account."), image: "logout")
|
// Appearance and filters
|
||||||
.foregroundColor(textColor())
|
if showSettingsButton(title: appearanceTitle){
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
NavigationLink(value:Route.AppearanceSettings(settings: settings)){
|
||||||
})
|
IconLabel(appearanceTitle,img_name:"eye",color:.red)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// Search/Universe
|
||||||
|
if showSettingsButton(title: searchUniverseTitle){
|
||||||
|
NavigationLink(value: Route.SearchSettings(settings: settings)){
|
||||||
|
IconLabel(searchUniverseTitle,img_name:"search",color:.red)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if state.is_privkey_user {
|
//Notifications
|
||||||
Section(header: Text("Permanently Delete Account", comment: "Section title for deleting the user")) {
|
if showSettingsButton(title: notificationsTitle){
|
||||||
|
NavigationLink(value: Route.NotificationSettings(settings: settings)){
|
||||||
|
IconLabel(notificationsTitle,img_name:"notification-bell-on",color:.blue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Zaps
|
||||||
|
if showSettingsButton(title: zapsTitle){
|
||||||
|
NavigationLink(value: Route.ZapSettings(settings: settings)){
|
||||||
|
IconLabel(zapsTitle,img_name:"zap.fill",color:.orange)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Translation
|
||||||
|
if showSettingsButton(title: translationTitle){
|
||||||
|
NavigationLink(value: Route.TranslationSettings(settings: settings)){
|
||||||
|
IconLabel(translationTitle,img_name:"globe",color:.green)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Reactions
|
||||||
|
if showSettingsButton(title: reactionsTitle){
|
||||||
|
NavigationLink(value: Route.ReactionsSettings(settings: settings)){
|
||||||
|
IconLabel(reactionsTitle,img_name:"shaka.fill",color:.purple)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Developer
|
||||||
|
if showSettingsButton(title: developerTitle){
|
||||||
|
NavigationLink(value: Route.DeveloperSettings(settings: settings)){
|
||||||
|
IconLabel(developerTitle,img_name:"magic-stick2.fill",color:DamusColors.adaptableBlack)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//First Aid
|
||||||
|
if showSettingsButton(title: firstAidTitle){
|
||||||
|
NavigationLink(value: Route.FirstAidSettings(settings: settings)){
|
||||||
|
IconLabel(firstAidTitle,img_name:"help2",color: .red)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Sign out Section
|
||||||
|
if showSettingsButton(title: signOutTitle){
|
||||||
|
Section(signOutTitle){
|
||||||
Button(action: {
|
Button(action: {
|
||||||
delete_account_warning = true
|
if state.keypair.privkey == nil {
|
||||||
|
logout(state)
|
||||||
|
} else {
|
||||||
|
confirm_logout = true
|
||||||
|
}
|
||||||
}, label: {
|
}, label: {
|
||||||
Label(NSLocalizedString("Delete Account", comment: "Button to delete the user's account."), image: "delete")
|
Label(signOutTitle, image: "logout")
|
||||||
|
.foregroundColor(textColor())
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
.foregroundColor(.red)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Delete Account
|
||||||
Section(
|
if showSettingsButton(title: deleteAccountTitle){
|
||||||
header: Text(NSLocalizedString("Version", comment: "Section title for displaying the version number of the Damus app.")),
|
if state.is_privkey_user {
|
||||||
footer: Text("").padding(.bottom, tabHeight + getSafeAreaBottom())
|
Section(header: Text("Permanently Delete Account", comment: "Section title for deleting the user")) {
|
||||||
) {
|
Button(action: {
|
||||||
Text(verbatim: VersionInfo.version)
|
delete_account_warning = true
|
||||||
.contextMenu {
|
}, label: {
|
||||||
Button {
|
Label(deleteAccountTitle, image: "delete")
|
||||||
UIPasteboard.general.string = VersionInfo.version
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
} label: {
|
.foregroundColor(.red)
|
||||||
Label(NSLocalizedString("Copy", comment: "Context menu option for copying the version of damus."), image: "copy2")
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Version info
|
||||||
|
if showSettingsButton(title: versionTitle) {
|
||||||
|
Section(
|
||||||
|
header: Text(versionTitle),
|
||||||
|
footer: Text("").padding(.bottom, tabHeight + getSafeAreaBottom())
|
||||||
|
) {
|
||||||
|
Text(verbatim: VersionInfo.version)
|
||||||
|
.contextMenu {
|
||||||
|
Button {
|
||||||
|
UIPasteboard.general.string = VersionInfo.version
|
||||||
|
} label: {
|
||||||
|
Label(copyString, image: "copy2")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle(NSLocalizedString("Settings", comment: "Navigation title for Settings view."))
|
.navigationTitle(NSLocalizedString("Settings", comment: "Navigation title for Settings view."))
|
||||||
.navigationBarTitleDisplayMode(.large)
|
.navigationBarTitleDisplayMode(.large)
|
||||||
|
.searchable(text: $searchText,prompt: "Search within settings")
|
||||||
.alert(NSLocalizedString("WARNING:\n\nTHIS WILL SIGN AN EVENT THAT DELETES THIS ACCOUNT.\n\nYOU WILL NO LONGER BE ABLE TO LOG INTO DAMUS USING THIS ACCOUNT KEY.\n\n ARE YOU SURE YOU WANT TO CONTINUE?", comment: "Alert for deleting the users account."), isPresented: $delete_account_warning) {
|
.alert(NSLocalizedString("WARNING:\n\nTHIS WILL SIGN AN EVENT THAT DELETES THIS ACCOUNT.\n\nYOU WILL NO LONGER BE ABLE TO LOG INTO DAMUS USING THIS ACCOUNT KEY.\n\n ARE YOU SURE YOU WANT TO CONTINUE?", comment: "Alert for deleting the users account."), isPresented: $delete_account_warning) {
|
||||||
|
|
||||||
Button(NSLocalizedString("Cancel", comment: "Cancel deleting the user."), role: .cancel) {
|
Button(NSLocalizedString("Cancel", comment: "Cancel deleting the user."), role: .cancel) {
|
||||||
@@ -154,7 +200,6 @@ struct ConfigView: View {
|
|||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ConfigView_Previews: PreviewProvider {
|
struct ConfigView_Previews: PreviewProvider {
|
||||||
|
|||||||
Reference in New Issue
Block a user