website/app/Shared.elm

141 lines
3.2 KiB
Elm
Raw Normal View History

2023-10-24 05:23:25 +07:00
module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
import BackendTask exposing (BackendTask)
import Effect exposing (Effect)
import FatalError exposing (FatalError)
2025-01-04 07:19:48 +07:00
import Header exposing (header)
2023-10-24 05:23:25 +07:00
import Html exposing (Html)
import Html.Styled
import Html.Styled.Events
2025-01-04 07:19:48 +07:00
import Link exposing (Link)
2023-10-24 05:23:25 +07:00
import Pages.Flags
import Pages.PageUrl exposing (PageUrl)
import Route exposing (Route)
import SharedTemplate exposing (SharedTemplate)
2025-01-04 07:19:48 +07:00
import UrlPath exposing (UrlPath)
2023-10-24 05:23:25 +07:00
import View exposing (View)
template : SharedTemplate Msg Model Data msg
template =
{ init = init
, update = update
, view = view
, data = data
, subscriptions = subscriptions
, onPageChange = Nothing
}
type Msg
= SharedMsg SharedMsg
| MenuClicked
type alias Data =
()
type SharedMsg
= NoOp
type alias Model =
{ showMenu : Bool
}
init :
Pages.Flags.Flags
->
Maybe
{ path :
{ path : UrlPath
, query : Maybe String
, fragment : Maybe String
}
, metadata : route
, pageUrl : Maybe PageUrl
}
-> ( Model, Effect Msg )
init flags maybePagePath =
( { showMenu = False }
, Effect.none
)
update : Msg -> Model -> ( Model, Effect Msg )
update msg model =
case msg of
SharedMsg globalMsg ->
( model, Effect.none )
MenuClicked ->
( { model | showMenu = not model.showMenu }, Effect.none )
subscriptions : UrlPath -> Model -> Sub Msg
subscriptions _ _ =
Sub.none
data : BackendTask FatalError Data
data =
BackendTask.succeed ()
view :
Data
->
{ path : UrlPath
, route : Maybe Route
}
-> Model
-> (Msg -> msg)
-> View msg
-> { body : List (Html msg), title : String }
view tableOfContents page model toMsg pageView =
{ body =
2025-01-04 07:19:48 +07:00
[ header
2024-06-16 02:13:12 +07:00
|> Html.Styled.toUnstyled
2025-01-04 07:19:48 +07:00
-- ((View.Header.view ToggleMobileMenu 123 page.path
-- |> Html.Styled.map toMsg
-- )
-- :: TableOfContents.view model.showMobileMenu False Nothing tableOfContents
, pageView.body
2023-10-24 05:23:25 +07:00
-- )
|> Html.Styled.div []
|> Html.Styled.toUnstyled
]
, title = pageView.title
}
2025-01-04 07:19:48 +07:00
2023-10-24 05:23:25 +07:00
-- view sharedData page model toMsg pageView =
-- { body =
-- [ Html.Styled.nav []
-- [ Html.Styled.button
-- [ Html.Styled.Events.onClick MenuClicked ]
-- [ Html.Styled.text
-- (if model.showMenu then
-- "Close Menu"
-- else
-- "Open Menu"
-- )
-- ]
-- , if model.showMenu then
-- Html.Styled.ul []
-- [ Html.Styled.li [] [ Html.Styled.text "Menu item 1" ]
-- , Html.Styled.li [] [ Html.Styled.text "Menu item 2" ]
-- ]
-- else
-- Html.Styled.text ""
-- ]
-- |> Html.Styled.map toMsg
-- , Html.Styled.main_ [] pageView.body
-- ]
-- , title = pageView.title
-- }