Dedupe timelineNavItem

Changelog-Fixed: Fix issue where navbar back button would show the wrong text
Closes: #687
This commit is contained in:
Jack Chakany
2023-03-05 14:24:32 -05:00
committed by William Casarin
parent a4855775ef
commit 8a70240968

View File

@@ -148,26 +148,22 @@ struct ContentView: View {
isSideBarOpened = false isSideBarOpened = false
} }
var timelineNavItem: some View { var timelineNavItem: Text {
VStack {
switch selected_timeline { switch selected_timeline {
case .home: case .home:
Image("damus-home") return Text("Home", comment: "Navigation bar title for Home view where posts and replies appear from those who the user is following.")
.resizable() .bold()
.frame(width:30,height:30)
.shadow(color: Color("DamusPurple"), radius: 2)
case .dms: case .dms:
Text("DMs", comment: "Toolbar label for DMs view, where DM is the English abbreviation for Direct Message.") return Text("DMs", comment: "Toolbar label for DMs view, where DM is the English abbreviation for Direct Message.")
.bold() .bold()
case .notifications: case .notifications:
Text("Notifications", comment: "Toolbar label for Notifications view.") return Text("Notifications", comment: "Toolbar label for Notifications view.")
.bold() .bold()
case .search: case .search:
Text("Universe 🛸", comment: "Toolbar label for the universal view where posts from all connected relay servers appear.") return Text("Universe 🛸", comment: "Toolbar label for the universal view where posts from all connected relay servers appear.")
.bold() .bold()
case .none: case .none:
Text(verbatim: "") return Text(verbatim: "")
}
} }
} }
@@ -203,27 +199,23 @@ struct ContentView: View {
EmptyView() EmptyView()
} }
} }
.navigationBarTitle({ .navigationBarTitle(timelineNavItem, displayMode: .inline)
switch selected_timeline {
case .home:
return NSLocalizedString("Home", comment: "Navigation bar title for Home view where posts and replies appear from those who the user is following.")
case .dms:
return NSLocalizedString("DMs", comment: "Navigation bar title for DMs view, where DM is the English abbreviation for Direct Message.")
case .notifications:
return NSLocalizedString("Notifications", comment: "Navigation bar title for Notifications view.")
case .search:
return NSLocalizedString("Universe 🛸", comment: "Navigation bar title for the universal view where posts from all connected relay servers appear.")
case .none:
return NSLocalizedString("", comment: "Toolbar label for unknown views. This label would be displayed only if a new timeline view is added but a toolbar label was not explicitly assigned to it yet.")
}
}(), displayMode: .inline)
.toolbar { .toolbar {
ToolbarItem(placement: .principal) { ToolbarItem(placement: .principal) {
VStack {
if selected_timeline == .home {
Image("damus-home")
.resizable()
.frame(width:30,height:30)
.shadow(color: Color("DamusPurple"), radius: 2)
} else {
timelineNavItem timelineNavItem
.opacity(isSideBarOpened ? 0 : 1) .opacity(isSideBarOpened ? 0 : 1)
.animation(isSideBarOpened ? .none : .default, value: isSideBarOpened) .animation(isSideBarOpened ? .none : .default, value: isSideBarOpened)
} }
} }
}
}
.ignoresSafeArea(.keyboard) .ignoresSafeArea(.keyboard)
} }