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

Commit 0eb0d7e

Browse files
committed
UnisonShare: Add foundations of Catalog page
Add a new page module for the Catalog and add placeholder model, update, and view functionality. This includes a very early iteration of a Project type.
1 parent 8440516 commit 0eb0d7e

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

src/Api.elm

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Api exposing
88
, list
99
, namespace
1010
, perform
11+
, projects
1112
, toRequest
1213
, toUrl
1314
)
@@ -53,6 +54,11 @@ namespace perspective fqn =
5354
Endpoint [ "namespaces", FQN.toString fqn ] queryParams
5455

5556

57+
projects : Endpoint
58+
projects =
59+
Endpoint [ "projects" ] []
60+
61+
5662
getDefinition : Perspective -> List String -> Endpoint
5763
getDefinition perspective fqnsOrHashes =
5864
let

src/Project.elm

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module Project exposing (..)
2+
3+
import FullyQualifiedName exposing (FQN)
4+
import Hash exposing (Hash)
5+
import Json.Decode as Decode
6+
7+
8+
type Owner
9+
= Owner String
10+
11+
12+
type alias Project a =
13+
{ a | owner : Owner, name : FQN, hash : Hash }
14+
15+
16+
type alias ProjectListing =
17+
Project ()
18+
19+
20+
decodeList : Decode.Decoder (List ProjectListing)
21+
decodeList =
22+
Decode.succeed []

src/UnisonShare/Page/Catalog.elm

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
module UnisonShare.Page.Catalog exposing (..)
2+
3+
import Api
4+
import Dict exposing (Dict)
5+
import Env exposing (Env)
6+
import Html exposing (Html, div, text)
7+
import Html.Attributes exposing (class)
8+
import Http
9+
import Project exposing (ProjectListing)
10+
import RemoteData exposing (RemoteData(..), WebData)
11+
import UI
12+
13+
14+
15+
-- MODEL
16+
17+
18+
type Category
19+
= Category String
20+
21+
22+
type Catalog
23+
= Catalog (Dict Category ProjectListing)
24+
25+
26+
type alias LoadedModel =
27+
{ query : String
28+
, catalog : Catalog
29+
}
30+
31+
32+
type alias Model =
33+
WebData LoadedModel
34+
35+
36+
init : Env -> ( Model, Cmd Msg )
37+
init env =
38+
let
39+
fetchCmd =
40+
Api.projects
41+
|> Api.toRequest Project.decodeList FetchProjectsFinished
42+
|> Api.perform env.apiBasePath
43+
in
44+
( Loading, fetchCmd )
45+
46+
47+
48+
-- UPDATE
49+
50+
51+
type Msg
52+
= UpdateQuery String
53+
| ClearQuery
54+
| FetchProjectsFinished (Result Http.Error (List ProjectListing))
55+
56+
57+
update : Msg -> Model -> ( Model, Cmd Msg )
58+
update msg model =
59+
case ( msg, model ) of
60+
( FetchProjectsFinished projectsResult, _ ) ->
61+
case projectsResult of
62+
Err e ->
63+
( Failure e, Cmd.none )
64+
65+
Ok projects ->
66+
let
67+
catalog =
68+
projectsToCatalog projects
69+
in
70+
( Success { query = "", catalog = catalog }, Cmd.none )
71+
72+
( UpdateQuery query, Success m ) ->
73+
( Success { m | query = query }, Cmd.none )
74+
75+
( ClearQuery, Success m ) ->
76+
( Success { m | query = "" }, Cmd.none )
77+
78+
_ ->
79+
( model, Cmd.none )
80+
81+
82+
projectsToCatalog : List ProjectListing -> Catalog
83+
projectsToCatalog _ =
84+
Catalog Dict.empty
85+
86+
87+
88+
-- VIEW
89+
90+
91+
viewLoaded : LoadedModel -> Html Msg
92+
viewLoaded _ =
93+
div [] [ text "Catalog" ]
94+
95+
96+
view : Model -> Html Msg
97+
view model =
98+
case model of
99+
NotAsked ->
100+
UI.nothing
101+
102+
Loading ->
103+
UI.nothing
104+
105+
Failure _ ->
106+
div [ class "" ] [ text "Error..." ]
107+
108+
Success m ->
109+
viewLoaded m

0 commit comments

Comments
 (0)