mirror of
https://github.com/yattee/yattee.git
synced 2025-04-27 15:30:33 +05:30
Fix menu commands
This commit is contained in:
parent
8b4838dca5
commit
c893e5dc38
@ -14,6 +14,31 @@ final class NavigationModel: ObservableObject {
|
|||||||
case nowPlaying
|
case nowPlaying
|
||||||
case search
|
case search
|
||||||
|
|
||||||
|
var stringValue: String {
|
||||||
|
switch self {
|
||||||
|
case .favorites:
|
||||||
|
return "favorites"
|
||||||
|
case .subscriptions:
|
||||||
|
return "subscriptions"
|
||||||
|
case .popular:
|
||||||
|
return "popular"
|
||||||
|
case .trending:
|
||||||
|
return "trending"
|
||||||
|
case .playlists:
|
||||||
|
return "playlists"
|
||||||
|
case let .channel(string):
|
||||||
|
return "channel\(string)"
|
||||||
|
case let .playlist(string):
|
||||||
|
return "playlist\(string)"
|
||||||
|
case .recentlyOpened:
|
||||||
|
return "recentlyOpened"
|
||||||
|
case .search:
|
||||||
|
return "search"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var playlistID: Playlist.ID? {
|
var playlistID: Playlist.ID? {
|
||||||
if case let .playlist(id) = self {
|
if case let .playlist(id) = self {
|
||||||
return id
|
return id
|
||||||
|
@ -12,29 +12,29 @@ struct MenuCommands: Commands {
|
|||||||
private var navigationMenu: some Commands {
|
private var navigationMenu: some Commands {
|
||||||
CommandGroup(before: .windowSize) {
|
CommandGroup(before: .windowSize) {
|
||||||
Button("Favorites") {
|
Button("Favorites") {
|
||||||
model.navigation?.tabSelection = .favorites
|
setTabSelection(.favorites)
|
||||||
}
|
}
|
||||||
.keyboardShortcut("1")
|
.keyboardShortcut("1")
|
||||||
|
|
||||||
Button("Subscriptions") {
|
Button("Subscriptions") {
|
||||||
model.navigation?.tabSelection = .subscriptions
|
setTabSelection(.subscriptions)
|
||||||
}
|
}
|
||||||
.disabled(subscriptionsDisabled)
|
.disabled(subscriptionsDisabled)
|
||||||
.keyboardShortcut("2")
|
.keyboardShortcut("2")
|
||||||
|
|
||||||
Button("Popular") {
|
Button("Popular") {
|
||||||
model.navigation?.tabSelection = .popular
|
setTabSelection(.popular)
|
||||||
}
|
}
|
||||||
.disabled(!(model.accounts?.app.supportsPopular ?? false))
|
.disabled(!(model.accounts?.app.supportsPopular ?? false))
|
||||||
.keyboardShortcut("3")
|
.keyboardShortcut("3")
|
||||||
|
|
||||||
Button("Trending") {
|
Button("Trending") {
|
||||||
model.navigation?.tabSelection = .trending
|
setTabSelection(.trending)
|
||||||
}
|
}
|
||||||
.keyboardShortcut("4")
|
.keyboardShortcut("4")
|
||||||
|
|
||||||
Button("Search") {
|
Button("Search") {
|
||||||
model.navigation?.tabSelection = .search
|
setTabSelection(.search)
|
||||||
}
|
}
|
||||||
.keyboardShortcut("f")
|
.keyboardShortcut("f")
|
||||||
|
|
||||||
@ -42,6 +42,15 @@ struct MenuCommands: Commands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func setTabSelection(_ tabSelection: NavigationModel.TabSelection) {
|
||||||
|
guard let navigation = model.navigation else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
navigation.sidebarSectionChanged.toggle()
|
||||||
|
navigation.tabSelection = tabSelection
|
||||||
|
}
|
||||||
|
|
||||||
private var subscriptionsDisabled: Bool {
|
private var subscriptionsDisabled: Bool {
|
||||||
!(
|
!(
|
||||||
(model.accounts?.app.supportsSubscriptions ?? false) && model.accounts?.signedIn ?? false
|
(model.accounts?.app.supportsSubscriptions ?? false) && model.accounts?.signedIn ?? false
|
||||||
|
@ -45,6 +45,7 @@ struct Sidebar: View {
|
|||||||
Label("Favorites", systemImage: "heart")
|
Label("Favorites", systemImage: "heart")
|
||||||
.accessibility(label: Text("Favorites"))
|
.accessibility(label: Text("Favorites"))
|
||||||
}
|
}
|
||||||
|
.id("favorites")
|
||||||
}
|
}
|
||||||
if visibleSections.contains(.subscriptions),
|
if visibleSections.contains(.subscriptions),
|
||||||
accounts.app.supportsSubscriptions && accounts.signedIn
|
accounts.app.supportsSubscriptions && accounts.signedIn
|
||||||
@ -53,6 +54,7 @@ struct Sidebar: View {
|
|||||||
Label("Subscriptions", systemImage: "star.circle")
|
Label("Subscriptions", systemImage: "star.circle")
|
||||||
.accessibility(label: Text("Subscriptions"))
|
.accessibility(label: Text("Subscriptions"))
|
||||||
}
|
}
|
||||||
|
.id("subscriptions")
|
||||||
}
|
}
|
||||||
|
|
||||||
if visibleSections.contains(.popular), accounts.app.supportsPopular {
|
if visibleSections.contains(.popular), accounts.app.supportsPopular {
|
||||||
@ -60,6 +62,7 @@ struct Sidebar: View {
|
|||||||
Label("Popular", systemImage: "arrow.up.right.circle")
|
Label("Popular", systemImage: "arrow.up.right.circle")
|
||||||
.accessibility(label: Text("Popular"))
|
.accessibility(label: Text("Popular"))
|
||||||
}
|
}
|
||||||
|
.id("popular")
|
||||||
}
|
}
|
||||||
|
|
||||||
if visibleSections.contains(.trending) {
|
if visibleSections.contains(.trending) {
|
||||||
@ -67,12 +70,14 @@ struct Sidebar: View {
|
|||||||
Label("Trending", systemImage: "chart.bar")
|
Label("Trending", systemImage: "chart.bar")
|
||||||
.accessibility(label: Text("Trending"))
|
.accessibility(label: Text("Trending"))
|
||||||
}
|
}
|
||||||
|
.id("trending")
|
||||||
}
|
}
|
||||||
|
|
||||||
NavigationLink(destination: LazyView(SearchView()), tag: TabSelection.search, selection: $navigation.tabSelection) {
|
NavigationLink(destination: LazyView(SearchView()), tag: TabSelection.search, selection: $navigation.tabSelection) {
|
||||||
Label("Search", systemImage: "magnifyingglass")
|
Label("Search", systemImage: "magnifyingglass")
|
||||||
.accessibility(label: Text("Search"))
|
.accessibility(label: Text("Search"))
|
||||||
}
|
}
|
||||||
|
.id("search")
|
||||||
.keyboardShortcut("f")
|
.keyboardShortcut("f")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,8 +85,12 @@ struct Sidebar: View {
|
|||||||
private func scrollScrollViewToItem(scrollView: ScrollViewProxy, for selection: TabSelection) {
|
private func scrollScrollViewToItem(scrollView: ScrollViewProxy, for selection: TabSelection) {
|
||||||
if case .recentlyOpened = selection {
|
if case .recentlyOpened = selection {
|
||||||
scrollView.scrollTo("recentlyOpened")
|
scrollView.scrollTo("recentlyOpened")
|
||||||
|
return
|
||||||
} else if case let .playlist(id) = selection {
|
} else if case let .playlist(id) = selection {
|
||||||
scrollView.scrollTo(id)
|
scrollView.scrollTo(id)
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollView.scrollTo(selection.stringValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user