diff --git a/elm-package.json b/elm-package.json index d40ed40..68ec45b 100644 --- a/elm-package.json +++ b/elm-package.json @@ -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", diff --git a/src/App.elm b/src/App.elm index d54c2fe..97d4243 100644 --- a/src/App.elm +++ b/src/App.elm @@ -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,37 +50,10 @@ 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 - ( { model | objects = objects } - , cmd - ) + GotObjects objects -> + ( { model | objects = objects } + , Cmd.none + ) _ -> ( model, 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 diff --git a/src/Gitlab.elm b/src/Gitlab.elm index 491558c..6aaaa5b 100644 --- a/src/Gitlab.elm +++ b/src/Gitlab.elm @@ -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))