Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
LePips committed Feb 16, 2024
1 parent c88c3e9 commit 99aafb4
Show file tree
Hide file tree
Showing 34 changed files with 160 additions and 93 deletions.
2 changes: 1 addition & 1 deletion PreferencesView/Sources/PreferencesView/Box.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2023 Jellyfin & Jellyfin Contributors
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

class Box {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2023 Jellyfin & Jellyfin Contributors
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import Foundation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2023 Jellyfin & Jellyfin Contributors
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import SwiftUI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2023 Jellyfin & Jellyfin Contributors
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import SwiftUI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2023 Jellyfin & Jellyfin Contributors
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import SwiftUI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2023 Jellyfin & Jellyfin Contributors
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import SwizzleSwift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2023 Jellyfin & Jellyfin Contributors
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import SwiftUI
Expand Down
5 changes: 2 additions & 3 deletions Shared/Coordinators/LibraryCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ final class LibraryCoordinator: NavigationCoordinatable {
Text("FIX ME")
} else {
LibraryView(parent: parent, filters: parameters.filters)



// LibraryView(viewModel: LibraryViewModel(
// parent: parent,
// type: parameters.type,
Expand Down Expand Up @@ -98,7 +97,7 @@ final class LibraryCoordinator: NavigationCoordinatable {
func makeLibrary(parameters: LibraryCoordinator.Parameters) -> LibraryCoordinator {
LibraryCoordinator(parameters: parameters)
}

// func makeFolderLibrary() -> LibraryCoordinator {
// LibraryCoordinator(parameters: .init(parent: <#T##LibraryParent#>, filters: <#T##ItemFilters#>))
// }
Expand Down
2 changes: 1 addition & 1 deletion Shared/Coordinators/MediaCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class MediaCoordinator: NavigationCoordinatable {
func makeLibrary(parameters: LibraryCoordinator.Parameters) -> LibraryCoordinator {
LibraryCoordinator(parameters: parameters)
}

func makeFolderLibrary(parameters: LibraryCoordinator.Parameters) -> LibraryCoordinator {
LibraryCoordinator(parameters: parameters)
}
Expand Down
2 changes: 1 addition & 1 deletion Shared/Extensions/Edge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2023 Jellyfin & Jellyfin Contributors
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import SwiftUI
Expand Down
10 changes: 5 additions & 5 deletions Shared/Extensions/JellyfinAPI/BaseItemDto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ extension BaseItemDto {
static var noResults: BaseItemDto {
.init(name: L10n.noResults)
}

// TODO: remove when `collectionType` becomes an enum
func includedItemTypesForCollectionType() -> [BaseItemKind]? {

guard let collectionType else { return nil }

var itemTypes: [BaseItemKind]?

switch collectionType {
case "movies":
itemTypes = [.movie]
Expand All @@ -272,7 +272,7 @@ extension BaseItemDto {
default:
itemTypes = nil
}

return itemTypes
}
}
4 changes: 2 additions & 2 deletions Shared/Extensions/JellyfinAPI/NameGuidPair.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ extension NameGuidPair: Displayable {
}
}

//extension NameGuidPair: LibraryParent {
// extension NameGuidPair: LibraryParent {
// var libraryType: BaseItemKind? { }
//}
// }

extension NameGuidPair {

Expand Down
34 changes: 34 additions & 0 deletions Shared/Extensions/Stateful.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Swiftfin is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import Foundation

protocol Stateful: AnyObject {

associatedtype State
associatedtype Action

var state: State { get set }

/// Send an action to the `Stateful` object, which will
/// `respond` to the action and set the new state.
@MainActor
func send(_ action: Action)

/// Respond to a sent action and return the new state
@MainActor
func respond(to action: Action) -> State
}

extension Stateful {

@MainActor
func send(_ action: Action) {
state = respond(to: action)
}
}
2 changes: 1 addition & 1 deletion Shared/Extensions/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Combine
import Foundation

extension Task {

func asAnyCancellable() -> AnyCancellable {
AnyCancellable(cancel)
}
Expand Down
2 changes: 1 addition & 1 deletion Shared/Extensions/UICollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2023 Jellyfin & Jellyfin Contributors
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import UIKit
2 changes: 1 addition & 1 deletion Shared/Extensions/ViewExtensions/Backport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2023 Jellyfin & Jellyfin Contributors
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import SwiftUI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import SwiftUI

struct AfterLastDisappearModifier: ViewModifier {

@State
private var lastDisappear: Date? = nil

let action: (TimeInterval) -> Void

func body(content: Content) -> some View {
content
.onAppear {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@
import SwiftUI

struct OnFinalDisappearModifier: ViewModifier {

@StateObject
private var observer: Observer

init(action: @escaping () -> Void) {
_observer = StateObject(wrappedValue: Observer(action: action))
}

func body(content: Content) -> some View {
content
.background {
Color.clear
}
}

private class Observer: ObservableObject {

private let action: () -> Void

init(action: @escaping () -> Void) {
self.action = action
}

deinit {
action()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import SwiftUI

struct OnFirstAppearModifier: ViewModifier {

@State
private var didAppear = false

let action: () -> Void

func body(content: Content) -> some View {
content
.onAppear {
Expand Down
10 changes: 5 additions & 5 deletions Shared/Extensions/ViewExtensions/ViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension View {
transformElse(self)
}
}

@ViewBuilder
@inlinable
func ifLet<Value, Content: View>(
Expand Down Expand Up @@ -237,23 +237,23 @@ extension View {
var backport: Backport<Self> {
Backport(content: self)
}

/// Perform an action on the final disappear of a `View`
func onFinalDisappear(perform action: @escaping () -> Void) -> some View {
modifier(OnFinalDisappearModifier(action: action))
}

/// Perform an action only on the first appearance of a `View`
func onFirstAppear(perform action: @escaping () -> Void) -> some View {
modifier(OnFirstAppearModifier(action: action))
}

/// Perform an action as a view appears which gives a time interval
/// from when this view last disappeared.
func afterLastDisappear(perform action: @escaping (TimeInterval) -> Void) -> some View {
modifier(AfterLastDisappearModifier(action: action))
}

func topBarTrailing(@ViewBuilder content: @escaping () -> some View) -> some View {
toolbar {
ToolbarItemGroup(placement: .topBarTrailing) {
Expand Down
2 changes: 1 addition & 1 deletion Shared/Objects/LibraryParent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import JellyfinAPI

protocol LibraryParent: Displayable, Identifiable {
var id: String? { get }

// Only called `libraryType` because `BaseItemPerson` has
// a different `type` property. However, people should have
// different views so this can be renamed when they do, or
Expand Down
2 changes: 1 addition & 1 deletion Shared/ViewModels/FilterViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class FilterViewModel: ViewModel {
)
let request = Paths.getQueryFilters(parameters: parameters)
let response = try? await userSession.client.send(request)

return response?.value.genres?
.map(\.filter) ?? []
}
Expand Down
20 changes: 10 additions & 10 deletions Shared/ViewModels/FoldersViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,40 @@ import JellyfinAPI
// is required to handle `collectionFolder` collectionType items,
// which is changed to a `folder` collectionType for view-handling
final class FolderViewModel: LibraryViewModel {

override func get(page: Int) async throws -> [BaseItemDto] {
let parameters = getItemParameters(for: page)
let request = Paths.getItemsByUserID(userID: userSession.user.id, parameters: parameters)
let response = try await userSession.client.send(request)

var validItems = (response.value.items ?? []).compactMap { item in

if item.collectionType == "collectionFolder" {
var t = item
t.collectionType = "folder"
return t
}

return item
}

return validItems
}

override func getItemParameters(for page: Int) -> Paths.GetItemsByUserIDParameters {

let filters = filterViewModel.currentFilters

var parameters = Paths.GetItemsByUserIDParameters()
parameters.parentID = parent?.id
parameters.fields = ItemFields.minimumCases
parameters.includeItemTypes = [.movie, .series, .boxSet, .folder, .collectionFolder]

parameters.limit = Self.DefaultPageSize
parameters.startIndex = page * Self.DefaultPageSize
parameters.sortOrder = filters.sortOrder.map { SortOrder(rawValue: $0.filterName) ?? .ascending }
parameters.sortBy = filters.sortBy.map(\.filterName).prepending("IsFolder")

return parameters
}
}
Loading

0 comments on commit 99aafb4

Please sign in to comment.