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

Commit 3de3c53

Browse files
authored
Merge pull request #287 from unisonweb/add-ui-page
Add UI.Page
2 parents 8c53c08 + dd0a7b0 commit 3de3c53

File tree

5 files changed

+259
-168
lines changed

5 files changed

+259
-168
lines changed

src/UI/Page.elm

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
module UI.Page exposing (..)
2+
3+
import Html exposing (Html, div, header, section)
4+
import Html.Attributes exposing (class, classList)
5+
import UI.AppHeader as AppHeader exposing (AppHeader)
6+
import UI.Sidebar as Sidebar
7+
8+
9+
type Hero msg
10+
= Hero (Html msg)
11+
12+
13+
type PageContent msg
14+
= PageContent (List (Html msg))
15+
16+
17+
type Page msg
18+
= HeroLayout
19+
{ header : AppHeader msg
20+
, hero : Hero msg
21+
, content :
22+
PageContent msg
23+
}
24+
| SidebarLayout
25+
{ header : AppHeader msg
26+
, sidebar : List (Html msg)
27+
, sidebarToggled : Bool
28+
, content : PageContent msg
29+
}
30+
| FullLayout { header : AppHeader msg, content : PageContent msg }
31+
32+
33+
34+
-- VIEW
35+
36+
37+
viewHero : Hero msg -> Html msg
38+
viewHero (Hero content) =
39+
header [ class "page-hero" ] [ content ]
40+
41+
42+
viewContent : PageContent msg -> Html msg
43+
viewContent (PageContent content) =
44+
section [ class "page-content" ] content
45+
46+
47+
view : Page msg -> Html msg
48+
view page =
49+
case page of
50+
HeroLayout { header, hero, content } ->
51+
div [ class "page hero-layout" ]
52+
[ AppHeader.view header
53+
, viewHero hero
54+
, viewContent content
55+
]
56+
57+
SidebarLayout { header, sidebar, sidebarToggled, content } ->
58+
div
59+
[ class "page sidebar-layout"
60+
, classList [ ( "sidebar-toggled", sidebarToggled ) ]
61+
]
62+
[ AppHeader.view header
63+
, Sidebar.view sidebar
64+
, viewContent content
65+
]
66+
67+
FullLayout { header, content } ->
68+
div [ class "page full-layout" ]
69+
[ AppHeader.view header
70+
, viewContent content
71+
]

src/UnisonLocal/App.elm

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import UI.Button as Button
2727
import UI.Click as Click exposing (Click(..))
2828
import UI.Icon as Icon
2929
import UI.Modal as Modal
30+
import UI.Page as Page
3031
import UI.Sidebar as Sidebar
3132
import UI.Tooltip as Tooltip
3233
import Url exposing (Url)
@@ -471,7 +472,7 @@ appTitle clickMsg =
471472
appTitle_ (h1 [] [ text "Unison", span [ class "context unison-local" ] [ text "Local" ] ])
472473

473474

474-
viewAppHeader : Model -> Html Msg
475+
viewAppHeader : Model -> AppHeader.AppHeader Msg
475476
viewAppHeader model =
476477
let
477478
changePerspectiveMsg =
@@ -485,12 +486,11 @@ viewAppHeader model =
485486
appTitle_ =
486487
appTitle (Just changePerspectiveMsg)
487488
in
488-
AppHeader.view
489-
{ menuToggle = Just ToggleSidebar
490-
, appTitle = appTitle_
491-
, banner = Nothing
492-
, rightButton = Just (Button.button (ShowModal PublishModal) "Publish on Unison Share" |> Button.share)
493-
}
489+
{ menuToggle = Just ToggleSidebar
490+
, appTitle = appTitle_
491+
, banner = Nothing
492+
, rightButton = Just (Button.button (ShowModal PublishModal) "Publish on Unison Share" |> Button.share)
493+
}
494494

495495

496496
viewSidebarHeader : Env -> Html Msg
@@ -558,42 +558,41 @@ unisonSubmenu =
558558
|> Tooltip.view
559559

560560

