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

Commit aa12a61

Browse files
committed
Use normal hrefs for the App title click
When clicking the title of the app ("Unison Share" / "Unison Local"), simply use a `Click.Href` of `"/"` to navigate to the root page of the application instead of a complicated perspective change.
1 parent 32beb16 commit aa12a61

File tree

3 files changed

+33
-72
lines changed

3 files changed

+33
-72
lines changed

src/UI/AppHeader.elm

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
module UI.AppHeader exposing (..)
22

3-
import Html exposing (Html, a, header, section, span)
3+
import Html exposing (Html, a, header, section)
44
import Html.Attributes exposing (class, id)
55
import Html.Events exposing (onClick)
66
import UI
77
import UI.Banner as Banner exposing (Banner)
88
import UI.Button as Button exposing (Button)
9+
import UI.Click as Click exposing (Click)
910
import UI.Icon as Icon
1011

1112

1213
type AppTitle msg
13-
= Clickable msg (Html msg)
14-
| Disabled (Html msg)
14+
= AppTitle (Click msg) (Html msg)
1515

1616

1717
type alias MenuToggle msg =
@@ -70,13 +70,8 @@ view appHeader_ =
7070

7171

7272
viewAppTitle : AppTitle msg -> Html msg
73-
viewAppTitle title =
74-
case title of
75-
Clickable clickMsg content ->
76-
a [ class "app-title", onClick clickMsg ] [ content ]
77-
78-
Disabled content ->
79-
span [ class "app-title" ] [ content ]
73+
viewAppTitle (AppTitle click content) =
74+
Click.view [ class "app-title" ] [ content ] click
8075

8176

8277
view_ : List (Html msg) -> Html msg

src/UnisonLocal/App.elm

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -451,36 +451,20 @@ subscriptions model =
451451
-- VIEW
452452

453453

454-
appTitle : Maybe msg -> AppHeader.AppTitle msg
455-
appTitle clickMsg =
456-
let
457-
appTitle_ =
458-
case clickMsg of
459-
Nothing ->
460-
AppHeader.Disabled
461-
462-
Just msg ->
463-
AppHeader.Clickable msg
464-
in
465-
appTitle_ (h1 [] [ text "Unison", span [ class "context unison-local" ] [ text "Local" ] ])
466-
467-
468-
viewAppHeader : Model -> AppHeader.AppHeader Msg
469-
viewAppHeader model =
470-
let
471-
changePerspectiveMsg =
472-
case model.env.perspective of
473-
Codebase codebaseHash ->
474-
ChangePerspective (Codebase codebaseHash)
454+
appTitle : Click msg -> AppHeader.AppTitle msg
455+
appTitle click =
456+
AppHeader.AppTitle click
457+
(h1 []
458+
[ text "Unison"
459+
, span [ class "context unison-local" ] [ text "Local" ]
460+
]
461+
)
475462

476-
Namespace { codebaseHash } ->
477-
ChangePerspective (Codebase codebaseHash)
478463

