2021-04-28 18:28:56 +03:00
|
|
|
module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
|
|
|
|
|
|
|
|
import Browser.Navigation
|
|
|
|
import Css.Global
|
|
|
|
import DataSource
|
|
|
|
import DataSource.Http
|
2022-03-25 19:03:22 +03:00
|
|
|
import Effect exposing (Effect)
|
2021-04-28 18:28:56 +03:00
|
|
|
import Html exposing (Html)
|
|
|
|
import Html.Styled
|
2022-03-09 21:33:33 +03:00
|
|
|
import Json.Decode as D
|
2021-05-19 17:59:39 +03:00
|
|
|
import Pages.Flags
|
2021-05-24 22:09:57 +03:00
|
|
|
import Pages.PageUrl exposing (PageUrl)
|
2021-05-23 21:03:54 +03:00
|
|
|
import Path exposing (Path)
|
2021-07-29 19:48:25 +03:00
|
|
|
import Route exposing (Route)
|
2021-04-28 18:28:56 +03:00
|
|
|
import SharedTemplate exposing (SharedTemplate)
|
|
|
|
import Tailwind.Utilities
|
2021-05-23 19:00:20 +03:00
|
|
|
import View exposing (View)
|
2021-04-28 18:28:56 +03:00
|
|
|
|
|
|
|
|
2021-07-29 19:48:25 +03:00
|
|
|
template : SharedTemplate Msg Model Data msg
|
2021-04-28 18:28:56 +03:00
|
|
|
template =
|
|
|
|
{ init = init
|
|
|
|
, update = update
|
|
|
|
, view = view
|
|
|
|
, data = data
|
|
|
|
, subscriptions = subscriptions
|
|
|
|
, onPageChange = Just OnPageChange
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type Msg
|
|
|
|
= OnPageChange
|
2021-05-23 21:03:54 +03:00
|
|
|
{ path : Path
|
2021-04-28 18:28:56 +03:00
|
|
|
, query : Maybe String
|
|
|
|
, fragment : Maybe String
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type alias Data =
|
|
|
|
Int
|
|
|
|
|
|
|
|
|
|
|
|
type SharedMsg
|
|
|
|
= NoOp
|
|
|
|
|
|
|
|
|
|
|
|
type alias Model =
|
|
|
|
{ showMobileMenu : Bool
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init :
|
2022-03-25 19:03:22 +03:00
|
|
|
Pages.Flags.Flags
|
2021-04-28 18:28:56 +03:00
|
|
|
->
|
|
|
|
Maybe
|
|
|
|
{ path :
|
2021-05-23 21:03:54 +03:00
|
|
|
{ path : Path
|
2021-04-28 18:28:56 +03:00
|
|
|
, query : Maybe String
|
|
|
|
, fragment : Maybe String
|
|
|
|
}
|
|
|
|
, metadata : route
|
2021-05-24 22:09:57 +03:00
|
|
|
, pageUrl : Maybe PageUrl
|
2021-04-28 18:28:56 +03:00
|
|
|
}
|
2022-03-25 19:03:22 +03:00
|
|
|
-> ( Model, Effect Msg )
|
|
|
|
init flags maybePagePath =
|
2021-04-28 18:28:56 +03:00
|
|
|
( { showMobileMenu = False }
|
2022-03-25 19:03:22 +03:00
|
|
|
, Effect.none
|
2021-04-28 18:28:56 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-03-25 19:03:22 +03:00
|
|
|
update : Msg -> Model -> ( Model, Effect Msg )
|
2021-04-28 18:28:56 +03:00
|
|
|
update msg model =
|
|
|
|
case msg of
|
|
|
|
OnPageChange _ ->
|
2022-03-25 19:03:22 +03:00
|
|
|
( { model | showMobileMenu = False }, Effect.none )
|
2021-04-28 18:28:56 +03:00
|
|
|
|
|
|
|
|
2021-05-23 21:03:54 +03:00
|
|
|
subscriptions : Path -> Model -> Sub Msg
|
2021-04-28 18:28:56 +03:00
|
|
|
subscriptions _ _ =
|
|
|
|
Sub.none
|
|
|
|
|
|
|
|
|
|
|
|
data : DataSource.DataSource Data
|
|
|
|
data =
|
2022-03-09 21:33:33 +03:00
|
|
|
--DataSource.Http.get "https://api.github.com/repos/dillonkearns/elm-pages"
|
|
|
|
-- (D.field "stargazers_count" D.int)
|
|
|
|
DataSource.succeed 123
|
2021-04-28 18:28:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
view :
|
|
|
|
Data
|
|
|
|
->
|
2021-05-23 21:03:54 +03:00
|
|
|
{ path : Path
|
2021-07-29 19:48:25 +03:00
|
|
|
, route : Maybe Route
|
2021-04-28 18:28:56 +03:00
|
|
|
}
|
|
|
|
-> Model
|
|
|
|
-> (Msg -> msg)
|
2021-05-23 19:00:20 +03:00
|
|
|
-> View msg
|
2021-04-28 18:28:56 +03:00
|
|
|
-> { body : Html msg, title : String }
|
|
|
|
view stars page model toMsg pageView =
|
|
|
|
{ body =
|
|
|
|
Html.Styled.div []
|
2021-05-07 20:51:29 +03:00
|
|
|
pageView.body
|
2021-04-28 18:28:56 +03:00
|
|
|
|> Html.Styled.toUnstyled
|
|
|
|
, title = pageView.title
|
|
|
|
}
|