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

Commit

Permalink
Eliminate AppContext
Browse files Browse the repository at this point in the history
The apps are splitting more cleanly, removing the need for the AppContext
type.
  • Loading branch information
hojberg committed Apr 6, 2022
1 parent 957c66f commit d0007fa
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 85 deletions.
4 changes: 0 additions & 4 deletions src/Env.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Env exposing (..)
import Api exposing (ApiBasePath(..))
import Browser.Navigation as Nav
import Code.Perspective exposing (Perspective)
import Env.AppContext as AppContext exposing (AppContext)


type OperatingSystem
Expand All @@ -19,7 +18,6 @@ type alias Env =
{ operatingSystem : OperatingSystem
, basePath : String
, apiBasePath : ApiBasePath
, appContext : AppContext
, navKey : Nav.Key
, perspective : Perspective
}
Expand All @@ -29,7 +27,6 @@ type alias Flags =
{ operatingSystem : String
, basePath : String
, apiBasePath : List String
, appContext : String
}


Expand All @@ -38,7 +35,6 @@ init flags navKey perspective =
{ operatingSystem = operatingSystemFromString flags.operatingSystem
, basePath = flags.basePath
, apiBasePath = ApiBasePath flags.apiBasePath
, appContext = AppContext.fromString flags.appContext
, navKey = navKey
, perspective = perspective
}
Expand Down
45 changes: 0 additions & 45 deletions src/Env/AppContext.elm

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module Code.PerspectiveLanding exposing (..)
module UnisonLocal.PerspectiveLanding exposing (..)

import Code.Definition.Doc as Doc
import Code.Definition.Readme as Readme
import Code.Definition.Reference exposing (Reference)
import Code.FullyQualifiedName as FQN exposing (FQN)
import Code.Namespace exposing (Namespace(..))
import Code.Perspective as Perspective
import Env exposing (Env)
import Env.AppContext exposing (AppContext(..))
import Code.Perspective as Perspective exposing (Perspective)
import Html exposing (Html, a, article, div, h2, header, p, section, span, strong, text)
import Html.Attributes exposing (class, href, id, rel, target)
import Lib.Util as Util
Expand Down Expand Up @@ -111,32 +109,21 @@ viewEmptyState title description cta =
]


viewEmptyStateCodebase : AppContext -> Html Msg
viewEmptyStateCodebase appContext =
let
button =
Button.iconThenLabel Find Icon.search "Find Definition"
|> Button.primaryMono
|> Button.medium
in
case appContext of
UnisonLocal ->
viewEmptyState
(span [ class "unison-local" ] [ text "Your ", span [ class "context" ] [ text "Local" ], text " Unison Codebase" ])
[ p [] [ text "Browse, search, read docs, open definitions, and explore your local codebase." ]
, p []
[ text "Check out "
, a [ class "unison-share", href "https://share.unison-lang.org", rel "noopener", target "_blank" ] [ strong [] [ text "Unison Share" ] ]
, text " for community projects."
]
]
button

UnisonShare ->
viewEmptyState
(span [ class "unison-share" ] [ text "Unison ", span [ class "context" ] [ text "Share" ] ])
[ p [] [ text "Explore to discover and share Unison libraries, documentation, types, and terms." ] ]
button
viewEmptyStateCodebase : Html Msg
viewEmptyStateCodebase =
viewEmptyState
(span [ class "unison-local" ] [ text "Your ", span [ class "context" ] [ text "Local" ], text " Unison Codebase" ])
[ p [] [ text "Browse, search, read docs, open definitions, and explore your local codebase." ]
, p []
[ text "Check out "
, a [ class "unison-share", href "https://share.unison-lang.org", rel "noopener", target "_blank" ] [ strong [] [ text "Unison Share" ] ]
, text " for community projects."
]
]
(Button.iconThenLabel Find Icon.search "Find Definition"
|> Button.primaryMono
|> Button.medium
)


viewEmptyStateNamespace : FQN -> Html Msg
Expand All @@ -154,11 +141,11 @@ viewEmptyStateNamespace fqn =
)


view : Env -> Model -> Html Msg
view env model =
case env.perspective of
view : Perspective -> Model -> Html Msg
view perspective model =
case perspective of
Perspective.Codebase _ ->
viewEmptyStateCodebase env.appContext
viewEmptyStateCodebase

Perspective.Namespace { fqn, details } ->
case details of
Expand Down
177 changes: 177 additions & 0 deletions src/UnisonShare/PerspectiveLanding.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
module UnisonShare.PerspectiveLanding exposing (..)

