website/app/Shared.elm

140 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)
import Html exposing (Html)
import Html.Styled
import Html.Styled.Events
import Pages.Flags
import Pages.PageUrl exposing (PageUrl)
import UrlPath exposing (UrlPath)
import Route exposing (Route)
import SharedTemplate exposing (SharedTemplate)
import View exposing (View)
2024-06-16 02:13:12 +07:00
import Header exposing (header)
import Link exposing (Link)
2023-10-24 05:23:25 +07:00
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 =
[
2024-06-16 02:13:12 +07:00
header
|> Html.Styled.toUnstyled
2023-10-24 05:23:25 +07:00
-- ((View.Header.view ToggleMobileMenu 123 page.path
-- |> Html.Styled.map toMsg
-- )
-- :: TableOfContents.view model.showMobileMenu False Nothing tableOfContents
2024-06-16 02:13:12 +07:00
, pageView.body
2023-10-24 05:23:25 +07:00
-- )
|> Html.Styled.div []
|> Html.Styled.toUnstyled
]
, title = pageView.title
}
-- 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
-- }