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

Clean AppContext and rename Ucm to Unison Local #280

Merged
merged 1 commit into from
Nov 29, 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
26 changes: 11 additions & 15 deletions src/App.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Browser
import Browser.Navigation as Nav
import CodebaseTree
import Definition.Reference exposing (Reference)
import Env exposing (AppContext(..), Env, OperatingSystem(..))
import Env exposing (Env, OperatingSystem(..))
import Env.AppContext as AppContext exposing (AppContext(..))
import Finder
import Finder.SearchOptions as SearchOptions
import FullyQualifiedName as FQN exposing (FQN)
Expand Down Expand Up @@ -451,10 +452,10 @@ appTitle clickMsg appContext =

content =
case appContext of
Env.Ucm ->
h1 [] [ text "Unison", span [ class "context ucm" ] [ text "Local" ] ]
UnisonLocal ->
h1 [] [ text "Unison", span [ class "context unison-local" ] [ text "Local" ] ]

Env.UnisonShare ->
UnisonShare ->
h1 [] [ text "Unison", span [ class "context unison-share" ] [ text "Share" ] ]
in
appTitle_ content
Expand All @@ -479,7 +480,7 @@ viewAppHeader model =

banner =
case appContext of
Ucm ->
UnisonLocal ->
Nothing

UnisonShare ->
Expand Down Expand Up @@ -544,7 +545,7 @@ subMenu appContext =
, ( "Community", ExternalHref "https://unisonweb.org/community" )
, ( "Report a bug", OnClick (ShowModal ReportBugModal) )
]
++ (if Env.isUnisonLocal appContext then
++ (if AppContext.isUnisonLocal appContext then
[ ( "Unison Share", ExternalHref "https://share.unison-lang.org" ) ]

else
Expand Down Expand Up @@ -578,7 +579,7 @@ viewMainSidebar model =
Perspective.toNamespacePerspective perspective >> ChangePerspective

sidebarContent =
if Perspective.isCodebasePerspective perspective && Env.isUnisonShare appContext then
if Perspective.isCodebasePerspective perspective && AppContext.isUnisonShare appContext then
UnisonShare.SidebarContent.view changePerspectiveMsg

else
Expand Down Expand Up @@ -732,7 +733,7 @@ viewReportBugModal appContext =
, div [ class "action" ]
[ githubLinkButton "unisonweb/codebase-ui"
, text "for reports on"
, strong [] [ text (Env.appContextToString appContext) ]
, strong [] [ text (AppContext.toString appContext) ]
, span [ class "subtle" ] [ text "(this UI)" ]
]
, div [ class "action" ]
Expand Down Expand Up @@ -784,7 +785,7 @@ viewAppError : AppContext -> Http.Error -> Html msg
viewAppError appContext error =
let
context =
Env.appContextToString appContext
AppContext.toString appContext
in
div [ id "app" ]
[ AppHeader.view (AppHeader.appHeader (appTitle Nothing appContext))
Expand All @@ -801,12 +802,7 @@ view : Model -> Browser.Document Msg
view model =
let
title_ =
case model.env.appContext of
UnisonShare ->
"Unison Share"

Ucm ->
"Unison Local"
AppContext.toString model.env.appContext

page =
case model.route of
Expand Down
47 changes: 2 additions & 45 deletions src/Env.elm
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
module Env exposing (..)

import Api exposing (ApiBasePath(..))
import Env.AppContext as AppContext exposing (AppContext)
import Perspective exposing (Perspective)


type AppContext
= UnisonShare
| Ucm


type OperatingSystem
= MacOS
| Windows
Expand Down Expand Up @@ -40,50 +36,11 @@ init flags perspective =
{ operatingSystem = operatingSystemFromString flags.operatingSystem
, basePath = flags.basePath
, apiBasePath = ApiBasePath flags.apiBasePath
, appContext = appContextFromString flags.appContext
, appContext = AppContext.fromString flags.appContext
, perspective = perspective
}


appContextFromString : String -> AppContext
appContextFromString rawContext =
if rawContext == "UnisonShare" then
UnisonShare

else
Ucm


appContextToString : AppContext -> String
appContextToString appContext =
case appContext of
UnisonShare ->
"Unison Share"

Ucm ->
"Unison Local"


isUnisonShare : AppContext -> Bool
isUnisonShare appContext =
case appContext of
UnisonShare ->
True

Ucm ->
False


isUnisonLocal : AppContext -> Bool
isUnisonLocal appContext =
case appContext of
UnisonShare ->
False

Ucm ->
True


operatingSystemFromString : String -> OperatingSystem
operatingSystemFromString rawOs =
case rawOs of
Expand Down
45 changes: 45 additions & 0 deletions src/Env/AppContext.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module Env.AppContext exposing (..)


type AppContext
= UnisonShare
| UnisonLocal


fromString : String -> AppContext
fromString rawContext =
if rawContext == "UnisonShare" then
UnisonShare

else
UnisonLocal


toString : AppContext -> String
toString appContext =
case appContext of
UnisonShare ->
"Unison Share"

UnisonLocal ->
"Unison Local"


isUnisonShare : AppContext -> Bool
isUnisonShare appContext =
case appContext of
UnisonShare ->
True

UnisonLocal ->
False


isUnisonLocal : AppContext -> Bool
isUnisonLocal appContext =
case appContext of
UnisonShare ->
False

UnisonLocal ->
True
9 changes: 5 additions & 4 deletions src/PerspectiveLanding.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Definition.Doc as Doc
import Definition.Readme as Readme
import Definition.Reference exposing (Reference)
import Env exposing (Env)
import Env.AppContext exposing (AppContext(..))
import FullyQualifiedName as FQN exposing (FQN)
import Html exposing (Html, a, article, div, h2, header, p, section, span, strong, text)
import Html.Attributes exposing (class, href, id, rel, target)
Expand Down Expand Up @@ -109,7 +110,7 @@ viewEmptyState title description cta =
]


viewEmptyStateCodebase : Env.AppContext -> Html Msg
viewEmptyStateCodebase : AppContext -> Html Msg
viewEmptyStateCodebase appContext =
let
button =
Expand All @@ -118,9 +119,9 @@ viewEmptyStateCodebase appContext =
|> Button.medium
in
case appContext of
Env.Ucm ->
UnisonLocal ->
viewEmptyState
(span [ class "ucm" ] [ text "Your ", span [ class "context" ] [ text "Local" ], text " Unison Codebase" ])
(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 "
Expand All @@ -130,7 +131,7 @@ viewEmptyStateCodebase appContext =
]
button

Env.UnisonShare ->
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." ] ]
Expand Down
3 changes: 2 additions & 1 deletion src/PreApp.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import App
import Browser
import Browser.Navigation as Nav
import Env exposing (Flags)
import Env.AppContext as AppContext
import Html
import Http
import Perspective exposing (Perspective, PerspectiveParams)
Expand Down Expand Up @@ -121,7 +122,7 @@ view : Model -> Browser.Document Msg
view model =
let
appContext flags =
Env.appContextFromString flags.appContext
AppContext.fromString flags.appContext
in
case model of
Initializing preEnv ->
Expand Down
2 changes: 1 addition & 1 deletion src/Ucm.elm → src/UnisonLocal.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Ucm exposing (..)
module UnisonLocal exposing (..)

import App
import Browser
Expand Down
4 changes: 2 additions & 2 deletions src/css/composites/app-header.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
color: var(--color-app-header-context-unison-share-fg);
}

#app-header .app-title .ucm {
color: var(--color-app-header-context-ucm-fg);
#app-header .app-title .unison-local {
color: var(--color-app-header-context-unison-local-fg);
}

