Implement scroll to package (#257)

This commit is contained in:
Marek Fajkus 2020-12-28 23:18:56 +01:00 committed by GitHub
parent 08943214d2
commit aa366aa31c
Failed to generate hash of commit
3 changed files with 26 additions and 3 deletions

View file

@ -174,7 +174,10 @@ viewResultItem channel show item =
-- DEBUG: ]
-- DEBUG: ]
|> List.append
(tr [ onClick (SearchMsg (Search.ShowDetails item.source.name)) ]
(tr
[ onClick (SearchMsg (Search.ShowDetails item.source.name))
, Search.elementId item.source.name
]
[ td [] [ text item.source.name ]
]
:: packageDetails

View file

@ -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))
, Search.elementId item.source.attr_name
]
[ td [] [ text <| item.source.attr_name ]
, td [] [ text item.source.pname ]
, td [] [ text item.source.pversion ]

View file

@ -8,6 +8,7 @@ module Search exposing
, channelDetailsFromId
, channels
, decodeResult
, elementId
, fromSortId
, init
, makeRequest
@ -168,6 +169,11 @@ ensureLoading model =
model
elementId : String -> Html.Attribute msg
elementId str =
Html.Attributes.id <| "result-" ++ str
-- ---------------------------
-- UPDATE
@ -185,6 +191,17 @@ type Msg a
| ChangePage Int
scrollToEntry : Maybe String -> Cmd (Msg a)
scrollToEntry val =
let
doScroll id =
Browser.Dom.getElement ("result-" ++ id)
|> Task.andThen (\{ element } -> Browser.Dom.setViewport element.x element.y)
|> Task.attempt (always NoOp)
in
Maybe.withDefault Cmd.none <| Maybe.map doScroll val
update :
Route.SearchRoute
-> Browser.Navigation.Key
@ -226,7 +243,7 @@ update toRoute navKey msg model =
QueryResponse result ->
( { model | result = result }
, Cmd.none
, scrollToEntry model.show
)
ShowDetails selected ->