|
| 1 | +module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template) |
| 2 | + |
| 3 | +import Browser.Navigation |
| 4 | +import DataSource |
| 5 | +import Html exposing (Html) |
| 6 | +import Pages.Flags |
| 7 | +import Pages.PageUrl exposing (PageUrl) |
| 8 | +import Path exposing (Path) |
| 9 | +import Route exposing (Route) |
| 10 | +import SharedTemplate exposing (SharedTemplate) |
| 11 | +import View exposing (View) |
| 12 | + |
| 13 | + |
| 14 | +template : SharedTemplate Msg Model Data msg |
| 15 | +template = |
| 16 | + { init = init |
| 17 | + , update = update |
| 18 | + , view = view |
| 19 | + , data = data |
| 20 | + , subscriptions = subscriptions |
| 21 | + , onPageChange = Just OnPageChange |
| 22 | + } |
| 23 | + |
| 24 | + |
| 25 | +type Msg |
| 26 | + = OnPageChange |
| 27 | + { path : Path |
| 28 | + , query : Maybe String |
| 29 | + , fragment : Maybe String |
| 30 | + } |
| 31 | + | SharedMsg SharedMsg |
| 32 | + |
| 33 | + |
| 34 | +type alias Data = |
| 35 | + () |
| 36 | + |
| 37 | + |
| 38 | +type SharedMsg |
| 39 | + = NoOp |
| 40 | + |
| 41 | + |
| 42 | +type alias Model = |
| 43 | + { showMobileMenu : Bool |
| 44 | + } |
| 45 | + |
| 46 | + |
| 47 | +init : |
| 48 | + Maybe Browser.Navigation.Key |
| 49 | + -> Pages.Flags.Flags |
| 50 | + -> |
| 51 | + Maybe |
| 52 | + { path : |
| 53 | + { path : Path |
| 54 | + , query : Maybe String |
| 55 | + , fragment : Maybe String |
| 56 | + } |
| 57 | + , metadata : route |
| 58 | + , pageUrl : Maybe PageUrl |
| 59 | + } |
| 60 | + -> ( Model, Cmd Msg ) |
| 61 | +init navigationKey flags maybePagePath = |
| 62 | + ( { showMobileMenu = False } |
| 63 | + , Cmd.none |
| 64 | + ) |
| 65 | + |
| 66 | + |
| 67 | +update : Msg -> Model -> ( Model, Cmd Msg ) |
| 68 | +update msg model = |
| 69 | + case msg of |
| 70 | + OnPageChange _ -> |
| 71 | + ( { model | showMobileMenu = False }, Cmd.none ) |
| 72 | + |
| 73 | + SharedMsg globalMsg -> |
| 74 | + ( model, Cmd.none ) |
| 75 | + |
| 76 | + |
| 77 | +subscriptions : Path -> Model -> Sub Msg |
| 78 | +subscriptions _ _ = |
| 79 | + Sub.none |
| 80 | + |
| 81 | + |
| 82 | +data : DataSource.DataSource Data |
| 83 | +data = |
| 84 | + DataSource.succeed () |
| 85 | + |
| 86 | + |
| 87 | +view : |
| 88 | + Data |
| 89 | + -> |
| 90 | + { path : Path |
| 91 | + , route : Maybe Route |
| 92 | + } |
| 93 | + -> Model |
| 94 | + -> (Msg -> msg) |
| 95 | + -> View msg |
| 96 | + -> { body : Html msg, title : String } |
| 97 | +view sharedData page model toMsg pageView = |
| 98 | + { body = Html.div [] pageView.body |
| 99 | + , title = pageView.title |
| 100 | + } |
0 commit comments