Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

UnisonShare: Add foundations of Catalog page #286

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"clean": "rm -rf dist",
"start": "webpack serve --mode development --port 1234 --config webpack.dev.js",
"test": "elm-test",
"review": "elm-review"
"review": "elm-review --ignore-files src/UnisonShare/Page/Catalog.elm"
},
"bugs": {
"url": "https://github.com/unisonweb/codebase-ui/issues"
Expand Down
6 changes: 6 additions & 0 deletions src/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Api exposing
, list
, namespace
, perform
, projects
, toRequest
, toUrl
)
Expand Down Expand Up @@ -53,6 +54,11 @@ namespace perspective fqn =
Endpoint [ "namespaces", FQN.toString fqn ] queryParams


projects : Endpoint
projects =
Endpoint [ "projects" ] []


getDefinition : Perspective -> List String -> Endpoint
getDefinition perspective fqnsOrHashes =
let
Expand Down
22 changes: 22 additions & 0 deletions src/Project.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Project exposing (..)

import FullyQualifiedName exposing (FQN)
import Hash exposing (Hash)
import Json.Decode as Decode


type Owner
= Owner String


type alias Project a =
{ a | owner : Owner, name : FQN, hash : Hash }


type alias ProjectListing =
Project ()


decodeList : Decode.Decoder (List ProjectListing)
decodeList =
Decode.succeed []
109 changes: 109 additions & 0 deletions src/UnisonShare/Page/Catalog.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
module UnisonShare.Page.Catalog exposing (..)

import Api
import Dict exposing (Dict)
import Env exposing (Env)
import Html exposing (Html, div, text)
import Html.Attributes exposing (class)
import Http
import Project exposing (ProjectListing)
import RemoteData exposing (RemoteData(..), WebData)
import UI



-- MODEL


type Category
= Category String


type Catalog
= Catalog (Dict Category ProjectListing)


type alias LoadedModel =
{ query : String
, catalog : Catalog
}


type alias Model =
WebData LoadedModel


init : Env -> ( Model, Cmd Msg )
init env =
let
fetchCmd =
Api.projects
|> Api.toRequest Project.decodeList FetchProjectsFinished
|> Api.perform env.apiBasePath
in
( Loading, fetchCmd )



-- UPDATE


type Msg
= UpdateQuery String
| ClearQuery
| FetchProjectsFinished (Result Http.Error (List ProjectListing))


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case ( msg, model ) of
( FetchProjectsFinished projectsResult, _ ) ->
case projectsResult of
Err e ->
( Failure e, Cmd.none )

Ok projects ->
let
catalog =
projectsToCatalog projects
in
( Success { query = "", catalog = catalog }, Cmd.none )

( UpdateQuery query, Success m ) ->
( Success { m | query = query }, Cmd.none )

( ClearQuery, Success m ) ->
( Success { m | query = "" }, Cmd.none )

_ ->
( model, Cmd.none )


projectsToCatalog : List ProjectListing -> Catalog
projectsToCatalog _ =
Catalog Dict.empty



-- VIEW


viewLoaded : LoadedModel -> Html Msg
viewLoaded _ =
div [] [ text "Catalog" ]


view : Model -> Html Msg
view model =
case model of
NotAsked ->
UI.nothing

Loading ->
UI.nothing

Failure _ ->
div [ class "" ] [ text "Error..." ]

Success m ->
viewLoaded m