Mark timelines as loading.

This commit is contained in:
Nicolas Perriault 2017-05-06 11:38:56 +02:00
parent 8344d63f47
commit bda0a82f3f
No known key found for this signature in database
GPG Key ID: DA5E4C83904F7A2A
3 changed files with 57 additions and 14 deletions

View File

@ -83,6 +83,7 @@ emptyTimeline id =
{ id = id
, entries = []
, links = Links Nothing Nothing
, loading = False
}
@ -482,6 +483,37 @@ updateViewer viewerMsg viewer =
(Just <| Viewer attachments attachment) ! []
markTimelineLoading : Bool -> String -> Model -> Model
markTimelineLoading loading id model =
let
mark timeline =
{ timeline | loading = loading }
in
case id of
"notifications" ->
{ model | notifications = mark model.notifications }
"home-timeline" ->
{ model | homeTimeline = mark model.homeTimeline }
"local-timeline" ->
{ model | localTimeline = mark model.localTimeline }
"global-timeline" ->
{ model | globalTimeline = mark model.globalTimeline }
"account-timeline" ->
case model.currentView of
AccountView account ->
{ model | accountTimeline = mark model.accountTimeline }
_ ->
model
_ ->
model
updateTimeline : Bool -> List a -> Links -> Timeline a -> Timeline a
updateTimeline append entries links timeline =
let
@ -491,7 +523,11 @@ updateTimeline append entries links timeline =
else
entries
in
{ timeline | entries = newEntries, links = links }
{ timeline
| entries = newEntries
, links = links
, loading = False
}
prependToTimeline : a -> Timeline a -> Timeline a
@ -939,7 +975,8 @@ update msg model =
! [ Command.loadAccount model.client accountId ]
TimelineLoadNext id next ->
model ! [ Command.loadNextTimeline model.client model.currentView id next ]
markTimelineLoading True id model
! [ Command.loadNextTimeline model.client model.currentView id next ]
ViewAccountFollowers account ->
{ model | currentView = AccountFollowersView account model.accountFollowers }

View File

@ -155,6 +155,7 @@ type alias Timeline a =
{ id : String
, entries : List a
, links : Links
, loading : Bool
}

View File

@ -82,17 +82,22 @@ justifiedButtonGroup cls buttons =
List.map (\b -> div [ class "btn-group" ] [ b ]) buttons
loadMoreBtn : { timeline | id : String, links : Links } -> Html Msg
loadMoreBtn timeline =
case timeline.links.next of
Just next ->
li [ class "list-group-item load-more text-center" ]
[ a
[ href next
, onClickWithPreventAndStop <| TimelineLoadNext timeline.id next
loadMoreBtn : { timeline | id : String, links : Links, loading : Bool } -> Html Msg
loadMoreBtn { id, links, loading } =
if loading then
-- TODO: proper spinner
li [ class "list-group-item load-more text-center" ]
[ text "Loading..." ]
else
case links.next of
Just next ->
li [ class "list-group-item load-more text-center" ]
[ a
[ href next
, onClickWithPreventAndStop <| TimelineLoadNext id next
]
[ text "Load more" ]
]
[ text "Load more" ]
]
Nothing ->
text ""
Nothing ->
text ""