1
0
Fork 0

Fix #145: Paginate account followers and following lists. (#149)

This commit is contained in:
Nicolas Perriault 2017-05-08 12:22:20 +02:00 committed by GitHub
parent f90f41571b
commit 75de9b8c08
6 changed files with 66 additions and 38 deletions

View File

@ -165,27 +165,27 @@ loadAccount client accountId =
Cmd.none
loadAccountFollowers : Maybe Client -> Int -> Cmd Msg
loadAccountFollowers client accountId =
loadAccountFollowers : Maybe Client -> Int -> Maybe String -> Cmd Msg
loadAccountFollowers client accountId url =
case client of
Just client ->
HttpBuilder.get (ApiUrl.followers accountId)
HttpBuilder.get (Maybe.withDefault (ApiUrl.followers accountId) url)
|> withClient client
|> withBodyDecoder (Decode.list accountDecoder)
|> send (MastodonEvent << AccountFollowers)
|> send (MastodonEvent << AccountFollowers (url /= Nothing))
Nothing ->
Cmd.none
loadAccountFollowing : Maybe Client -> Int -> Cmd Msg
loadAccountFollowing client accountId =
loadAccountFollowing : Maybe Client -> Int -> Maybe String -> Cmd Msg
loadAccountFollowing client accountId url =
case client of
Just client ->
HttpBuilder.get (ApiUrl.following accountId)
HttpBuilder.get (Maybe.withDefault (ApiUrl.following accountId) url)
|> withClient client
|> withBodyDecoder (Decode.list accountDecoder)
|> send (MastodonEvent << AccountFollowing)
|> send (MastodonEvent << AccountFollowing (url /= Nothing))
Nothing ->
Cmd.none
@ -345,6 +345,22 @@ loadNextTimeline client currentView id next =
_ ->
Cmd.none
"account-followers" ->
case currentView of
AccountFollowersView account timeline ->
loadAccountFollowers client account.id (Just next)
_ ->
Cmd.none
"account-following" ->
case currentView of
AccountFollowingView account timeline ->
loadAccountFollowing client account.id (Just next)
_ ->
Cmd.none
_ ->
Cmd.none

View File

@ -18,8 +18,8 @@ init { registration, client } location =
, localTimeline = Update.Timeline.empty "local-timeline"
, globalTimeline = Update.Timeline.empty "global-timeline"
, accountTimeline = Update.Timeline.empty "account-timeline"
, accountFollowers = []
, accountFollowing = []
, accountFollowers = Update.Timeline.empty "account-followers"
, accountFollowing = Update.Timeline.empty "account-following"
, accountRelationships = []
, accountRelationship = Nothing
, notifications = Update.Timeline.empty "notifications"

View File

@ -39,8 +39,8 @@ type alias MastodonResult a =
type MastodonMsg
= AccessToken (MastodonResult AccessTokenResult)
| AccountFollowed (MastodonResult Relationship)
| AccountFollowers (MastodonResult (List Account))
| AccountFollowing (MastodonResult (List Account))
| AccountFollowers Bool (MastodonResult (List Account))
| AccountFollowing Bool (MastodonResult (List Account))
| AccountReceived (MastodonResult Account)
| AccountRelationship (MastodonResult (List Relationship))
| AccountRelationships (MastodonResult (List Relationship))
@ -102,8 +102,8 @@ type Msg
type CurrentView
= -- Basically, what we should be displaying in the fourth column
AccountFollowersView Account (List Account)
| AccountFollowingView Account (List Account)
AccountFollowersView Account (Timeline Account)
| AccountFollowingView Account (Timeline Account)
| AccountView Account
| GlobalTimelineView
| LocalTimelineView
@ -177,8 +177,8 @@ type alias Model =
, localTimeline : Timeline Status
, globalTimeline : Timeline Status
, accountTimeline : Timeline Status
, accountFollowers : List Account
, accountFollowing : List Account
, accountFollowers : Timeline Account
, accountFollowing : Timeline Account
, accountRelationships : List Relationship
, accountRelationship : Maybe Relationship
, notifications : Timeline NotificationAggregate

View File