479-
appTitle_ =
480-
appTitle (Just changePerspectiveMsg)
481-
in
464+
appHeader : AppHeader.AppHeader Msg
465+
appHeader =
482466
{ menuToggle = Just ToggleSidebar
483-
, appTitle = appTitle_
467+
, appTitle = appTitle (Click.Href "/")
484468
, banner = Nothing
485469
, rightButton = Just (Button.button (ShowModal PublishModal) "Publish on Unison Share" |> Button.share)
486470
}
@@ -746,7 +730,7 @@ viewModal model =
746730
viewAppLoading : Html msg
747731
viewAppLoading =
748732
div [ id "app" ]
749-
[ AppHeader.view (AppHeader.appHeader (appTitle Nothing))
733+
[ AppHeader.view (AppHeader.appHeader (appTitle Click.Disabled))
750734
, PageLayout.view
751735
(PageLayout.SidebarLayout
752736
{ sidebar = []
@@ -760,7 +744,7 @@ viewAppLoading =
760744
viewAppError : Http.Error -> Html msg
761745
viewAppError error =
762746
div [ id "app" ]
763-
[ AppHeader.view (AppHeader.appHeader (appTitle Nothing))
747+
[ AppHeader.view (AppHeader.appHeader (appTitle Click.Disabled))
764748
, PageLayout.view
765749
(PageLayout.SidebarLayout
766750
{ sidebar = []
@@ -801,5 +785,5 @@ view model =
801785
}
802786
in
803787
{ title = "Unison Local"
804-
, body = [ div [ id "app" ] [ AppHeader.view (viewAppHeader model), PageLayout.view page, viewModal model ] ]
788+
, body = [ div [ id "app" ] [ AppHeader.view appHeader, PageLayout.view page, viewModal model ] ]
805789
}

src/UnisonShare/App.elm

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -462,34 +462,19 @@ subscriptions model =
462462
-- VIEW
463463

464464

465-
appTitle : Maybe msg -> AppHeader.AppTitle msg
466-
appTitle clickMsg =
467-
let
468-
appTitle_ =
469-
case clickMsg of
470-
Nothing ->
471-
AppHeader.Disabled
472-
473-
Just msg ->
474-
AppHeader.Clickable msg
475-
in
476-
appTitle_ (h1 [] [ text "Unison", span [ class "context unison-share" ] [ text "Share" ] ])
465+
appTitle : Click msg -> AppHeader.AppTitle msg
466+
appTitle click =
467+
AppHeader.AppTitle click
468+
(h1 []
469+
[ text "Unison"
470+
, span [ class "context unison-share" ] [ text "Share" ]
471+
]
472+
)
477473

478474

479-
viewAppHeader : Model -> AppHeader.AppHeader Msg
480-
viewAppHeader model =
475+
appHeader : AppHeader.AppHeader Msg
476+
appHeader =
481477
let
482-
changePerspectiveMsg =
483-
case model.env.perspective of
484-
Codebase codebaseHash ->
485-
ChangePerspective (Codebase codebaseHash)
486-
487-
Namespace { codebaseHash } ->
488-
ChangePerspective (Codebase codebaseHash)
489-
490-
appTitle_ =
491-
appTitle (Just changePerspectiveMsg)
492-
493478
banner =
494479
Just
495480
(Banner.promotion "article"
@@ -499,7 +484,7 @@ viewAppHeader model =
499484
)
500485
in
501486
{ menuToggle = Just ToggleSidebar
502-
, appTitle = appTitle_
487+
, appTitle = appTitle (Click.Href "/")
503488
, banner = banner
504489
, rightButton = Just (Button.button (ShowModal AppModal.PublishModal) "Publish on Unison Share" |> Button.share)
505490
}
@@ -643,7 +628,7 @@ viewMainSidebar model =
643628
viewAppLoading : Html msg
644629
viewAppLoading =
645630
div [ id "app" ]
646-
[ AppHeader.view (AppHeader.appHeader (appTitle Nothing))
631+
[ AppHeader.view (AppHeader.appHeader (appTitle Click.Disabled))
647632
, PageLayout.view
648633
(PageLayout.FullLayout
649634
{ content = PageLayout.PageContent [] }
@@ -654,7 +639,7 @@ viewAppLoading =
654639
viewAppError : Http.Error -> Html msg
655640
viewAppError error =
656641
div [ id "app" ]
657-
[ AppHeader.view (AppHeader.appHeader (appTitle Nothing))
642+
[ AppHeader.view (AppHeader.appHeader (appTitle Click.Disabled))
658643
, PageLayout.view
659644
(PageLayout.FullLayout
660645
{ content =
@@ -673,9 +658,6 @@ viewAppError error =
673658
view : Model -> Browser.Document Msg
674659
view model =
675660
let
676-
appHeader =
677-
AppHeader.view (viewAppHeader model)
678-
679661
withSidebar pageContent =
680662
PageLayout.SidebarLayout
681663
{ sidebar = viewMainSidebar model
@@ -705,7 +687,7 @@ view model =
705687
{ title = "Unison Share"
706688
, body =
707689
[ div [ id "app" ]
708-
[ appHeader
690+
[ AppHeader.view appHeader
709691
, page
710692
, Html.map AppModalMsg (AppModal.view model.env model.appModal)
711693
]

0 commit comments

Comments
 (0)