diff --git a/src/Model.elm b/src/Model.elm index 2cad6a6..3967a35 100644 --- a/src/Model.elm +++ b/src/Model.elm @@ -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 } diff --git a/src/Types.elm b/src/Types.elm index 71b6250..f51ba07 100644 --- a/src/Types.elm +++ b/src/Types.elm @@ -155,6 +155,7 @@ type alias Timeline a = { id : String , entries : List a , links : Links + , loading : Bool } diff --git a/src/View/Common.elm b/src/View/Common.elm index 7d908ff..1e8870c 100644 --- a/src/View/Common.elm +++ b/src/View/Common.elm @@ -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 ""