Convert ContentView navigation links

This commit is contained in:
Scott Penrose
2023-06-03 15:37:46 -04:00
committed by William Casarin
parent f361f55bd5
commit 8258c5beb0

View File

@@ -82,14 +82,6 @@ struct ContentView: View {
@State var damus_state: DamusState? = nil
@SceneStorage("ContentView.selected_timeline") var selected_timeline: Timeline = .home
@State var is_deleted_account: Bool = false
@State var active_profile: String? = nil
@State var active_search: NostrFilter? = nil
@State var active_event: NostrEvent? = nil
@State var profile_open: Bool = false
@State var thread_open: Bool = false
@State var search_open: Bool = false
@State var wallet_open: Bool = false
@State var active_nwc: WalletConnectURL? = nil
@State var muting: String? = nil
@State var confirm_mute: Bool = false
@State var user_muted_confirm: Bool = false
@@ -156,10 +148,7 @@ struct ContentView: View {
}
func popToRoot() {
profile_open = false
thread_open = false
search_open = false
wallet_open = false
navigationCoordinator.popToRoot()
isSideBarOpened = false
}
@@ -170,21 +159,6 @@ struct ContentView: View {
func MainContent(damus: DamusState) -> some View {
VStack {
NavigationLink(destination: WalletView(damus_state: damus, model: damus_state!.wallet), isActive: $wallet_open) {
EmptyView()
}
NavigationLink(destination: MaybeProfileView, isActive: $profile_open) {
EmptyView()
}
if let active_event {
let thread = ThreadModel(event: active_event, damus_state: damus_state!)
NavigationLink(destination: ThreadView(state: damus_state!, thread: thread), isActive: $thread_open) {
EmptyView()
}
}
NavigationLink(destination: MaybeSearchView, isActive: $search_open) {
EmptyView()
}
switch selected_timeline {
case .search:
if #available(iOS 16.0, *) {
@@ -226,28 +200,6 @@ struct ContentView: View {
}
}
var MaybeSearchView: some View {
Group {
if let search = self.active_search {
SearchView(appstate: damus_state!, search: SearchModel(state: damus_state!, search: search))
} else {
EmptyView()
}
}
}
var MaybeProfileView: some View {
Group {
if let pk = self.active_profile {
let profile_model = ProfileModel(pubkey: pk, damus: damus_state!)
let followers = FollowersModel(damus_state: damus_state!, target: pk)
ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers)
} else {
EmptyView()
}
}
}
func MaybeReportView(target: ReportTarget) -> some View {
Group {
if let damus_state {
@@ -264,25 +216,29 @@ struct ContentView: View {
func open_event(ev: NostrEvent) {
popToRoot()
self.active_event = ev
self.thread_open = true
let thread = ThreadModel(event: ev, damus_state: damus_state!)
navigationCoordinator.push(route: Route.Thread(thread: thread))
}
func open_wallet(nwc: WalletConnectURL) {
self.damus_state!.wallet.new(nwc)
self.wallet_open = true
navigationCoordinator.push(route: Route.Wallet(wallet: damus_state!.wallet))
}
func open_profile(id: String) {
popToRoot()
self.active_profile = id
self.profile_open = true
let profile_model = ProfileModel(pubkey: id, damus: damus_state!)
let followers = FollowersModel(damus_state: damus_state!, target: id)
navigationCoordinator.push(route: Route.Profile(profile: profile_model, followers: followers))
}
func open_search(filt: NostrFilter) {
popToRoot()
self.active_search = filt
self.search_open = true
let search = SearchModel(state: damus_state!, search: filt)
navigationCoordinator.push(route: Route.Search(search: search))
}
var body: some View {