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

Commit

Permalink
Add foundations for the User page
Browse files Browse the repository at this point in the history
Add a new route `/users/:username` that displays a users page with their
README and their projects (via a new query param to the `/projects`
API).
  • Loading branch information
hojberg committed Jan 24, 2022
1 parent 32beb16 commit 6d04b8a
Show file tree
Hide file tree
Showing 19 changed files with 450 additions and 72 deletions.
15 changes: 12 additions & 3 deletions src/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,18 @@ namespace perspective fqn =
Endpoint [ "namespaces", FQN.toString fqn ] queryParams


projects : Endpoint
projects =
Endpoint [ "projects" ] []
projects : Maybe String -> Endpoint
projects owner =
let
queryParams =
case owner of
Just owner_ ->
[ string "owner" owner_ ]

Nothing ->
[]
in
Endpoint [ "projects" ] queryParams


getDefinition : Perspective -> List String -> Endpoint
Expand Down
7 changes: 2 additions & 5 deletions src/Definition/Readme.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ module Definition.Readme exposing (..)

import Definition.Doc as Doc exposing (Doc, DocFoldToggles, FoldId)
import Definition.Reference exposing (Reference)
import Html exposing (Html, div, header, text)
import Html exposing (Html, div)
import Html.Attributes exposing (class)
import Json.Decode as Decode
import UI.Icon as Icon


{-| Represent the Readme Doc definition of a namespace. This is typically
Expand All @@ -28,9 +27,7 @@ view :
-> Html msg
view refToMsg toggleFoldMsg docFoldToggles (Readme doc) =
div [ class "readme" ]
[ header [] [ Icon.view Icon.doc, text "README" ]
, Doc.view refToMsg toggleFoldMsg docFoldToggles doc
]
[ Doc.view refToMsg toggleFoldMsg docFoldToggles doc ]



Expand Down
7 changes: 6 additions & 1 deletion src/PerspectiveLanding.elm
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ view env model =
Success (Namespace _ _ { readme }) ->
case readme of
Just r ->
container [ Readme.view OpenReference ToggleDocFold model r ]
container
[ div [ class "perspective-landing-readme" ]
[ header [] [ Icon.view Icon.doc, text "README" ]
, Readme.view OpenReference ToggleDocFold model r
]
]

Nothing ->
viewEmptyStateNamespace fqn
Expand Down
34 changes: 30 additions & 4 deletions src/UI/Card.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,36 @@ import Html exposing (Html, div, h3, text)
import Html.Attributes exposing (class)


type CardType
= Contained
| Uncontained


type alias Card msg =
{ title : Maybe String, items : List (Html msg) }
{ type_ : CardType
, title : Maybe String
, items : List (Html msg)
}


card : List (Html msg) -> Card msg
card items =
{ title = Nothing, items = items }
{ type_ = Uncontained, title = Nothing, items = items }


titled : String -> List (Html msg) -> Card msg
titled title items =
{ title = Just title, items = items }
{ type_ = Uncontained, title = Just title, items = items }


withType : CardType -> Card msg -> Card msg
withType type_ card_ =
{ card_ | type_ = type_ }


asContained : Card msg -> Card msg
asContained card_ =
{ card_ | type_ = Contained }


withTitle : String -> Card msg -> Card msg
Expand Down Expand Up @@ -43,5 +61,13 @@ view card_ =

Nothing ->
card_.items

typeClass =
case card_.type_ of
Contained ->
"contained"

Uncontained ->
"uncontained"
in
div [ class "card" ] items
div [ class "card", class typeClass ] items
73 changes: 58 additions & 15 deletions src/UnisonShare/App.elm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import KeyboardShortcut.KeyboardEvent as KeyboardEvent exposing (KeyboardEvent)
import Namespace exposing (NamespaceDetails)
import Perspective exposing (Perspective(..))
import PerspectiveLanding
import RemoteData
import RemoteData exposing (RemoteData(..))
import UI
import UI.AppHeader as AppHeader
import UI.Banner as Banner
Expand All @@ -30,6 +30,7 @@ import UI.Sidebar as Sidebar
import UI.Tooltip as Tooltip
import UnisonShare.AppModal as AppModal
import UnisonShare.Page.Catalog as Catalog
import UnisonShare.Page.UserPage as UserPage
import UnisonShare.Route as Route exposing (Route)
import Url exposing (Url)
import Workspace
Expand All @@ -46,6 +47,7 @@ type alias Model =
, workspace : Workspace.Model
, perspectiveLanding : PerspectiveLanding.Model
, catalog : Catalog.Model
, userPage : UserPage.Model
, appModal : AppModal.Model
, keyboardShortcut : KeyboardShortcut.Model
, env : Env
Expand Down Expand Up @@ -78,7 +80,20 @@ init env route =
|> Maybe.withDefault Cmd.none

( catalog, catalogCmd ) =
Catalog.init env
case route of
Route.Catalog ->
Catalog.init env

_ ->
( NotAsked, Cmd.none )

( userPage, userPageCmd ) =
case route of
Route.User username ->
UserPage.init env username

_ ->
( NotAsked, Cmd.none )

model =
{ route = route
Expand All @@ -90,13 +105,15 @@ init env route =
, env = env
, sidebarToggled = False
, catalog = catalog
, userPage = userPage
}
in
( model
, Cmd.batch
[ Cmd.map CodebaseTreeMsg codebaseTreeCmd
, Cmd.map WorkspaceMsg workspaceCmd
, Cmd.map CatalogMsg catalogCmd
, Cmd.map UserPageMsg userPageCmd
, fetchNamespaceDetailsCmd
]
)
Expand All @@ -118,6 +135,7 @@ type Msg
-- sub msgs
| AppModalMsg AppModal.Msg
| CatalogMsg Catalog.Msg
| UserPageMsg UserPage.Msg
| WorkspaceMsg Workspace.Msg
| PerspectiveLandingMsg PerspectiveLanding.Msg
| CodebaseTreeMsg CodebaseTree.Msg
Expand Down Expand Up @@ -156,6 +174,13 @@ update msg ({ env } as model) =
in
( { model2 | catalog = catalog }, Cmd.map CatalogMsg cmd )

Route.User username ->
let
( userPage, cmd ) =
UserPage.init model.env username
in
( { model2 | userPage = userPage }, Cmd.map UserPageMsg cmd )

Route.Project params (Route.ProjectDefinition ref) ->
let
( workspace, cmd ) =
Expand Down Expand Up @@ -233,6 +258,13 @@ update msg ({ env } as model) =
in
( { model | catalog = catalog }, Cmd.map CatalogMsg cmd )

( Route.User _, UserPageMsg uMsg ) ->
let
( userPage, cmd ) =
UserPage.update env uMsg model.userPage
in
( { model | userPage = userPage }, Cmd.map UserPageMsg cmd )

( Route.Project _ _, WorkspaceMsg wMsg ) ->
let
( workspace, wCmd, outMsg ) =
Expand Down Expand Up @@ -683,28 +715,39 @@ view model =
, content = PageLayout.PageContent [ pageContent ]
}

