Update the Paginated module

This commit is contained in:
Correl Roush 2018-01-26 16:05:56 -05:00
parent 9368410d4b
commit 894638a3fa
3 changed files with 19 additions and 45 deletions

View file

@ -9,7 +9,7 @@
"exposed-modules": [],
"dependencies": {
"NoRedInk/elm-decode-pipeline": "3.0.0 <= v < 4.0.0",
"correl/elm-paginated": "1.0.0 <= v < 2.0.0",
"correl/elm-paginated": "3.0.0 <= v < 4.0.0",
"elm-community/maybe-extra": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",

View file

@ -4,6 +4,7 @@ import Gitlab
import Html
import Paginated
import RemoteData
import Task
repo : Gitlab.Repo
@ -17,7 +18,7 @@ client =
type alias ObjectsResponse =
RemoteData.WebData (Paginated.Response Gitlab.Object)
RemoteData.WebData (List Gitlab.Object)
type alias Model =
@ -49,36 +50,9 @@ init =
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
GotObjects data ->
let
next p =
case p of
Paginated.Complete _ ->
Cmd.none
Paginated.Partial request _ ->
Paginated.httpRequest request
|> RemoteData.sendRequest
|> Cmd.map GotObjects
( objects, cmd ) =
RemoteData.update
(\b ->
case model.objects of
RemoteData.Success a ->
let
updated =
Paginated.update a b
in
( updated, next updated )
_ ->
( b, next b )
)
data
in
GotObjects objects ->
( { model | objects = objects }
, cmd
, Cmd.none
)
_ ->
@ -105,15 +79,7 @@ viewFiles data =
RemoteData.Loading ->
Html.div [] [ Html.text "Loading objects..." ]
RemoteData.Success (Paginated.Partial _ objects) ->
Html.div []
[ Html.text <|
"Loading objects... ("
++ (toString (List.length objects))
++ " )"
]
RemoteData.Success (Paginated.Complete objects) ->
RemoteData.Success objects ->
let
files =
List.filter
@ -136,6 +102,6 @@ viewFile file =
getObjects : Cmd Msg
getObjects =
Gitlab.getObjects repo client
|> Paginated.httpRequest
|> RemoteData.sendRequest
|> Cmd.map GotObjects
|> Paginated.toTask
|> RemoteData.fromTask
|> Task.perform GotObjects

View file

@ -5,6 +5,7 @@ import Json.Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (decode, required)
import Maybe.Extra
import Paginated
import Task exposing (Task)
type Msg
@ -106,3 +107,10 @@ getObjects repo client =
]
decoder
client
getFiles : Repo -> Client -> Task Http.Error (List Object)
getFiles repo client =
getObjects repo client
|> Paginated.toTask
|> Task.map (List.filter (\o -> o.objectType == Blob))