561-
viewMainSidebar : Model -> Html Msg
561+
viewMainSidebar : Model -> List (Html Msg)
562562
viewMainSidebar model =
563-
Sidebar.view
564-
[ viewMainSidebarCollapseButton model
565-
, div [ class "expanded-content" ]
566-
[ viewSidebarHeader model.env
567-
, div [ class "sidebar-scroll-area" ]
568-
[ Sidebar.section
569-
"Namespaces and Definitions"
570-
[ Html.map CodebaseTreeMsg (CodebaseTree.view model.codebaseTree) ]
571-
, nav []
572-
(List.map
573-
(\( l, c ) -> Click.view [] [ text l ] c)
574-
subMenu
575-
++ [ a [ class "show-keyboard-shortcuts", onClick (ShowModal HelpModal) ]
576-
[ text "Keyboard Shortcuts"
577-
, KeyboardShortcut.view model.keyboardShortcut (KeyboardShortcut.single QuestionMark)
578-
]
579-
]
580-
)
581-
]
582-
]
583-
, div [ class "collapsed-content" ]
584-
[ unisonSubmenu
585-
, Tooltip.tooltip
586-
(a
587-
[ class "show-keyboard-shortcuts-collapsed", onClick (ShowModal HelpModal) ]
588-
[ KeyboardShortcut.view model.keyboardShortcut (KeyboardShortcut.single QuestionMark)
589-
]
563+
[ viewMainSidebarCollapseButton model
564+
, div [ class "expanded-content" ]
565+
[ viewSidebarHeader model.env
566+
, div [ class "sidebar-scroll-area" ]
567+
[ Sidebar.section
568+
"Namespaces and Definitions"
569+
[ Html.map CodebaseTreeMsg (CodebaseTree.view model.codebaseTree) ]
570+
, nav []
571+
(List.map
572+
(\( l, c ) -> Click.view [] [ text l ] c)
573+
subMenu
574+
++ [ a [ class "show-keyboard-shortcuts", onClick (ShowModal HelpModal) ]
575+
[ text "Keyboard Shortcuts"
576+
, KeyboardShortcut.view model.keyboardShortcut (KeyboardShortcut.single QuestionMark)
577+
]
578+
]
590579
)
591-
(Tooltip.Text "Keyboard Shortcuts")
592-
|> Tooltip.withPosition Tooltip.RightOf
593-
|> Tooltip.withArrow Tooltip.Middle
594-
|> Tooltip.view
595580
]
596581
]
582+
, div [ class "collapsed-content" ]
583+
[ unisonSubmenu
584+
, Tooltip.tooltip
585+
(a
586+
[ class "show-help-collapsed", onClick (ShowModal HelpModal) ]
587+
[ KeyboardShortcut.view model.keyboardShortcut (KeyboardShortcut.single QuestionMark)
588+
]
589+
)
590+
(Tooltip.Text "Keyboard Shortcuts")
591+
|> Tooltip.withPosition Tooltip.RightOf
592+
|> Tooltip.withArrow Tooltip.Middle
593+
|> Tooltip.view
594+
]
595+
]
597596

598597

599598
viewHelpModal : OperatingSystem -> KeyboardShortcut.Model -> Html Msg
@@ -748,30 +747,39 @@ viewModal model =
748747

749748
viewAppLoading : Html msg
750749
viewAppLoading =
751-
div [ id "app" ]
752-
[ AppHeader.view (AppHeader.appHeader (appTitle Nothing))
753-
, Sidebar.view []
754-
, div [ id "main-content" ] []
755-
]
750+
Page.view
751+
(Page.SidebarLayout
752+
{ header = AppHeader.appHeader (appTitle Nothing)
753+
, sidebar = []
754+
, sidebarToggled = False
755+
, content = Page.PageContent []
756+
}
757+
)
756758

757759

758760
viewAppError : Http.Error -> Html msg
759761
viewAppError error =
760-
div [ id "app" ]
761-
[ AppHeader.view (AppHeader.appHeader (appTitle Nothing))
762-
, Sidebar.view []
763-
, div [ id "main-content", class "app-error" ]
764-
[ Icon.view Icon.warn
765-
, p [ title (Api.errorToString error) ]
766-
[ text "Unison Local could not be started." ]
767-
]
768-
]
762+
Page.view
763+
(Page.SidebarLayout
764+
{ header = AppHeader.appHeader (appTitle Nothing)
765+
, sidebar = []
766+
, sidebarToggled = False
767+
, content =
768+
Page.PageContent
769+
[ div [ class "app-error" ]
770+
[ Icon.view Icon.warn
771+
, p [ title (Api.errorToString error) ]
772+
[ text "Unison Local could not be started." ]
773+
]
774+
]
775+
}
776+
)
769777

770778

771779
view : Model -> Browser.Document Msg
772780
view model =
773781
let
774-
page =
782+
pageContent =
775783
case model.route of
776784
Route.Perspective _ ->
777785
Html.map PerspectiveLandingMsg
@@ -782,14 +790,15 @@ view model =
782790

783791
Route.Definition _ _ ->
784792
Html.map WorkspaceMsg (Workspace.view model.workspace)
793+
794+
page =
795+
Page.SidebarLayout
796+
{ header = viewAppHeader model
797+
, sidebar = viewMainSidebar model
798+
, sidebarToggled = model.sidebarToggled
799+
, content = Page.PageContent [ pageContent ]
800+
}
785801
in
786802
{ title = "Unison Local"
787-
, body =
788-
[ div [ id "app", classList [ ( "sidebar-toggled", model.sidebarToggled ) ] ]
789-
[ viewAppHeader model
790-
, viewMainSidebar model
791-
, div [ id "main-content" ] [ page ]
792-
, viewModal model
793-
]
794-
]
803+
, body = [ div [ id "app" ] [ Page.view page, viewModal model ] ]
795804
}

0 commit comments

Comments
 (0)