Skip to content

Commit

Permalink
Implement scroll to package
Browse files Browse the repository at this point in the history
  • Loading branch information
turboMaCk committed Dec 27, 2020
1 parent 153674a commit 757ba70
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Page/Packages.elm
Expand Up @@ -221,7 +221,10 @@ viewResultItem channel show item =
-- DEBUG: ]
-- DEBUG: ]
|> List.append
(tr [ onClick (SearchMsg (Search.ShowDetails item.source.attr_name)) ]
(tr
[ onClick (SearchMsg (Search.ShowDetails item.source.attr_name))
, Html.Attributes.id <| "result-" ++ item.source.attr_name
]
[ td [] [ text <| item.source.attr_name ]
, td [] [ text item.source.pname ]
, td [] [ text item.source.pversion ]
Expand Down
20 changes: 18 additions & 2 deletions src/Search.elm
Expand Up @@ -150,7 +150,7 @@ init args model =
|> Maybe.withDefault Relevance
}
|> ensureLoading
, Browser.Dom.focus "search-query-input" |> Task.attempt (\_ -> NoOp)
, Cmd.batch [ Browser.Dom.focus "search-query-input" |> Task.attempt (\_ -> NoOp) ]
)


Expand Down Expand Up @@ -185,6 +185,22 @@ type Msg a
| ChangePage Int


scrollToEntry : Maybe String -> Cmd (Msg a)
scrollToEntry val =
case val of
Nothing ->
Cmd.none

Just id ->
let
_ =
Debug.log "id" id
in
Browser.Dom.getElement ("result-" ++ id)
|> Task.andThen (\{ element } -> Browser.Dom.setViewport element.x element.y)
|> Task.attempt (always NoOp)


update :
Route.SearchRoute
-> Browser.Navigation.Key
Expand Down Expand Up @@ -226,7 +242,7 @@ update toRoute navKey msg model =

QueryResponse result ->
( { model | result = result }
, Cmd.none
, scrollToEntry model.show
)

ShowDetails selected ->
Expand Down

0 comments on commit 757ba70

Please sign in to comment.