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": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"NoRedInk/elm-decode-pipeline": "3.0.0 <= v < 4.0.0", "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-community/maybe-extra": "4.0.0 <= v < 5.0.0",
"elm-lang/core": "5.1.1 <= v < 6.0.0", "elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0", "elm-lang/html": "2.0.0 <= v < 3.0.0",

View file

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

View file

@ -5,6 +5,7 @@ import Json.Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (decode, required) import Json.Decode.Pipeline exposing (decode, required)
import Maybe.Extra import Maybe.Extra
import Paginated import Paginated
import Task exposing (Task)
type Msg type Msg
@ -106,3 +107,10 @@ getObjects repo client =
] ]
decoder decoder
client 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))