Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS & tvOS] ItemLibraryViewModel - Cleanup #1411

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

JPKribs
Copy link
Member

@JPKribs JPKribs commented Jan 26, 2025

Summary

The goal of this. PR is to touch up the ItemLibraryViewModel to accommodate some of the new items that we've added since it was created. @LePips left some notes in in there and ItemTypeLIbraryViewModel and mostly I am going to try and follow them.

Primary change was I removed ItemTypeLIbraryViewModel and moved ItemType to the the ItemFilterCollection instead. I've tested on tvOS and all libraries are correct including the the ItemType sections for TV Shows and Movies. Because of this, we are still able use a single ViewModel for both existing Library types we have on iOS and tvOS.

This PR is based on: #1409 (review)

@JPKribs
Copy link
Member Author

JPKribs commented Jan 26, 2025

@LePips This all looks correct and is working as intended. Please let me know if there is anything that I should be doing differently or if you had any other cleanup intended! The only missing item I'd like to roll into this PR is from ItemLibraryViewModel.

I was looking at adding this (see below) but might need a bit more context. Since LibraryParent is a protocol, do we want that there? Or on the enum for libraryType? Or a LibraryParent func in ItemLibraryViewModel?

    func itemParameters(for page: Int?) -> Paths.GetItemsByUserIDParameters {

        var libraryID: String?
        var personIDs: [String]?
        var studioIDs: [String]?
        var isRecursive: Bool? = true

        // TODO: this logic should be moved to a `LibraryParent` function
        //       that transforms a `GetItemsByUserIDParameters` struct, instead
        //       of having to do this case-by-case.

        if let libraryType = parent?.libraryType, let id = parent?.id {
            switch libraryType {
            case .collectionFolder, .userView:
                libraryID = id
            case .folder:
                libraryID = id
                isRecursive = nil
            case .person:
                personIDs = [id]
            case .studio:
                studioIDs = [id]
            default: ()
            }
        }

        var parameters = Paths.GetItemsByUserIDParameters()
        parameters.enableUserData = true
        parameters.fields = .MinimumFields
        parameters.isRecursive = isRecursive
        parameters.parentID = libraryID
        parameters.personIDs = personIDs
        parameters.studioIDs = studioIDs
        ...

One unintended side effect of using the includeItemTypes for the filters is they were previously set defaulted to [.movie, .series, .boxSet] for all ItemLibraryViewModel. I added a ItemLibraryViewModel default to [.movie, .series, .boxSet] that are used if the FilterViewModel is not present. FilterViewModel defaults to [.movie, .series, .boxSet] as well so if there is a library that does not specifically set a type this will use the previous values as well.

@JPKribs JPKribs requested a review from LePips January 28, 2025 02:06
@JPKribs JPKribs added the enhancement New feature or request label Jan 28, 2025
@JPKribs JPKribs changed the title [iOS & tvOS] ItemLibraryViewModel Cleanup [iOS & tvOS] ItemLibraryViewModel - Cleanup Jan 29, 2025
…gLibraryView` to have the default filters. This was originally in place. This Commit just ensures that iOS and tvOS have the same implementation.
@@ -102,7 +102,7 @@ struct PagingLibraryView<Element: Poster & Identifiable>: View {
private func select(item: BaseItemDto) {
switch item.type {
case .collectionFolder, .folder:
let viewModel = ItemLibraryViewModel(parent: item)
let viewModel = ItemLibraryViewModel(parent: item, filters: .default)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am adding this to mirror iOS.

@@ -117,6 +115,11 @@ final class ItemLibraryViewModel: PagingLibraryViewModel<BaseItemDto> {
if filters.sortBy.first == ItemSortBy.random {
parameters.excludeItemIDs = elements.compactMap(\.id)
}
} else {
// Default item types & sort order
Copy link
Member Author

@JPKribs JPKribs Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does 2 things:

  1. Right now, when filters are not present, there is no sort order. For an example, take the current 1.2 or 1.3(5) version and open select a person. It will show you all of their movies & shows but in no specific order. This is because the order is set from the FilterViewModel. This ensure, if the FilterViewModel is not present, this will default to ordering the results by name.

  2. Since I am using the includeItemTypes in the FilterViewModel, I don't want to set this value twice, This [.movie, .series, .boxSet] is the previously default value for this, so I am ensuring this is set when a FilterViewModel is not present (see people again). This is the same default found on the FilterViewModel so it will be set there as well if the view does not use these values.

The alternative to this is I can reference FilterViewModel.init().currentFilters.types so this is only being set from the FilterViewModel?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant