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

Disable sort controls when fetching data #507

Merged
merged 3 commits into from
Nov 2, 2020
Merged

Conversation

VegetarianZombie
Copy link
Contributor

At the moment, when the user taps the sorting button (popularity, most recent), the app will make a request to the server. This request can be very slow which means the end-user can keep tapping the sort button. This results with the sort state being out of sync with the actual returned results.

To solve this issue, I've locked the buttons. This means that the user won't be able to change the sort order once they tapped the button. I've changed the font of the button to signify it is no longer tappable.

IMG_0108
IMG_0107
IMG_0110
IMG_0109

@VegetarianZombie VegetarianZombie linked an issue Oct 27, 2020 that may be closed by this pull request
Copy link
Collaborator

@sammyd sammyd left a comment

Choose a reason for hiding this comment

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

Some questions about the approach before I approve this PR.

}
}
}.disabled(isSorting)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a bit disappointing that "disabled" doesn't automatically have some kind of style modification that demonstrates that it is disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - it was pretty frustrating to see that the disabled state looks exactly the same as enabled.

Text(filters.sortFilter.name)
.font(.uiLabelBold)
.foregroundColor(.textButtonText)
if isSorting {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is isSorting necessary? Could you not replicate the same functionality with

if [.loading, .loadingAdditional].contains(libraryRepository.state) {

Then it might be the case that you only need the changes in this function, and not the state var, or the change with body, or indeed the changeSort() below?

If this is the case, it might be worth adding a new property on the LibraryRepository (or ContentRepository) to proxy this "network operation in progress" concept.

I might however be overlooking things, in which case I apologise (=

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @sammyd, yes - you are correct. I didn't need to provide an isSorting property. I originally thought I needed it so I can force a UI update. I removed the property and added your code as well as some additional code for the disabled check. It works exactly as before. 👍

I didn't add a property to the repository because I'm thinking I don't think I'll need to change the repo state in such a way. I was thinking I would add it if I needed to do so in a different part of the codebase. Do you think that's a good idea or would you prefer I add it to the repository?

Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that it's necessary to add a property anywhere unless you want to. The only thing I was kinda alluding to is the repetition of the "check the state" code that appears twice. I think it's fine as it is 👍

Copy link
Collaborator

@sammyd sammyd left a comment

Choose a reason for hiding this comment

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

👍 Couple of questions, but other than that it looks good. Nice work—thank you Brian.

@@ -27,6 +27,7 @@
// THE SOFTWARE.

import SwiftUI
import Combine
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this import still necessary?

}
}
}.disabled(libraryRepository.state == .loading || libraryRepository.state == .loadingAdditional)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should probably be consistent with line 108. So either this, or switch 108 to match this || statement, whichever you feel is clearer.

Suggested change
}.disabled(libraryRepository.state == .loading || libraryRepository.state == .loadingAdditional)
}.disabled([.loading, .loadingAdditional].contains(libraryRepository.state))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good - I've updated the PR with your suggestions. Thanks!

Copy link
Contributor

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

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

LGTM if all your questions have been answered @sammyd ?

Copy link
Collaborator

@sammyd sammyd left a comment

Choose a reason for hiding this comment

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

Yep! Looks good to me—thanks @VegetarianZombie & @0xTim

@VegetarianZombie VegetarianZombie merged commit 42ebccd into development Nov 2, 2020
@VegetarianZombie VegetarianZombie deleted the sorting-fix branch November 2, 2020 17:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sort toggle unpredictable in portrait on iPad
3 participants