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

Commit 695e642

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 131ae30 commit 695e642

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
@@ -494,34 +494,19 @@ subscriptions model =
494494
-- VIEW
495495

496496

497-
appTitle : Maybe msg -> AppHeader.AppTitle msg
498-
appTitle clickMsg =
499-
let
500-
appTitle_ =
501-
case clickMsg of
502-
Nothing ->
503-
AppHeader.Disabled
504-
505-
Just msg ->
506-
AppHeader.Clickable msg
507-
in
508-
appTitle_ (h1 [] [ text "Unison", span [ class "context unison-share" ] [ text "Share" ] ])
497+
appTitle : Click msg -> AppHeader.AppTitle msg
498+
appTitle click =
499+
AppHeader.AppTitle click
500+
(h1 []
501+
[ text "Unison"
502+
, span [ class "context unison-share" ] [ text "Share" ]
503+
]
504+
)
509505

510506

511-
viewAppHeader : Model -> AppHeader.AppHeader Msg
512-
viewAppHeader model =
507+
appHeader : AppHeader.AppHeader Msg
508+
appHeader =
513509
let
514-
changePerspectiveMsg =
515-
case model.env.perspective of
516-
Codebase codebaseHash ->
517-
ChangePerspective (Codebase codebaseHash)
518-
519-
Namespace { codebaseHash } ->
520-
ChangePerspective (Codebase codebaseHash)
521-
522-
appTitle_ =
523-
appTitle (Just changePerspectiveMsg)
524-
525510
banner =
526511
Just
527512
(Banner.promotion "article"
@@ -531,7 +516,7 @@ viewAppHeader model =
531516
)
532517
in
533518
{ menuToggle = Just ToggleSidebar
534-
, appTitle = appTitle_
519+
, appTitle = appTitle (Click.Href "/")
535520
, banner = banner
536521
, rightButton = Just (Button.button (ShowModal AppModal.PublishModal) "Publish on Unison Share" |> Button.share)
537522
}
@@ -675,7 +660,7 @@ viewMainSidebar model =
675660
viewAppLoading : Html msg
676661
viewAppLoading =
677662
div [ id "app" ]
678-
[ AppHeader.view (AppHeader.appHeader (appTitle Nothing))
663+
[ AppHeader.view (AppHeader.appHeader (appTitle Click.Disabled))
679664
, PageLayout.view
680665
(PageLayout.FullLayout
681666
{ content = PageLayout.PageContent [] }
@@ -686,7 +671,7 @@ viewAppLoading =
686671
viewAppError : Http.Error -> Html msg
687672
viewAppError error =
688673
div [ id "app" ]
689-
[ AppHeader.view (AppHeader.appHeader (appTitle Nothing))
674+
[ AppHeader.view (AppHeader.appHeader (appTitle Click.Disabled))
690675
, PageLayout.view
691676
(PageLayout.FullLayout
692677
{ content =
@@ -705,9 +690,6 @@ viewAppError error =
705690
view : Model -> Browser.Document Msg
706691
view model =
707692
let
708-
appHeader =
709-
AppHeader.view (viewAppHeader model)
710-
711693
withSidebar pageContent =
712694
PageLayout.SidebarLayout
713695
{ sidebar = viewMainSidebar model
@@ -748,7 +730,7 @@ view model =
748730
{ title = "Unison Share"
749731
, body =
750732
[ div [ id "app", class pageId ]
751-
[ appHeader
733+
[ AppHeader.view appHeader
752734
, page
753735
, Html.map AppModalMsg (AppModal.view model.env model.appModal)
754736
]

0 commit comments

Comments
 (0)