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
Conversation
if Search.shouldLoad searchModel then | ||
submitQuery PackagesMsg Page.Packages.makeRequest searchModel |
There was a problem hiding this comment.
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.
, case href of | ||
-- ignore links with no `href` attribute | ||
"" -> | ||
Cmd.none | ||
|
||
_ -> | ||
Browser.Navigation.load href |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" ] |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
.loader-wrapper { | ||
height: 200px; | ||
overflow: hidden; | ||
} |
There was a problem hiding this comment.
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
.sort-form, | ||
.sort-form > .sort-group { | ||
margin-bottom: 0; | ||
} | ||
.pager { | ||
& > li > a { | ||
cursor: pointer; | ||
margin: 0 2px; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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) = |
There was a problem hiding this comment.
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 | ||
"" -> |
There was a problem hiding this comment.
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"?
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 |
8e45cb3
to
327a8aa
Compare
good catch. The problem is:
These sum type page models are quite tricky to work with 😰 . We need to prevent init from being called. in situations like this. |
resolves #224
TODO:
This changes the way we handle Loading:
result : RemoteData
is now source of truth for if we should or should not trigger the searchresut = Loading
is set only when right conditions are met (eg term is not empty)Main.elm
queries data only when result state isLoading
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.