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

Add Catalog Route and render Catalog page #288

Merged
merged 2 commits into from
Dec 13, 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 @@ -9,7 +9,7 @@
"scripts": {
"build": "webpack --mode production --config webpack.prod.js",
"clean": "rm -rf dist",
"start": "webpack serve --mode development --port 1234 --config webpack.dev.js",
"start": "echo 'Please use either `npm run start:unisonLocal` or `npm run start:unisonShare`'",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm start is no longer used.

"start:unisonLocal": "webpack serve --mode development --port 1234 --config webpack.unisonLocal.dev.js",
"start:unisonShare": "webpack serve --mode development --port 1234 --config webpack.unisonShare.dev.js",
"test": "elm-test",
Expand Down
2 changes: 1 addition & 1 deletion src/Project.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type alias Project a =


type alias ProjectListing =
Project ()
Project {}


decodeList : Decode.Decoder (List ProjectListing)
Expand Down
2 changes: 1 addition & 1 deletion src/UnisonLocal/App.elm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Namespace exposing (NamespaceDetails)
import Perspective exposing (Perspective(..))
import PerspectiveLanding
import RemoteData
import Route exposing (Route)
import UI
import UI.AppHeader as AppHeader
import UI.Button as Button
Expand All @@ -30,6 +29,7 @@ import UI.Modal as Modal
import UI.Page as Page
import UI.Sidebar as Sidebar
import UI.Tooltip as Tooltip
import UnisonLocal.Route as Route exposing (Route)
import Url exposing (Url)
import Workspace
import Workspace.WorkspaceItems as WorkspaceItems
Expand Down
2 changes: 1 addition & 1 deletion src/UnisonLocal/PreApp.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Env exposing (Flags)
import Html
import Http
import Perspective exposing (Perspective, PerspectiveParams)
import Route exposing (Route)
import UnisonLocal.App as App
import UnisonLocal.Route as Route exposing (Route)
import Url exposing (Url)


Expand Down
2 changes: 1 addition & 1 deletion src/Route.elm → src/UnisonLocal/Route.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Route exposing
module UnisonLocal.Route exposing
( Route(..)
, fromUrl
, navigate
Expand Down
67 changes: 54 additions & 13 deletions src/UnisonShare/App.elm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Namespace exposing (NamespaceDetails)
import Perspective exposing (Perspective(..))
import PerspectiveLanding
import RemoteData
import Route exposing (Route)
import UI
import UI.AppHeader as AppHeader
import UI.Banner as Banner
Expand All @@ -29,7 +28,8 @@ import UI.Page as Page
import UI.Sidebar as Sidebar
import UI.Tooltip as Tooltip
import UnisonShare.AppModal as AppModal
import UnisonShare.SidebarContent
import UnisonShare.Page.Catalog as Catalog
import UnisonShare.Route as Route exposing (Route)
import Url exposing (Url)
import Workspace
import Workspace.WorkspaceItems as WorkspaceItems
Expand All @@ -45,6 +45,7 @@ type alias Model =
, codebaseTree : CodebaseTree.Model
, workspace : Workspace.Model
, perspectiveLanding : PerspectiveLanding.Model
, catalog : Catalog.Model
, appModal : AppModal.Model
, keyboardShortcut : KeyboardShortcut.Model
, env : Env
Expand Down Expand Up @@ -75,6 +76,9 @@ init env route navKey =
|> Maybe.map (Api.perform env.apiBasePath)
|> Maybe.withDefault Cmd.none

( catalog, _ ) =
Catalog.init env

model =
{ navKey = navKey
, route = route
Expand All @@ -85,6 +89,7 @@ init env route navKey =
, keyboardShortcut = KeyboardShortcut.init env.operatingSystem
, env = env
, sidebarToggled = False
, catalog = catalog
}
in
( model
Expand All @@ -111,6 +116,7 @@ type Msg
| ToggleSidebar
-- sub msgs
| AppModalMsg AppModal.Msg
| CatalogMsg Catalog.Msg
| WorkspaceMsg Workspace.Msg
| PerspectiveLandingMsg PerspectiveLanding.Msg
| CodebaseTreeMsg CodebaseTree.Msg
Expand All @@ -135,6 +141,13 @@ update msg ({ env } as model) =
{ env | perspective = Perspective.nextFromParams env.perspective params }
in
case route of
Route.Catalog ->
let
( catalog, cmd ) =
Catalog.init model.env
in
( { model | catalog = catalog }, Cmd.map CatalogMsg cmd )

Route.Definition params ref ->
let
( workspace, cmd ) =
Expand Down Expand Up @@ -205,6 +218,13 @@ update msg ({ env } as model) =
in
( newModel, Cmd.batch [ Cmd.map AppModalMsg amCmd, cmd ] )

CatalogMsg cMsg ->
let
( catalog, cmd ) =
Catalog.update cMsg model.catalog
in
( { model | catalog = catalog }, Cmd.map CatalogMsg cmd )

WorkspaceMsg wMsg ->
let
( workspace, wCmd, outMsg ) =
Expand Down Expand Up @@ -570,7 +590,13 @@ viewMainSidebar model =

sidebarContent =
if Perspective.isCodebasePerspective perspective then
UnisonShare.SidebarContent.view changePerspectiveMsg
let
base =
FQN.fromString "unison.base"
in
Sidebar.section "Popular libraries"
[ Sidebar.item (changePerspectiveMsg base) (FQN.toString base)
]

else
UI.nothing
Expand Down Expand Up @@ -641,30 +667,45 @@ viewAppError error =
view : Model -> Browser.Document Msg
view model =
let
pageContent =
appHeader =
viewAppHeader model

withSidebar pageContent =
Page.SidebarLayout
{ header = viewAppHeader model
, sidebar = viewMainSidebar model
, sidebarToggled = model.sidebarToggled
, content = Page.PageContent [ pageContent ]
}

page =
case model.route of
Route.Catalog ->
let
( m, _ ) =
Catalog.init model.env
in
-- Html.map CatalogMsg (Catalog.view appHeader m)
Catalog.view appHeader m

Route.Perspective _ ->
Html.map PerspectiveLandingMsg
(PerspectiveLanding.view
model.env
model.perspectiveLanding
)
|> withSidebar
|> Page.view

Route.Definition _ _ ->
Html.map WorkspaceMsg (Workspace.view model.workspace)

page =
Page.SidebarLayout
{ header = viewAppHeader model
, sidebar = viewMainSidebar model
, sidebarToggled = model.sidebarToggled
, content = Page.PageContent [ pageContent ]
}
|> withSidebar
|> Page.view
in
{ title = "Unison Share"
, body =
[ div [ id "app" ]
[ Page.view page
[ page
, Html.map AppModalMsg (AppModal.view model.env model.appModal)
]
]
Expand Down
31 changes: 12 additions & 19 deletions src/UnisonShare/Page/Catalog.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Http
import Project exposing (ProjectListing)
import RemoteData exposing (RemoteData(..), WebData)
import UI
import UI.AppHeader exposing (AppHeader)
import UI.Page as Page exposing (Page)



Expand Down Expand Up @@ -88,22 +90,13 @@ projectsToCatalog _ =
-- 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
view : AppHeader msg -> Model -> Html msg
view appHeader _ =
let
page =
Page.FullLayout
{ header = appHeader
, content = Page.PageContent [ div [] [ text "Catalog" ] ]
}
in
Page.view page
9 changes: 7 additions & 2 deletions src/UnisonShare/PreApp.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Env exposing (Flags)
import Html
import Http
import Perspective exposing (Perspective, PerspectiveParams)
import Route exposing (Route)
import UnisonShare.App as App
import UnisonShare.Route as Route exposing (Route)
import Url exposing (Url)


Expand All @@ -32,11 +32,16 @@ init flags url navKey =
route =
Route.fromUrl flags.basePath url

perspectiveParams =
route
|> Route.perspectiveParams
|> Maybe.withDefault (Perspective.ByCodebase Perspective.Relative)

preEnv =
{ flags = flags
, route = route
, navKey = navKey
, perspectiveParams = Route.perspectiveParams route
, perspectiveParams = perspectiveParams
}

perspectiveToAppInit perspective =
Expand Down
Loading