import Code.Definition.Doc as Doc
import Code.Definition.Readme as Readme
import Code.Definition.Reference exposing (Reference)
import Code.FullyQualifiedName as FQN exposing (FQN)
import Code.Namespace exposing (Namespace(..))
import Code.Perspective as Perspective exposing (Perspective)
import Html exposing (Html, a, article, div, h2, header, p, section, span, strong, text)
import Html.Attributes exposing (class, href, id, rel, target)
import Lib.Util as Util
import RemoteData exposing (RemoteData(..))
import UI
import UI.Button as Button exposing (Button)
import UI.Icon as Icon
import UI.Toolbar as Toolbar


type alias Model =
Doc.DocFoldToggles


init : Model
init =
Doc.emptyDocFoldToggles


type Msg
= OpenReference Reference
| ToggleDocFold Doc.FoldId
| Find


type OutMsg
= OpenDefinition Reference
| ShowFinderRequest
| None


update : Msg -> Model -> ( Model, OutMsg )
update msg model =
case msg of
OpenReference r ->
( model, OpenDefinition r )

Find ->
( model, ShowFinderRequest )

ToggleDocFold fid ->
( Doc.toggleFold model fid, None )



-- VIEW


container : List (Html msg) -> Html msg
container content =
article [ id "perspective-landing" ]
[ section
[ id "perspective-landing-content" ]
content
]


viewLoading : Html msg
viewLoading =
container
[ div
[ class "loading" ]
[ UI.loadingPlaceholderRow
, UI.loadingPlaceholderRow
]
]


viewError : FQN -> String -> Html msg
viewError fqn message =
container
[ div
[ class "perspective-landing-error" ]
[ header [] [ Icon.view Icon.warn, text ("Error loading " ++ FQN.toString fqn) ]
, p [] [ text message ]
]
]


viewEmptyState : Html msg -> List (Html msg) -> Button msg -> Html msg
viewEmptyState title description cta =
let
fauxItem =
div [ class "faux-empty-state-item" ]
[ UI.loadingPlaceholderRow
, UI.loadingPlaceholderRow
]
in
container
[ section [ class "perspective-landing-empty-state" ]
[ section
[ class "content" ]
(h2 [] [ title ]
:: description
++ [ fauxItem
, fauxItem
, section [ class "actions" ] [ Button.view cta ]
]
)
]
]


viewEmptyStateCodebase : Html Msg
viewEmptyStateCodebase =
viewEmptyState
(span [ class "unison-share" ] [ text "Unison ", span [ class "context" ] [ text "Share" ] ])
[ p [] [ text "Explore to discover and share Unison libraries, documentation, types, and terms." ] ]
(Button.iconThenLabel Find Icon.search "Find Definition"
|> Button.primaryMono
|> Button.medium
)


viewEmptyStateNamespace : FQN -> Html Msg
viewEmptyStateNamespace fqn =
let
fqn_ =
FQN.toString fqn
in
viewEmptyState
(FQN.view fqn)
[ p [] [ text "Browse, search, read docs, open definitions, and explore" ] ]
(Button.iconThenLabel Find Icon.search ("Find Definitions in " ++ fqn_)
|> Button.primaryMono
|> Button.medium
)


view : Perspective -> Model -> Html Msg
view perspective model =
case perspective of
Perspective.Codebase _ ->
viewEmptyStateCodebase

Perspective.Namespace { fqn, details } ->
case details of
NotAsked ->
viewLoading

Loading ->
viewLoading

Success (Namespace _ _ { readme }) ->
let
content =
case readme of
Just r ->
container
[ div [ class "perspective-landing-readme" ]
[ header [ class "title" ] [ Icon.view Icon.doc, text "README" ]
, Readme.view OpenReference ToggleDocFold model r
]
]

Nothing ->
viewEmptyStateNamespace fqn
in
div []
[ Button.iconThenLabel Find Icon.search "Find Definition"
|> Button.small
|> Button.view
|> Toolbar.toolbar
|> Toolbar.view
, content
]

Failure error ->
viewError fqn (Util.httpErrorToString error)
1 change: 0 additions & 1 deletion src/unisonLocal.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const flags = {
operatingSystem: detectOs(window.navigator),
basePath,
apiBasePath,
appContext: "UnisonLocal",
};

preventDefaultGlobalKeyboardEvents();
Expand Down
1 change: 0 additions & 1 deletion src/unisonShare.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const flags = {
operatingSystem: detectOs(window.navigator),
basePath,
apiBasePath,
appContext: "UnisonShare",
};

preventDefaultGlobalKeyboardEvents();
Expand Down

0 comments on commit d0007fa

Please sign in to comment.