1
0
mirror of https://github.com/avinal/avinal.github.io.git synced 2026-07-03 23:30:09 +05:30

fix parsing and add scroll

Signed-off-by: Avinal Kumar <avinal.xlvii@gmail.com>
This commit is contained in:
2022-09-14 15:36:16 +05:30
parent e6e5a939f3
commit b0bcd5794e
2 changed files with 43 additions and 1 deletions
+31
View File
@@ -1,9 +1,11 @@
port module Blog exposing (..)
import Base exposing (urlPrefix)
import Browser.Dom as Dom
import Html exposing (..)
import Html.Attributes exposing (class, href, id, style)
import Http exposing (Error(..))
import Task
import Url exposing (Protocol(..))
import Yaml.Decode as Yaml exposing (Decoder, field, list, string)
@@ -46,6 +48,9 @@ initialModel =
port sendString : String -> Cmd msg
port isRenderComplete : (Bool -> msg) -> Sub msg
view : Model -> Html Msg
view model =
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
= GetMarkdown
| DataReceived (Result Http.Error String)
| ScrollToFragment Bool Bool
| ScrollAttempted (Result Dom.Error ())
| NoSuchPage
@@ -208,9 +221,15 @@ update msg model =
DataReceived (Err _) ->
( { model | success = False }, Cmd.none )
ScrollToFragment _ _ ->
( model, scrollOnFragment model.fragment )
NoSuchPage ->
( { model | success = False }, Cmd.none )
ScrollAttempted _ ->
( model, Cmd.none )
errorToString : Http.Error -> String
errorToString error =
@@ -237,6 +256,18 @@ errorToString error =
errorMessage
subscriptions : Model -> Sub Msg
subscriptions model =
isRenderComplete
(ScrollToFragment <|
if model.fragment == "" then
False
else
True
)
-- main : Program (String, String) Model Msg
-- main =
+12 -1
View File
@@ -283,6 +283,17 @@ updateUrl model =
|> toSplash model
subscriptions : Model -> Sub Msg
subscriptions model =
case model.page of
BlogPage blogModel ->
Blog.subscriptions blogModel
|> Sub.map GotBlogMsg
_ ->
Sub.none
-- ENTRYPOINT
@@ -293,7 +304,7 @@ main =
{ init = init
, view = view
, update = update
, subscriptions = \_ -> Sub.none
, subscriptions = subscriptions
, onUrlChange = ChangeUrl
, onUrlRequest = ClickedLink
}