Fix browser back button to restore scroll state

Removes the url parameter that was used to identify the card to scroll
to and instead use the id from the internal model.
This commit is contained in:
Eike Kettner
2020-10-18 21:32:37 +02:00
parent ead2e52253
commit 5e0eaf419e
11 changed files with 32 additions and 39 deletions

View File

@ -41,6 +41,7 @@ type alias Model =
, searchTypeForm : SearchType
, contentOnlySearch : Maybe String
, dragDropData : DD.DragDropData
, scrollToCard : Maybe String
}
@ -70,6 +71,7 @@ init flags =
, contentOnlySearch = Nothing
, dragDropData =
DD.DragDropData DD.init Nothing
, scrollToCard = Nothing
}
@ -98,7 +100,7 @@ type Msg
| KeyUpMsg (Maybe KeyCode)
| SetContentOnly String
| ScrollResult (Result Dom.Error ())
| ClearItemDetailId (Maybe String)
| ClearItemDetailId
type SearchType

View File

@ -243,18 +243,12 @@ update mId key flags settings msg model =
ScrollResult _ ->
let
cmd =
Process.sleep 800 |> Task.perform (always (ClearItemDetailId mId))
Process.sleep 800 |> Task.perform (always ClearItemDetailId)
in
withSub ( model, cmd )
ClearItemDetailId id ->
-- if user clicks quickly away (e.g. on another item), the
-- deferred command should be ignored
if mId == id then
noSub ( model, Page.set key (HomePage Nothing) )
else
noSub ( model, Cmd.none )
ClearItemDetailId ->
noSub ( { model | scrollToCard = Nothing }, Cmd.none )
@ -269,7 +263,10 @@ scrollToCard mId model =
in
case mId of
Just id ->
( model, Task.attempt ScrollResult (scroll id), Sub.none )
( { model | scrollToCard = mId }
, Task.attempt ScrollResult (scroll id)
, Sub.none
)
Nothing ->
( model, Cmd.none, Sub.none )

View File

@ -82,7 +82,7 @@ view current flags settings model =
]
[ viewSearchBar flags model
, Html.map ItemCardListMsg
(Comp.ItemCardList.view current settings model.itemListModel)
(Comp.ItemCardList.view model.scrollToCard settings model.itemListModel)
]
, div
[ classList

View File

@ -25,7 +25,7 @@ update referrer flags msg model =
AuthResp (Ok lr) ->
let
gotoRef =
Maybe.withDefault (HomePage Nothing) referrer |> Page.goto
Maybe.withDefault HomePage referrer |> Page.goto
in
if lr.success then
( { model | result = Just lr, password = "" }, Cmd.batch [ setAccount lr, gotoRef ], Just lr )

View File

@ -77,7 +77,7 @@ renderSuccessMsg public _ =
else
p []
[ text "Your files have been successfully uploaded. They are now being processed. Check the "
, a [ class "ui link", Page.href (HomePage Nothing) ]
, a [ class "ui link", Page.href HomePage ]
[ text "Items page"
]
, text " later where the files will arrive eventually. Or go to the "