Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Sort toggle unpredictable in portrait on iPad #464

Closed
CatieCatterwaul opened this issue Aug 17, 2020 · 4 comments · Fixed by #507
Closed

Sort toggle unpredictable in portrait on iPad #464

CatieCatterwaul opened this issue Aug 17, 2020 · 4 comments · Fixed by #507
Assignees
Labels
bug Something isn't working

Comments

@CatieCatterwaul
Copy link
Contributor

Sorting works as expected in landscape, but doesn't continue when switching to portrait

https://www.dropbox.com/s/ulga69jlwnt3h9q/iOS14%20-%20Sort%20toggle%20in%20portrait%20-%20iPad.mov?dl=0

@CatieCatterwaul CatieCatterwaul added the bug Something isn't working label Aug 17, 2020
@VegetarianZombie VegetarianZombie self-assigned this Oct 2, 2020
@VegetarianZombie
Copy link
Contributor

I spent the afternoon looking into this issue. The issue occurs in the ContentRepository class. When changing the sort order, the state property is set to loadingAdditional. In loadMore(), the state is checked. If the state is .loadingAdditional, then the method exits early. Is there a reason why this is so? Removing the check for .loadingAdditional will solve this problem. Is there a reason why it is there?

@sammyd @0xTim - any insight is appreciated!

@sammyd
Copy link
Collaborator

sammyd commented Oct 9, 2020

Hi @VegetarianZombie, apologies for the delay in getting to this. I don't think I follow what you mean, so I thought I'd go through how I think this should work:

  1. A user taps the sort button, and it calls changeSort() in LibraryView. This in turn updates the filters property on the LibraryRepository:
    https://github.com/razeware/emitron-iOS/blob/development/Emitron/Emitron/UI/Library/LibraryView.swift#L151
  2. This property has a didSet callback, which in turn sets the nonPaginationParameters:
    https://github.com/razeware/emitron-iOS/blob/development/Emitron/Emitron/Data/ContentRepositories/LibraryRepository.swift#L50
  3. This property also has a didSet callback, which, provided the repository isn't initialising, will call the reload() method:
    https://github.com/razeware/emitron-iOS/blob/development/Emitron/Emitron/Data/ContentRepositories/ContentRepository.swift#L65
  4. This re-requests the data from the API. To ensure that there aren't multiple, competing requests, we check the current state of the repository:
    https://github.com/razeware/emitron-iOS/blob/development/Emitron/Emitron/Data/ContentRepositories/ContentRepository.swift#L121
  5. At the beginning of this process, we set the repo state to loading, to ensure that we don't enter this method again
    https://github.com/razeware/emitron-iOS/blob/development/Emitron/Emitron/Data/ContentRepositories/ContentRepository.swift#L125
  6. When the results return, then we reset the state, allowing future API requests to execute:
    https://github.com/razeware/emitron-iOS/blob/development/Emitron/Emitron/Data/ContentRepositories/ContentRepository.swift#L149

So I'm not sure when changing the sort order sets the state property to loadingAdditional? Maybe there's something going on that I'm missing?

@VegetarianZombie
Copy link
Contributor

Thank you @sammyd!

I followed the code paths, setting breakpoints. It appears loadingAdditional is set when the loadMore method is called. I thought this was a bug, but it turns, the state reset (#6) is delayed by at least a few seconds. Thus, the state is still set to loadingAdditional when the sort button is pressed. If we don't press the button, and just wait a few seconds, the callback does fire and the state is reset as expected. Then sorting then works.

I'll do some more investigation on Monday but my guess is that this a slow feed issue. I'll see what I can do in the UI to handle a slow callback so we don't lose that functionality.

@sammyd
Copy link
Collaborator

sammyd commented Oct 12, 2020

Ah yes! That would explain it.

The feed is /painfully/ slow right now (I'm going to try and work out why and speed it up). We should probably be resilient to that in the app, if possible.

@VegetarianZombie VegetarianZombie linked a pull request Oct 27, 2020 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants