mirror of
https://github.com/avinal/avinal.github.io.git
synced 2026-07-04 07:40:09 +05:30
fix parsing and add scroll
Signed-off-by: Avinal Kumar <avinal.xlvii@gmail.com>
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
port module Blog exposing (..)
|
port module Blog exposing (..)
|
||||||
|
|
||||||
import Base exposing (urlPrefix)
|
import Base exposing (urlPrefix)
|
||||||
|
import Browser.Dom as Dom
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (class, href, id, style)
|
import Html.Attributes exposing (class, href, id, style)
|
||||||
import Http exposing (Error(..))
|
import Http exposing (Error(..))
|
||||||
|
import Task
|
||||||
import Url exposing (Protocol(..))
|
import Url exposing (Protocol(..))
|
||||||
import Yaml.Decode as Yaml exposing (Decoder, field, list, string)
|
import Yaml.Decode as Yaml exposing (Decoder, field, list, string)
|
||||||
|
|
||||||
@@ -46,6 +48,9 @@ initialModel =
|
|||||||
port sendString : String -> Cmd msg
|
port sendString : String -> Cmd msg
|
||||||
|
|
||||||
|
|
||||||
|
port isRenderComplete : (Bool -> msg) -> Sub msg
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html Msg
|
view : Model -> Html Msg
|
||||||
view model =
|
view model =
|
||||||
div [ class "foo-interface" ]
|
div [ class "foo-interface" ]
|
||||||
@@ -123,9 +128,17 @@ viewMetadata show =
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
scrollOnFragment : String -> Cmd Msg
|
||||||
|
scrollOnFragment fragment =
|
||||||
|
Task.attempt ScrollAttempted
|
||||||
|
(Dom.getElement fragment |> Task.andThen (\info -> Dom.setViewport 0 info.element.y))
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= GetMarkdown
|
= GetMarkdown
|
||||||
| DataReceived (Result Http.Error String)
|
| DataReceived (Result Http.Error String)
|
||||||
|
| ScrollToFragment Bool Bool
|
||||||
|
| ScrollAttempted (Result Dom.Error ())
|
||||||
| NoSuchPage
|
| NoSuchPage
|
||||||
|
|
||||||
|
|
||||||
@@ -208,9 +221,15 @@ update msg model =
|
|||||||
DataReceived (Err _) ->
|
DataReceived (Err _) ->
|
||||||
( { model | success = False }, Cmd.none )
|
( { model | success = False }, Cmd.none )
|
||||||
|
|
||||||
|
ScrollToFragment _ _ ->
|
||||||
|
( model, scrollOnFragment model.fragment )
|
||||||
|
|
||||||
NoSuchPage ->
|
NoSuchPage ->
|
||||||
( { model | success = False }, Cmd.none )
|
( { model | success = False }, Cmd.none )
|
||||||
|
|
||||||
|
ScrollAttempted _ ->
|
||||||
|
( model, Cmd.none )
|
||||||
|
|
||||||
|
|
||||||
errorToString : Http.Error -> String
|
errorToString : Http.Error -> String
|
||||||
errorToString error =
|
errorToString error =
|
||||||
@@ -237,6 +256,18 @@ errorToString error =
|
|||||||
errorMessage
|
errorMessage
|
||||||
|
|
||||||
|
|
||||||
|
subscriptions : Model -> Sub Msg
|
||||||
|
subscriptions model =
|
||||||
|
isRenderComplete
|
||||||
|
(ScrollToFragment <|
|
||||||
|
if model.fragment == "" then
|
||||||
|
False
|
||||||
|
|
||||||
|
else
|
||||||
|
True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- main : Program (String, String) Model Msg
|
-- main : Program (String, String) Model Msg
|
||||||
-- main =
|
-- main =
|
||||||
|
|||||||
+12
-1
@@ -283,6 +283,17 @@ updateUrl model =
|
|||||||
|> toSplash model
|
|> toSplash model
|
||||||
|
|
||||||
|
|
||||||
|
subscriptions : Model -> Sub Msg
|
||||||
|
subscriptions model =
|
||||||
|
case model.page of
|
||||||
|
BlogPage blogModel ->
|
||||||
|
Blog.subscriptions blogModel
|
||||||
|
|> Sub.map GotBlogMsg
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
Sub.none
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- ENTRYPOINT
|
-- ENTRYPOINT
|
||||||
|
|
||||||
@@ -293,7 +304,7 @@ main =
|
|||||||
{ init = init
|
{ init = init
|
||||||
, view = view
|
, view = view
|
||||||
, update = update
|
, update = update
|
||||||
, subscriptions = \_ -> Sub.none
|
, subscriptions = subscriptions
|
||||||
, onUrlChange = ChangeUrl
|
, onUrlChange = ChangeUrl
|
||||||
, onUrlRequest = ClickedLink
|
, onUrlRequest = ClickedLink
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user