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
|
|
|
|
import Html exposing (Html)
|
|
|
|
import Html.Styled
|
|
|
|
import OptimizedDecoder 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-04-28 18:28:56 +03:00
|
|
|
import Secrets
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
template : SharedTemplate Msg Model Data SharedMsg msg
|
|
|
|
template =
|
|
|
|
{ init = init
|
|
|
|
, update = update
|
|
|
|
, view = view
|
|
|
|
, data = data
|
|
|
|
, subscriptions = subscriptions
|
|
|
|
, onPageChange = Just OnPageChange
|
|
|
|
, sharedMsg = SharedMsg
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
| SharedMsg SharedMsg
|
|
|
|
|
|
|
|
|
|
|
|
type alias Data =
|
|
|
|
Int
|
|
|
|
|
|
|
|
|
|
|
|
type SharedMsg
|
|
|
|
= NoOp
|
|
|
|
|
|
|
|
|
|
|
|
type alias Model =
|
|
|
|
{ showMobileMenu : Bool
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init :
|
|
|
|
Maybe Browser.Navigation.Key
|
2021-05-19 17:59:39 +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
|
|
|
}
|
|
|
|
-> ( Model, Cmd Msg )
|
2021-05-19 17:59:39 +03:00
|
|
|
init _ flags maybePagePath =
|
2021-04-28 18:28:56 +03:00
|
|
|
( { showMobileMenu = False }
|
|
|
|
, Cmd.none
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
|
|
update msg model =
|
|
|
|
case msg of
|
|
|
|
OnPageChange _ ->
|
|
|
|
( { model | showMobileMenu = False }, Cmd.none )
|
|
|
|
|
|
|
|
SharedMsg globalMsg ->
|
|
|
|
( model, Cmd.none )
|
|
|
|
|
|
|
|
|
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 =
|
|
|
|
DataSource.Http.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages")
|
|
|
|
(D.field "stargazers_count" D.int)
|
|
|
|
|
|
|
|
|
|
|
|
view :
|
|
|
|
Data
|
|
|
|
->
|
2021-05-23 21:03:54 +03:00
|
|
|
{ path : Path
|
2021-04-28 18:28:56 +03:00
|
|
|
, frontmatter : route
|
|
|
|
}
|
|
|
|
-> 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
|
|
|
|
}
|