2025-01-02 01:17:48 +00:00
|
|
|
module Body exposing (Msg(..), Model(..), init, update, view, handleRoute, subscriptions)
|
2024-12-30 23:04:52 +00:00
|
|
|
|
|
|
|
import Element
|
|
|
|
|
|
|
|
import Page.Landing
|
|
|
|
import Page.Products
|
|
|
|
import Page.Resources
|
2025-01-26 21:12:06 +00:00
|
|
|
import Page.About
|
|
|
|
import Page.Contact
|
|
|
|
import Page.Term
|
2025-01-01 01:50:26 +00:00
|
|
|
import Page.NotFound
|
2024-12-30 23:04:52 +00:00
|
|
|
|
|
|
|
type Msg
|
|
|
|
= MsgLanding Page.Landing.Msg
|
|
|
|
| MsgProducts Page.Products.Msg
|
|
|
|
| MsgResources Page.Resources.Msg
|
|
|
|
| MsgAbout Page.About.Msg
|
|
|
|
| MsgContact Page.Contact.Msg
|
2025-01-26 21:12:06 +00:00
|
|
|
| MsgTerm Page.Term.Msg
|
2025-01-01 01:50:26 +00:00
|
|
|
| MsgNotFound Page.NotFound.Msg
|
2024-12-30 23:04:52 +00:00
|
|
|
|
|
|
|
type Model
|
|
|
|
= ModelLanding Page.Landing.Model
|
|
|
|
| ModelProducts Page.Products.Model
|
|
|
|
| ModelResources Page.Resources.Model
|
|
|
|
| ModelAbout Page.About.Model
|
|
|
|
| ModelContact Page.Contact.Model
|
2025-01-26 21:12:06 +00:00
|
|
|
| ModelTerm Page.Term.Model
|
2025-01-01 01:50:26 +00:00
|
|
|
| ModelNotFound Page.NotFound.Model
|
2024-12-30 23:04:52 +00:00
|
|
|
|
2025-01-26 21:12:06 +00:00
|
|
|
init : () -> (Model, Cmd Msg)
|
|
|
|
init flags =
|
|
|
|
let
|
|
|
|
(landingModel, landingCmd) = Page.Landing.init ()
|
|
|
|
in
|
|
|
|
(ModelLanding landingModel, Cmd.map MsgLanding landingCmd)
|
2024-12-30 23:04:52 +00:00
|
|
|
|
2025-01-02 01:17:48 +00:00
|
|
|
subscriptions : Model -> Sub Msg
|
|
|
|
subscriptions model =
|
|
|
|
case model of
|
|
|
|
ModelLanding m -> Page.Landing.subscriptions m |> Sub.map MsgLanding
|
|
|
|
ModelProducts m -> Page.Products.subscriptions m |> Sub.map MsgProducts
|
|
|
|
ModelResources m -> Page.Resources.subscriptions m |> Sub.map MsgResources
|
|
|
|
ModelAbout m -> Page.About.subscriptions m |> Sub.map MsgAbout
|
|
|
|
ModelContact m -> Page.Contact.subscriptions m |> Sub.map MsgContact
|
2025-01-26 21:12:06 +00:00
|
|
|
ModelTerm m -> Page.Term.subscriptions m |> Sub.map MsgTerm
|
2025-01-02 01:17:48 +00:00
|
|
|
ModelNotFound m -> Page.NotFound.subscriptions m |> Sub.map MsgNotFound
|
|
|
|
|
2025-01-26 21:12:06 +00:00
|
|
|
handleRoute : String -> (Model, Cmd Msg)
|
2025-01-01 01:50:26 +00:00
|
|
|
handleRoute path =
|
2025-01-26 21:12:06 +00:00
|
|
|
case path of
|
|
|
|
"/" ->
|
|
|
|
let
|
|
|
|
(landingModel, landingCmd) = Page.Landing.init ()
|
|
|
|
in
|
|
|
|
(ModelLanding landingModel, Cmd.map MsgLanding landingCmd)
|
2025-01-01 01:50:26 +00:00
|
|
|
|
2025-01-26 21:12:06 +00:00
|
|
|
"/Products" ->
|
|
|
|
let
|
|
|
|
(productsModel, productsCmd) = Page.Products.init ()
|
|
|
|
in
|
|
|
|
(ModelProducts productsModel, Cmd.map MsgProducts productsCmd)
|
|
|
|
|
|
|
|
"/Resources" ->
|
|
|
|
let
|
|
|
|
(resourcesModel, resourcesCmd) = Page.Resources.init ()
|
|
|
|
in
|
|
|
|
(ModelResources resourcesModel, Cmd.map MsgResources resourcesCmd)
|
|
|
|
|
|
|
|
"/About" ->
|
|
|
|
let
|
|
|
|
(aboutModel, aboutCmd) = Page.About.init ()
|
|
|
|
in
|
|
|
|
(ModelAbout aboutModel, Cmd.map MsgAbout aboutCmd)
|
|
|
|
|
|
|
|
"/Contact" ->
|
|
|
|
let
|
|
|
|
(contactModel, contactCmd) = Page.Contact.init ()
|
|
|
|
in
|
|
|
|
(ModelContact contactModel, Cmd.map MsgContact contactCmd)
|
|
|
|
|
|
|
|
"/Term" ->
|
|
|
|
let
|
|
|
|
(termModel, termCmd) = Page.Term.init ()
|
|
|
|
in
|
|
|
|
(ModelTerm termModel, Cmd.map MsgTerm termCmd)
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
let
|
|
|
|
(notFoundModel, notFoundCmd) = Page.NotFound.init ()
|
|
|
|
in
|
|
|
|
(ModelNotFound notFoundModel, Cmd.map MsgNotFound notFoundCmd)
|
2024-12-30 23:04:52 +00:00
|
|
|
update : Msg -> Model -> (Model, Cmd Msg)
|
|
|
|
update bodyMsg bodyModel =
|
|
|
|
let
|
|
|
|
updatePage msg model updateFn wrapMsg toBodyModel =
|
|
|
|
let
|
|
|
|
(newModel, cmd) = updateFn msg model
|
|
|
|
in
|
|
|
|
(toBodyModel newModel, Cmd.map wrapMsg cmd)
|
|
|
|
in
|
|
|
|
case (bodyMsg, bodyModel) of
|
|
|
|
(MsgLanding msg, ModelLanding m) ->
|
|
|
|
updatePage msg m Page.Landing.update MsgLanding ModelLanding
|
|
|
|
|
|
|
|
(MsgProducts msg, ModelProducts m) ->
|
|
|
|
updatePage msg m Page.Products.update MsgProducts ModelProducts
|
|
|
|
|
|
|
|
(MsgResources msg, ModelResources m) ->
|
|
|
|
updatePage msg m Page.Resources.update MsgResources ModelResources
|
|
|
|
|
|
|
|
(MsgAbout msg, ModelAbout m) ->
|
|
|
|
updatePage msg m Page.About.update MsgAbout ModelAbout
|
|
|
|
|
|
|
|
(MsgContact msg, ModelContact m) ->
|
|
|
|
updatePage msg m Page.Contact.update MsgContact ModelContact
|
|
|
|
|
2025-01-26 21:12:06 +00:00
|
|
|
(MsgTerm msg, ModelTerm m) ->
|
|
|
|
updatePage msg m Page.Term.update MsgTerm ModelTerm
|
|
|
|
|
2024-12-30 23:04:52 +00:00
|
|
|
_ ->
|
|
|
|
(bodyModel, Cmd.none)
|
|
|
|
|
|
|
|
view : Model -> Element.Element Msg
|
|
|
|
view model =
|
|
|
|
let
|
|
|
|
content = case model of
|
2025-01-02 01:17:48 +00:00
|
|
|
ModelLanding m -> Page.Landing.view m |> Element.map MsgLanding
|
|
|
|
ModelProducts m -> Page.Products.view m |> Element.map MsgProducts
|
|
|
|
ModelResources m -> Page.Resources.view m |> Element.map MsgResources
|
|
|
|
ModelAbout m -> Page.About.view m |> Element.map MsgAbout
|
|
|
|
ModelContact m -> Page.Contact.view m |> Element.map MsgContact
|
2025-01-26 21:12:06 +00:00
|
|
|
ModelTerm m -> Page.Term.view m |> Element.map MsgTerm
|
2025-01-02 01:17:48 +00:00
|
|
|
ModelNotFound m -> Page.NotFound.view m |> Element.map MsgNotFound
|
2024-12-30 23:04:52 +00:00
|
|
|
in
|
|
|
|
Element.el [Element.centerY ,Element.centerX] content
|