mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 10:44:06 +00:00
Minor fixes, split files into folders
This commit is contained in:
22
Shared/Views/PopularView.swift
Normal file
22
Shared/Views/PopularView.swift
Normal file
@@ -0,0 +1,22 @@
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct PopularView: View {
|
||||
@ObservedObject private var store = Store<[Video]>()
|
||||
|
||||
var resource = InvidiousAPI.shared.popular
|
||||
|
||||
init() {
|
||||
resource.addObserver(store)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VideosView(videos: store.collection)
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("Popular")
|
||||
#endif
|
||||
.onAppear {
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
}
|
||||
}
|
58
Shared/Views/SearchView.swift
Normal file
58
Shared/Views/SearchView.swift
Normal file
@@ -0,0 +1,58 @@
|
||||
import Defaults
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct SearchView: View {
|
||||
@Default(.searchQuery) private var queryText
|
||||
@Default(.searchSortOrder) private var searchSortOrder
|
||||
@Default(.searchDate) private var searchDate
|
||||
@Default(.searchDuration) private var searchDuration
|
||||
|
||||
@EnvironmentObject<SearchState> private var state
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
VideosView(videos: state.store.collection)
|
||||
|
||||
if state.store.collection.isEmpty && !state.isLoading && !state.query.isEmpty {
|
||||
Text("No results")
|
||||
|
||||
if searchFiltersActive {
|
||||
Button("Reset search filters") {
|
||||
Defaults.reset(.searchDate, .searchDuration)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.searchable(text: $queryText)
|
||||
.onAppear {
|
||||
state.changeQuery { query in
|
||||
query.query = queryText
|
||||
query.sortBy = searchSortOrder
|
||||
query.date = searchDate
|
||||
query.duration = searchDuration
|
||||
}
|
||||
}
|
||||
.onChange(of: queryText) { queryText in
|
||||
state.changeQuery { query in query.query = queryText }
|
||||
}
|
||||
.onChange(of: searchSortOrder) { order in
|
||||
state.changeQuery { query in query.sortBy = order }
|
||||
}
|
||||
.onChange(of: searchDate) { date in
|
||||
state.changeQuery { query in query.date = date }
|
||||
}
|
||||
.onChange(of: searchDuration) { duration in
|
||||
state.changeQuery { query in query.duration = duration }
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("Search")
|
||||
#endif
|
||||
}
|
||||
|
||||
var searchFiltersActive: Bool {
|
||||
searchDate != nil || searchDuration != nil
|
||||
}
|
||||
}
|
24
Shared/Views/SubscriptionsView.swift
Normal file
24
Shared/Views/SubscriptionsView.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SubscriptionsView: View {
|
||||
@ObservedObject private var store = Store<[Video]>()
|
||||
|
||||
var resource = InvidiousAPI.shared.subscriptions
|
||||
|
||||
init() {
|
||||
resource.addObserver(store)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VideosView(videos: store.collection)
|
||||
.onAppear {
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
.refreshable {
|
||||
resource.load()
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("Subscriptions")
|
||||
#endif
|
||||
}
|
||||
}
|
57
Shared/Views/VideoContextMenuView.swift
Normal file
57
Shared/Views/VideoContextMenuView.swift
Normal file
@@ -0,0 +1,57 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct VideoContextMenuView: View {
|
||||
@EnvironmentObject<NavigationState> private var navigationState
|
||||
|
||||
let video: Video
|
||||
|
||||
@Default(.showingAddToPlaylist) var showingAddToPlaylist
|
||||
@Default(.videoIDToAddToPlaylist) var videoIDToAddToPlaylist
|
||||
|
||||
var body: some View {
|
||||
openChannelButton(from: video)
|
||||
|
||||
openVideoDetailsButton
|
||||
|
||||
if navigationState.tabSelection == .playlists {
|
||||
removeFromPlaylistButton
|
||||
} else {
|
||||
addToPlaylistButton
|
||||
}
|
||||
}
|
||||
|
||||
func openChannelButton(from video: Video) -> some View {
|
||||
Button("\(video.author) Channel") {
|
||||
navigationState.openChannel(Channel.from(video: video))
|
||||
}
|
||||
}
|
||||
|
||||
func closeChannelButton(from video: Video) -> some View {
|
||||
Button("Close \(Channel.from(video: video).name) Channel") {
|
||||
navigationState.closeChannel()
|
||||
}
|
||||
}
|
||||
|
||||
var openVideoDetailsButton: some View {
|
||||
Button("Open video details") {
|
||||
navigationState.openVideoDetails(video)
|
||||
}
|
||||
}
|
||||
|
||||
var addToPlaylistButton: some View {
|
||||
Button("Add to playlist...") {
|
||||
videoIDToAddToPlaylist = video.id
|
||||
showingAddToPlaylist = true
|
||||
}
|
||||
}
|
||||
|
||||
var removeFromPlaylistButton: some View {
|
||||
Button("Remove from playlist", role: .destructive) {
|
||||
let resource = InvidiousAPI.shared.playlistVideo(Defaults[.selectedPlaylistID]!, video.indexID!)
|
||||
resource.request(.delete).onSuccess { _ in
|
||||
InvidiousAPI.shared.playlists.load()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user