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

Refactor the loading and request management #230

Merged
merged 6 commits into from Nov 28, 2020
Merged

Conversation

turboMaCk
Copy link
Member

@turboMaCk turboMaCk commented Nov 19, 2020

resolves #224

TODO:

  • Unify the source of truth between loading and request sending
  • Update pagination for compatibility with new approach
  • Update sorting for compatibility with new approach

This changes the way we handle Loading:

  • result : RemoteData is now source of truth for if we should or should not trigger the search
  • resut = Loading is set only when right conditions are met (eg term is not empty)
  • Main.elm queries data only when result state is Loading
  • Unlike before, we now need to set Loading also for pagination. Because of this I made a small layout changes so that pagination is visible even in loading state for better UI.

This PR could be improved further - for instance we can avoid having prev button enabled during loading etc. However I didin't want to introduce way too many changes in single PR.

@turboMaCk turboMaCk self-assigned this Nov 19, 2020
@turboMaCk turboMaCk marked this pull request as draft November 19, 2020 17:41
@github-actions
Copy link
Contributor

github-actions bot commented Nov 19, 2020

Comment on lines +139 to +140
if Search.shouldLoad searchModel then
submitQuery PackagesMsg Page.Packages.makeRequest searchModel
Copy link
Member Author

Choose a reason for hiding this comment

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

single source of truth for when to perform loading.

Comment on lines +222 to +228
, case href of
-- ignore links with no `href` attribute
"" ->
Cmd.none

_ ->
Browser.Navigation.load href
Copy link
Member Author

@turboMaCk turboMaCk Nov 21, 2020

Choose a reason for hiding this comment

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

this fixes issues with links lacking Html.Attributes.href reloading app.

Comment on lines +162 to +168
ensureLoading : Model a -> Model a
ensureLoading model =
if model.query /= Nothing && model.query /= Just "" && List.member model.channel channels then
{ model | result = RemoteData.Loading }

else
model
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the only place where we explicitely define in which case we are able to load the data.

Copy link
Member

Choose a reason for hiding this comment

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

I think some condition is missing since we shouldn't load when we open details of an search result item.

Copy link
Member Author

Choose a reason for hiding this comment

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

in that case we simply don't call this function.

in
ChangePage <| ((total // model.size) - remainder) * model.size
]
[ text "Last" ]
Copy link
Member Author

Choose a reason for hiding this comment

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

most of the diff here is due to changes in indentation due to Html.map.

@@ -1,6 +1,7 @@
body {
position: relative;
min-height: 100vh;
overflow-y: scroll;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is to prevent page jumping few pixels in width. Having results might force scrollbars while loading state does not (list is very short). Setting vertical scrollbar to be always visible means no changes in document width as these two state change.

Comment on lines +104 to +107
.loader-wrapper {
height: 200px;
overflow: hidden;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

this is to prevent jumping due to changes in height as animation is running

Comment on lines +93 to +102
.sort-form,
.sort-form > .sort-group {
margin-bottom: 0;
}
.pager {
& > li > a {
cursor: pointer;
margin: 0 2px;
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry I could not resist my OCD alarm. This is just to clean up the layout just a tiny bit.

before
image

now:
image

@turboMaCk turboMaCk marked this pull request as ready for review November 21, 2020 21:06
Copy link
Member

@garbas garbas left a comment

Choose a reason for hiding this comment

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

Just did a quick test and I noticed that when you click on a result item a new request is sent to the backend. I think we messed up this once and I'm not sure I'm going to remember to check this always. We should make this somehow more reliable, but I have zero idea how.

-> ( Model, Cmd Msg )
submitQuery old ( new, cmd ) =
attemptQuery : ( Model, Cmd Msg ) -> ( Model, Cmd Msg )
attemptQuery (( model, _ ) as pair) =
Copy link
Member

Choose a reason for hiding this comment

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

Didn't know you can use as in this way. Neat!

, Browser.Navigation.load href
, case href of
-- ignore links with no `href` attribute
"" ->
Copy link
Member

Choose a reason for hiding this comment

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

Will this work properly also for links with "#someid"?

@garbas
Copy link
Member

garbas commented Nov 23, 2020

There is also another thing that it would be nice to do, while we are at it. When a result item is selected, we should scroll to it. I think this was working at some point or maybe I was just dreaming that I implemented it :) This is in a reference to this bug report #231

@turboMaCk
Copy link
Member Author

good catch.

The problem is:

  • open detail triggers urlChange effect
  • effects is handled in Main
  • in main init is called which clears the results

These sum type page models are quite tricky to work with 😰 . We need to prevent init from being called. in situations like this.

@turboMaCk turboMaCk marked this pull request as draft November 25, 2020 16:33
@turboMaCk turboMaCk marked this pull request as ready for review November 25, 2020 16:35
@garbas garbas merged commit 060daed into master Nov 28, 2020
@garbas garbas deleted the turboMaCk/fix-loading branch November 28, 2020 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clicking the search button for a already loaded result shows inifite loading animation
2 participants