page =
( pageId, page ) =
case model.route of
Route.Catalog ->
Html.map CatalogMsg (Catalog.view model.catalog)
( "catalog-page", Html.map CatalogMsg (Catalog.view model.catalog) )

Route.User _ ->
( "user-page", Html.map UserPageMsg (UserPage.view model.userPage) )

Route.Project _ Route.ProjectRoot ->
Html.map PerspectiveLandingMsg
(PerspectiveLanding.view
model.env
model.perspectiveLanding
)
|> withSidebar
|> PageLayout.view
let
page_ =
Html.map PerspectiveLandingMsg
(PerspectiveLanding.view
model.env
model.perspectiveLanding
)
|> withSidebar
|> PageLayout.view
in
( "project-page", page_ )

Route.Project _ (Route.ProjectDefinition _) ->
Html.map WorkspaceMsg (Workspace.view model.workspace)
|> withSidebar
|> PageLayout.view
let
page_ =
Html.map WorkspaceMsg (Workspace.view model.workspace)
|> withSidebar
|> PageLayout.view
in
( "project-page", page_ )
in
{ title = "Unison Share"
, body =
[ div [ id "app" ]
[ div [ id "app", class pageId ]
[ appHeader
, page
, Html.map AppModalMsg (AppModal.view model.env model.appModal)
Expand Down
2 changes: 1 addition & 1 deletion src/UnisonShare/Page/Catalog.elm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fetchCatalog env =
|> Api.toTask env.apiBasePath Catalog.decodeCatalogMask
|> Task.andThen
(\catalog ->
Api.projects
Api.projects Nothing
|> Api.toTask env.apiBasePath Project.decodeListings
|> Task.map (\projects -> ( catalog, projects ))
)
Expand Down
Loading

0 comments on commit 6d04b8a

Please sign in to comment.