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: return Text("Home", comment: "Navigation bar title for Home view where posts and replies appear from those who the user is following.")
Image("damus-home") .bold()
.resizable() case .dms:
.frame(width:30,height:30) return Text("DMs", comment: "Toolbar label for DMs view, where DM is the English abbreviation for Direct Message.")
.shadow(color: Color("DamusPurple"), radius: 2) .bold()
case .dms: case .notifications:
Text("DMs", comment: "Toolbar label for DMs view, where DM is the English abbreviation for Direct Message.") return Text("Notifications", comment: "Toolbar label for Notifications view.")
.bold() .bold()
case .notifications: case .search:
Text("Notifications", comment: "Toolbar label for Notifications view.") return Text("Universe 🛸", comment: "Toolbar label for the universal view where posts from all connected relay servers appear.")
.bold() .bold()
case .search: case .none:
Text("Universe 🛸", comment: "Toolbar label for the universal view where posts from all connected relay servers appear.") return Text(verbatim: "")
.bold()
case .none:
Text(verbatim: "")
}
} }
} }
@@ -203,25 +199,21 @@ 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) {
timelineNavItem VStack {
.opacity(isSideBarOpened ? 0 : 1) if selected_timeline == .home {
.animation(isSideBarOpened ? .none : .default, value: isSideBarOpened) Image("damus-home")
.resizable()
.frame(width:30,height:30)
.shadow(color: Color("DamusPurple"), radius: 2)
} else {
timelineNavItem
.opacity(isSideBarOpened ? 0 : 1)
.animation(isSideBarOpened ? .none : .default, value: isSideBarOpened)
}
}
} }
} }
.ignoresSafeArea(.keyboard) .ignoresSafeArea(.keyboard)