mirror of
https://github.com/jellyfin/Swiftfin.git
synced 2024-11-23 14:10:01 +00:00
wip (#585)
This commit is contained in:
parent
20e0789ce2
commit
93c19dbe54
@ -6,6 +6,7 @@
|
|||||||
// Copyright (c) 2022 Jellyfin & Jellyfin Contributors
|
// Copyright (c) 2022 Jellyfin & Jellyfin Contributors
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import Defaults
|
||||||
import Foundation
|
import Foundation
|
||||||
import JellyfinAPI
|
import JellyfinAPI
|
||||||
import Stinsen
|
import Stinsen
|
||||||
@ -63,9 +64,18 @@ final class LibraryCoordinator: NavigationCoordinatable {
|
|||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func makeStart() -> some View {
|
func makeStart() -> some View {
|
||||||
if let parent = parameters.parent {
|
if let parent = parameters.parent {
|
||||||
LibraryView(viewModel: LibraryViewModel(parent: parent, type: parameters.type, filters: parameters.filters))
|
if parameters.filters == .init(), let id = parent.id, let storedFilters = Defaults[.libraryFilterStore][id] {
|
||||||
|
LibraryView(viewModel: LibraryViewModel(parent: parent, type: parameters.type, filters: storedFilters, saveFilters: true))
|
||||||
|
} else {
|
||||||
|
LibraryView(viewModel: LibraryViewModel(
|
||||||
|
parent: parent,
|
||||||
|
type: parameters.type,
|
||||||
|
filters: parameters.filters,
|
||||||
|
saveFilters: false
|
||||||
|
))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LibraryView(viewModel: LibraryViewModel(filters: parameters.filters))
|
LibraryView(viewModel: LibraryViewModel(filters: parameters.filters, saveFilters: false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Combine
|
import Combine
|
||||||
|
import Defaults
|
||||||
import Foundation
|
import Foundation
|
||||||
import JellyfinAPI
|
import JellyfinAPI
|
||||||
|
|
||||||
struct ItemFilters: Hashable {
|
struct ItemFilters: Codable, Defaults.Serializable, Hashable {
|
||||||
|
|
||||||
var genres: [Filter] = []
|
var genres: [Filter] = []
|
||||||
var tags: [Filter] = []
|
|
||||||
var filters: [Filter] = []
|
var filters: [Filter] = []
|
||||||
var sortOrder: [Filter] = [APISortOrder.ascending.filter]
|
var sortOrder: [Filter] = [APISortOrder.ascending.filter]
|
||||||
var sortBy: [Filter] = [SortBy.name.filter]
|
var sortBy: [Filter] = [SortBy.name.filter]
|
||||||
@ -31,7 +31,7 @@ struct ItemFilters: Hashable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Type-erased object for use with WritableKeyPath
|
// Type-erased object for use with WritableKeyPath
|
||||||
struct Filter: Displayable, Hashable, Identifiable {
|
struct Filter: Codable, Defaults.Serializable, Displayable, Hashable, Identifiable {
|
||||||
var displayName: String
|
var displayName: String
|
||||||
var id: String?
|
var id: String?
|
||||||
var filterName: String
|
var filterName: String
|
||||||
|
@ -26,6 +26,7 @@ extension Defaults.Keys {
|
|||||||
static let lastServerUserID = Defaults.Key<String?>("lastServerUserID", suite: .generalSuite)
|
static let lastServerUserID = Defaults.Key<String?>("lastServerUserID", suite: .generalSuite)
|
||||||
static let inNetworkBandwidth = Key<Int>("InNetworkBandwidth", default: 40_000_000, suite: .generalSuite)
|
static let inNetworkBandwidth = Key<Int>("InNetworkBandwidth", default: 40_000_000, suite: .generalSuite)
|
||||||
static let outOfNetworkBandwidth = Key<Int>("OutOfNetworkBandwidth", default: 40_000_000, suite: .generalSuite)
|
static let outOfNetworkBandwidth = Key<Int>("OutOfNetworkBandwidth", default: 40_000_000, suite: .generalSuite)
|
||||||
|
static let libraryFilterStore = Key<[String: ItemFilters]>("libraryFilterStore", default: [:], suite: .generalSuite)
|
||||||
|
|
||||||
enum Customization {
|
enum Customization {
|
||||||
static let itemViewType = Key<ItemViewType>("itemViewType", default: .compactLogo, suite: .generalSuite)
|
static let itemViewType = Key<ItemViewType>("itemViewType", default: .compactLogo, suite: .generalSuite)
|
||||||
|
@ -39,7 +39,6 @@ final class FilterViewModel: ViewModel {
|
|||||||
self?.handleAPIRequestError(completion: completion)
|
self?.handleAPIRequestError(completion: completion)
|
||||||
}, receiveValue: { [weak self] queryFilters in
|
}, receiveValue: { [weak self] queryFilters in
|
||||||
self?.allFilters.genres = queryFilters.genres?.map(\.filter) ?? []
|
self?.allFilters.genres = queryFilters.genres?.map(\.filter) ?? []
|
||||||
self?.allFilters.tags = queryFilters.tags?.map(\.filter) ?? []
|
|
||||||
})
|
})
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ final class ItemTypeLibraryViewModel: PagingLibraryViewModel {
|
|||||||
let sortBy: [String] = filters.sortBy.map(\.filterName).appending("IsFolder")
|
let sortBy: [String] = filters.sortBy.map(\.filterName).appending("IsFolder")
|
||||||
let sortOrder = filters.sortOrder.map { SortOrder(rawValue: $0.filterName) ?? .ascending }
|
let sortOrder = filters.sortOrder.map { SortOrder(rawValue: $0.filterName) ?? .ascending }
|
||||||
let itemFilters: [ItemFilter] = filters.filters.compactMap { .init(rawValue: $0.filterName) }
|
let itemFilters: [ItemFilter] = filters.filters.compactMap { .init(rawValue: $0.filterName) }
|
||||||
let tags: [String] = filters.tags.map(\.filterName)
|
|
||||||
|
|
||||||
ItemsAPI.getItemsByUserId(
|
ItemsAPI.getItemsByUserId(
|
||||||
userId: SessionManager.main.currentLogin.user.id,
|
userId: SessionManager.main.currentLogin.user.id,
|
||||||
@ -51,7 +50,6 @@ final class ItemTypeLibraryViewModel: PagingLibraryViewModel {
|
|||||||
includeItemTypes: itemTypes,
|
includeItemTypes: itemTypes,
|
||||||
filters: itemFilters,
|
filters: itemFilters,
|
||||||
sortBy: sortBy,
|
sortBy: sortBy,
|
||||||
tags: tags,
|
|
||||||
enableUserData: true,
|
enableUserData: true,
|
||||||
genreIds: genreIDs
|
genreIds: genreIDs
|
||||||
)
|
)
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Combine
|
import Combine
|
||||||
|
import Defaults
|
||||||
import JellyfinAPI
|
import JellyfinAPI
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import UIKit
|
import UIKit
|
||||||
@ -18,6 +19,7 @@ final class LibraryViewModel: PagingLibraryViewModel {
|
|||||||
|
|
||||||
let parent: LibraryParent?
|
let parent: LibraryParent?
|
||||||
let type: LibraryParentType
|
let type: LibraryParentType
|
||||||
|
private let saveFilters: Bool
|
||||||
|
|
||||||
var libraryCoordinatorParameters: LibraryCoordinator.Parameters {
|
var libraryCoordinatorParameters: LibraryCoordinator.Parameters {
|
||||||
if let parent = parent {
|
if let parent = parent {
|
||||||
@ -27,32 +29,29 @@ final class LibraryViewModel: PagingLibraryViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init(filters: ItemFilters) {
|
convenience init(filters: ItemFilters, saveFilters: Bool = false) {
|
||||||
self.parent = nil
|
self.init(parent: nil, type: .library, filters: filters, saveFilters: saveFilters)
|
||||||
self.type = .library
|
|
||||||
self.filterViewModel = .init(parent: nil, currentFilters: filters)
|
|
||||||
super.init()
|
|
||||||
|
|
||||||
filterViewModel.$currentFilters
|
|
||||||
.sink { newFilters in
|
|
||||||
self.requestItems(with: newFilters, replaceCurrentItems: true)
|
|
||||||
}
|
|
||||||
.store(in: &cancellables)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init(
|
init(
|
||||||
parent: LibraryParent,
|
parent: LibraryParent?,
|
||||||
type: LibraryParentType,
|
type: LibraryParentType,
|
||||||
filters: ItemFilters = .init()
|
filters: ItemFilters = .init(),
|
||||||
|
saveFilters: Bool = false
|
||||||
) {
|
) {
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.type = type
|
self.type = type
|
||||||
self.filterViewModel = .init(parent: parent, currentFilters: filters)
|
self.filterViewModel = .init(parent: parent, currentFilters: filters)
|
||||||
|
self.saveFilters = saveFilters
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
filterViewModel.$currentFilters
|
filterViewModel.$currentFilters
|
||||||
.sink { newFilters in
|
.sink { newFilters in
|
||||||
self.requestItems(with: newFilters, replaceCurrentItems: true)
|
self.requestItems(with: newFilters, replaceCurrentItems: true)
|
||||||
|
|
||||||
|
if self.saveFilters, let id = self.parent?.id {
|
||||||
|
Defaults[.libraryFilterStore][id] = newFilters
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
@ -102,7 +101,6 @@ final class LibraryViewModel: PagingLibraryViewModel {
|
|||||||
let sortBy: [String] = filters.sortBy.map(\.filterName).appending("IsFolder")
|
let sortBy: [String] = filters.sortBy.map(\.filterName).appending("IsFolder")
|
||||||
let sortOrder = filters.sortOrder.map { SortOrder(rawValue: $0.filterName) ?? .ascending }
|
let sortOrder = filters.sortOrder.map { SortOrder(rawValue: $0.filterName) ?? .ascending }
|
||||||
let itemFilters: [ItemFilter] = filters.filters.compactMap { .init(rawValue: $0.filterName) }
|
let itemFilters: [ItemFilter] = filters.filters.compactMap { .init(rawValue: $0.filterName) }
|
||||||
let tags: [String] = filters.tags.map(\.filterName)
|
|
||||||
|
|
||||||
ItemsAPI.getItemsByUserId(
|
ItemsAPI.getItemsByUserId(
|
||||||
userId: SessionManager.main.currentLogin.user.id,
|
userId: SessionManager.main.currentLogin.user.id,
|
||||||
@ -116,7 +114,6 @@ final class LibraryViewModel: PagingLibraryViewModel {
|
|||||||
includeItemTypes: includeItemTypes,
|
includeItemTypes: includeItemTypes,
|
||||||
filters: itemFilters,
|
filters: itemFilters,
|
||||||
sortBy: sortBy,
|
sortBy: sortBy,
|
||||||
tags: tags,
|
|
||||||
enableUserData: true,
|
enableUserData: true,
|
||||||
personIds: personIDs,
|
personIds: personIDs,
|
||||||
studioIds: studioIDs,
|
studioIds: studioIDs,
|
||||||
|
@ -86,7 +86,6 @@ final class SearchViewModel: ViewModel {
|
|||||||
let sortBy: [String] = filters.sortBy.map(\.filterName)
|
let sortBy: [String] = filters.sortBy.map(\.filterName)
|
||||||
let sortOrder = filters.sortOrder.map { SortOrder(rawValue: $0.filterName) ?? .ascending }
|
let sortOrder = filters.sortOrder.map { SortOrder(rawValue: $0.filterName) ?? .ascending }
|
||||||
let itemFilters: [ItemFilter] = filters.filters.compactMap { .init(rawValue: $0.filterName) }
|
let itemFilters: [ItemFilter] = filters.filters.compactMap { .init(rawValue: $0.filterName) }
|
||||||
let tags: [String] = filters.tags.map(\.filterName)
|
|
||||||
|
|
||||||
ItemsAPI.getItemsByUserId(
|
ItemsAPI.getItemsByUserId(
|
||||||
userId: SessionManager.main.currentLogin.user.id,
|
userId: SessionManager.main.currentLogin.user.id,
|
||||||
@ -98,7 +97,6 @@ final class SearchViewModel: ViewModel {
|
|||||||
includeItemTypes: [itemType],
|
includeItemTypes: [itemType],
|
||||||
filters: itemFilters,
|
filters: itemFilters,
|
||||||
sortBy: sortBy,
|
sortBy: sortBy,
|
||||||
tags: tags,
|
|
||||||
enableUserData: true,
|
enableUserData: true,
|
||||||
genreIds: genreIDs,
|
genreIds: genreIDs,
|
||||||
enableImages: true
|
enableImages: true
|
||||||
|
@ -39,16 +39,6 @@ struct FilterDrawerHStack: View {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterDrawerButton(title: L10n.tags, activated: viewModel.currentFilters.tags != [])
|
|
||||||
.onSelect {
|
|
||||||
onSelect(.init(
|
|
||||||
title: L10n.tags,
|
|
||||||
viewModel: viewModel,
|
|
||||||
filter: \.tags,
|
|
||||||
selectorType: .multi
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
FilterDrawerButton(title: L10n.filters, activated: viewModel.currentFilters.filters != [])
|
FilterDrawerButton(title: L10n.filters, activated: viewModel.currentFilters.filters != [])
|
||||||
.onSelect {
|
.onSelect {
|
||||||
onSelect(.init(
|
onSelect(.init(
|
||||||
|
Loading…
Reference in New Issue
Block a user