#app-header .right {
Expand Down
2 changes: 1 addition & 1 deletion src/css/perspective-landing.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
width: 28rem;
}

.perspective-landing-empty-state .ucm .context {
.perspective-landing-empty-state .unison-local .context {
color: var(--color-pink-2);
}

Expand Down
2 changes: 1 addition & 1 deletion src/css/themes/unison/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
--color-app-header-subtle-fg: var(--color-gray-lighten-20);
--color-app-header-subtle-fg-em: var(--color-gray-lighten-50);
--color-app-header-context-unison-share-fg: var(--color-purple-4);
--color-app-header-context-ucm-fg: var(--color-pink-3);
--color-app-header-context-unison-local-fg: var(--color-pink-3);
--color-app-header-border: var(--color-gray-base);

--color-keyboard-shortcut-key-fg: var(--color-gray-base);
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/ucm.js → src/unisonLocal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "./init";
import detectOs from "./detectOs";
import preventDefaultGlobalKeyboardEvents from "./preventDefaultGlobalKeyboardEvents";
import { Elm } from "./Ucm.elm";
import { Elm } from "./UnisonLocal.elm";

const basePath = new URL(document.baseURI).pathname;

Expand All @@ -20,10 +20,10 @@ const flags = {
operatingSystem: detectOs(window.navigator),
basePath,
apiBasePath,
appContext: "Ucm",
appContext: "UnisonLocal",
};

preventDefaultGlobalKeyboardEvents();

// The main entry point for the `ucm` target of the Codebase UI.
Elm.Ucm.init({ flags });
// The main entry point for the `UnisonLocal` target of the Codebase UI.
Elm.UnisonLocal.init({ flags });
4 changes: 2 additions & 2 deletions webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
const API_URL = process.env.API_URL || "127.0.0.1:8080";

module.exports = {
entry: "./src/ucm.js",
entry: "./src/unisonLocal.js",

module: {
rules: [
Expand Down Expand Up @@ -42,7 +42,7 @@ module.exports = {
plugins: [
new HtmlWebpackPlugin({
favicon: "./static/favicon.ico",
template: "./src/ucm.ejs",
template: "./src/unisonLocal.ejs",
inject: "body",
publicPath: "/",
base: "/",
Expand Down
16 changes: 9 additions & 7 deletions webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,35 +80,37 @@ const unisonShareCfg = {
},
};

const ucmCfg = {
const unisonLocalCfg = {
...shared,

entry: "./src/ucm.js",
entry: "./src/unisonLocal.js",

plugins: [
new HtmlWebpackPlugin({
favicon: "./static/favicon.ico",
template: "./src/ucm.ejs",
template: "./src/unisonLocal.ejs",
inject: "body",
publicPath: "/static/",
base: false, // set dynamically by grabbing the 2 first path segments in the url.
filename: path.resolve(__dirname, "dist/ucm/index.html"),
filename: path.resolve(__dirname, "dist/unisonLocal/index.html"),
}),

new FileManagerPlugin({
events: {
onEnd: {
archive: [{ source: "dist/ucm", destination: "dist/ucm.zip" }],
archive: [
{ source: "dist/unisonLocal", destination: "dist/unisonLocal.zip" },
],
},
},
}),
],

output: {
filename: "[name].[contenthash].js",
path: path.resolve(__dirname, "dist/ucm/static"),
path: path.resolve(__dirname, "dist/unisonLocal/static"),
clean: true,
},
};

module.exports = [unisonShareCfg, ucmCfg];
module.exports = [unisonShareCfg, unisonLocalCfg];