damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit c679be96442b8020db82fb40b7061affbfa33f41
parent 9f701a7d441d42e5509f19ec45e2fbd3afcc1bad
Author: Bryan Montz <bryanmontz@me.com>
Date:   Fri, 17 Feb 2023 06:30:48 -0600

Top-level tab state restoration

Changelog-Added: Top-level tab state restoration
Closes: #634

Diffstat:
Mdamus/ContentView.swift | 7++-----
Mdamus/Models/UserSettingsStore.swift | 3---
Mdamus/Views/MainTabView.swift | 4++--
Mdamus/Views/Notifications/NotificationsView.swift | 45+++++++++++++++++----------------------------
4 files changed, 21 insertions(+), 38 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -62,7 +62,7 @@ struct ContentView: View { @State var status: String = "Not connected" @State var active_sheet: Sheets? = nil @State var damus_state: DamusState? = nil - @State var selected_timeline: Timeline? = .home + @SceneStorage("ContentView.selected_timeline") var selected_timeline: Timeline = .home @State var is_deleted_account: Bool = false @State var is_profile_open: Bool = false @State var event: NostrEvent? = nil @@ -76,7 +76,7 @@ struct ContentView: View { @State var confirm_mute: Bool = false @State var user_muted_confirm: Bool = false @State var confirm_overwrite_mutelist: Bool = false - @State var filter_state : FilterState = .posts_and_replies + @SceneStorage("ContentView.filter_state") var filter_state : FilterState = .posts_and_replies @State private var isSideBarOpened = false @StateObject var home: HomeModel = HomeModel() @@ -180,9 +180,6 @@ struct ContentView: View { case .dms: DirectMessagesView(damus_state: damus_state!, model: damus_state!.dms, settings: damus_state!.settings) - - case .none: - EmptyView() } } .navigationBarTitle(timeline_name(selected_timeline), displayMode: .inline) diff --git a/damus/Models/UserSettingsStore.swift b/damus/Models/UserSettingsStore.swift @@ -152,9 +152,6 @@ class UserSettingsStore: ObservableObject { @StringSetting(key: "friend_filter", default_value: .all) var friend_filter: FriendFilter - - @StringSetting(key: "notification_state", default_value: .all) - var notification_state: NotificationFilterState @StringSetting(key: "translation_service", default_value: .none) var translation_service: TranslationService diff --git a/damus/Views/MainTabView.swift b/damus/Views/MainTabView.swift @@ -37,7 +37,7 @@ func show_indicator(timeline: Timeline, current: NewEventsBits, indicator_settin struct TabButton: View { let timeline: Timeline let img: String - @Binding var selected: Timeline? + @Binding var selected: Timeline @Binding var new_events: NewEventsBits let settings: UserSettingsStore @@ -75,7 +75,7 @@ struct TabButton: View { struct TabBar: View { @Binding var new_events: NewEventsBits - @Binding var selected: Timeline? + @Binding var selected: Timeline let settings: UserSettingsStore let action: (Timeline) -> () diff --git a/damus/Views/Notifications/NotificationsView.swift b/damus/Views/Notifications/NotificationsView.swift @@ -74,25 +74,13 @@ class NotificationFilter: ObservableObject, Equatable { } } -enum NotificationFilterState: String, StringCodable { +enum NotificationFilterState: String { case all case zaps case replies - init?(from string: String) { - guard let val = NotificationFilterState(rawValue: string) else { - return nil - } - - self = val - } - - func to_string() -> String { - self.rawValue - } - func is_other( item: NotificationItem) -> Bool { - return item.is_zap == nil && item.is_reply == nil + item.is_zap == nil && item.is_reply == nil } func filter(_ item: NotificationItem) -> Bool { @@ -110,7 +98,8 @@ enum NotificationFilterState: String, StringCodable { struct NotificationsView: View { let state: DamusState @ObservedObject var notifications: NotificationsModel - @StateObject var filter_state: NotificationFilter = NotificationFilter() + @StateObject var filter = NotificationFilter() + @SceneStorage("NotificationsView.filter_state") var filter_state: NotificationFilterState = .all @Environment(\.colorScheme) var colorScheme @@ -123,14 +112,14 @@ struct NotificationsView: View { } var body: some View { - TabView(selection: $filter_state.state) { + TabView(selection: $filter_state) { // This is needed or else there is a bug when switching from the 3rd or 2nd tab to first. no idea why. mystery NotificationTab( NotificationFilter( state: .all, - fine_filter: filter_state.fine_filter + fine_filter: filter.fine_filter ) ) .tag(NotificationFilterState.all) @@ -138,7 +127,7 @@ struct NotificationsView: View { NotificationTab( NotificationFilter( state: .zaps, - fine_filter: filter_state.fine_filter + fine_filter: filter.fine_filter ) ) .tag(NotificationFilterState.zaps) @@ -146,31 +135,31 @@ struct NotificationsView: View { NotificationTab( NotificationFilter( state: .replies, - fine_filter: filter_state.fine_filter + fine_filter: filter.fine_filter ) ) .tag(NotificationFilterState.replies) } .toolbar { ToolbarItem(placement: .navigationBarTrailing) { - if would_filter_non_friends_from_notifications(contacts: state.contacts, state: self.filter_state.state, items: self.notifications.notifications) { - FriendsButton(filter: $filter_state.fine_filter) + if would_filter_non_friends_from_notifications(contacts: state.contacts, state: filter_state, items: self.notifications.notifications) { + FriendsButton(filter: $filter.fine_filter) } } } - .onChange(of: filter_state.fine_filter) { val in + .onChange(of: filter.fine_filter) { val in state.settings.friend_filter = val } - .onChange(of: filter_state.state) { val in - state.settings.notification_state = val + .onChange(of: filter_state) { val in + filter.state = val } .onAppear { - self.filter_state.fine_filter = state.settings.friend_filter - self.filter_state.state = state.settings.notification_state + self.filter.fine_filter = state.settings.friend_filter + filter.state = filter_state } .safeAreaInset(edge: .top, spacing: 0) { VStack(spacing: 0) { - CustomPicker(selection: $filter_state.state, content: { + CustomPicker(selection: $filter_state, content: { Text("All", comment: "Label for filter for all notifications.") .tag(NotificationFilterState.all) @@ -221,7 +210,7 @@ struct NotificationsView: View { struct NotificationsView_Previews: PreviewProvider { static var previews: some View { - NotificationsView(state: test_damus_state(), notifications: NotificationsModel(), filter_state: NotificationFilter()) + NotificationsView(state: test_damus_state(), notifications: NotificationsModel(), filter: NotificationFilter()) } }