Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main exposing (main)
- import Url exposing (Url)
- import Html exposing (..)
- import Html.Attributes exposing (..)
- import Html.Events exposing (..)
- import Browser exposing (..)
- import Browser.Navigation as Navigation exposing (load)
- import Url.Parser exposing (Parser, (</>), int, map, oneOf, s, string)
- main =
- Browser.application
- { init = init
- , update = update
- , subscriptions = subscriptions
- , onUrlRequest = StateUrl
- , onUrlChange = UrlChange
- , view = view -->> toUnstyled
- }
- init : Flags -> Url -> Navigation.Key -> (Model, Cmd Msg)
- init flags url key =
- Debug.log "Frist Debug Log"
- ({query_value = "no val", url = url, fragment = Nothing, query = Nothing, key = key}, Cmd.none)
- type alias Model =
- { query_value : String
- , url : Url
- , fragment : Maybe String
- , query : Maybe String
- , key : Navigation.Key
- }
- type alias Flags =
- {}
- type Msg
- = StateUrl UrlRequest
- | UrlChange Url
- | SomeAction Url
- update : Msg -> Model -> ( Model, Cmd Msg )
- update msg model =
- case msg of
- StateUrl req ->
- Debug.log "1"
- ( model, Cmd.none )
- UrlChange url ->
- Debug.log "url"
- (model, Cmd.none )
- SomeAction url ->
- (model, Cmd.none)
- subscriptions : Model -> Sub Msg
- subscriptions model =
- Sub.none
- view model =
- { title = "Some Title"
- , body = [div [][text "Hello"
- , br [][]
- , text model.query_value
- , br [][]
- , text (Maybe.withDefault "no query" model.query)
- ]
- ,div [][
- button [ onClick SomeAction ] [ text "+" ]
- ]
- ]
- }
- -- Route Parsing
- type Route
- = Topic String
- | Blog Int
- | User String
- | Comment String Int
- routeParser : Parser (Route -> a) a
- routeParser =
- oneOf
- [ map Topic (s "topic" </> string)
- , map Blog (s "blog" </> int)
- , map User (s "user" </> string)
- , map Comment (s "user" </> string </> s "comment" </> int)
- ]
Add Comment
Please, Sign In to add comment