@ -118,8 +118,8 @@ update msg model =
LoadAccount accountId ->
{ model
| accountTimeline = Update.Timeline.empty "account-timeline"
, accountFollowers = []
, accountFollowing = []
, accountFollowers = Update.Timeline.empty "account-followers"
, accountFollowing = Update.Timeline.empty "account-following"
, accountRelationships = []
, accountRelationship = Nothing
}
@ -130,12 +130,18 @@ update msg model =
! [ Command.loadNextTimeline model.client model.currentView id next ]
ViewAccountFollowers account ->
{ model | currentView = AccountFollowersView account model.accountFollowers }
! [ Command.loadAccountFollowers model.client account.id ]
{ model
| currentView = AccountFollowersView account model.accountFollowers
, accountRelationships = []
}
! [ Command.loadAccountFollowers model.client account.id Nothing ]
ViewAccountFollowing account ->
{ model | currentView = AccountFollowingView account model.accountFollowing }
! [ Command.loadAccountFollowing model.client account.id ]
{ model
| currentView = AccountFollowingView account model.accountFollowing
, accountRelationships = []
}
! [ Command.loadAccountFollowing model.client account.id Nothing ]
ViewAccountStatuses account ->
{ model | currentView = AccountView account } ! []
@ -151,8 +157,8 @@ update msg model =
{ model
| currentView = Update.Timeline.preferred model
, accountTimeline = Update.Timeline.empty "account-timeline"
, accountFollowing = []
, accountFollowers = []
, accountFollowing = Update.Timeline.empty "account-following"
, accountFollowers = Update.Timeline.empty "account-followers"
}
! []

View File

@ -178,7 +178,10 @@ update msg model =
AccountReceived result ->
case result of
Ok { decoded } ->
{ model | currentView = AccountView decoded }
{ model
| currentView = AccountView decoded
, accountRelationships = []
}
! [ Command.loadAccountTimeline model.client decoded.id model.accountTimeline.links.next ]
Err error ->
@ -196,21 +199,19 @@ update msg model =
Err error ->
{ model | errors = addErrorNotification (errorText error) model } ! []
AccountFollowers result ->
AccountFollowers append result ->
case result of
Ok { decoded } ->
-- TODO: store next link
{ model | accountFollowers = decoded }
Ok { decoded, links } ->
{ model | accountFollowers = Update.Timeline.update append decoded links model.accountFollowers }
! [ Command.loadRelationships model.client <| List.map .id decoded ]
Err error ->
{ model | errors = addErrorNotification (errorText error) model } ! []
AccountFollowing result ->
AccountFollowing append result ->
case result of
Ok { decoded } ->
-- TODO: store next link
{ model | accountFollowing = decoded }
Ok { decoded, links } ->
{ model | accountFollowing = Update.Timeline.update append decoded links model.accountFollowing }
! [ Command.loadRelationships model.client <| List.map .id decoded ]
Err error ->
@ -232,8 +233,10 @@ update msg model =
AccountRelationships result ->
case result of
Ok { decoded } ->
-- TODO: store next link
{ model | accountRelationships = decoded } ! []
{ model
| accountRelationships = List.concat [ model.accountRelationships, decoded ]
}
! []
Err error ->
{ model | errors = addErrorNotification (errorText error) model } ! []

View File

@ -100,12 +100,12 @@ followView currentUser relationship account =
accountFollowView :
CurrentUser
-> List Account
-> Timeline Account
-> List Relationship
-> CurrentUserRelation
-> Account
-> Html Msg
accountFollowView currentUser accounts relationships relationship account =
accountFollowView currentUser timeline relationships relationship account =
let
keyedEntry account =
( toString account.id
@ -116,10 +116,13 @@ accountFollowView currentUser accounts relationships relationship account =
account
]
)
entries =
List.map keyedEntry timeline.entries
in
accountView currentUser account relationship <|
Keyed.ul [ class "list-group" ] <|
List.map keyedEntry accounts
(entries ++ [ ( "load-more", Common.loadMoreBtn timeline ) ])
accountTimelineView : CurrentUser -> Timeline Status -> CurrentUserRelation -> Account -> Html Msg