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

Merged
merged 8 commits into from
Feb 2, 2025

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.
Copy link
Member

@LePips LePips left a comment

Choose a reason for hiding this comment

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

Apologies as I haven't had time recently to think deeply about code, but I had other ideas about how this would be implemented. Filtering on the itemTypes should have only been on the ItemFilterCollection instead of the FilterViewModel, as the FilterViewModel largely serves as an observable source of information for the selected and total collection of filters. I understand they were used for the query filter call, but there was no mechanism to reload these if the filtered item types changes and I'm not worried about filtering those based on the selected item types.

This work is good to clean up the ItemTypeLibraryViewModel. I am deferring filtering on BaseItemKind due to some issues I observed during testing.

@LePips LePips merged commit 3ee2abe into jellyfin:main Feb 2, 2025
4 checks passed
@JPKribs JPKribs deleted the libraryItemsViewModel branch February 2, 2025 18:51
@JPKribs
Copy link
Member Author

JPKribs commented Feb 2, 2025

No worries at all! Your changes make a ton of sense. Thank you for the revisions this looks great!

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.

2 participants