mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-03-25 16:45:05 +00:00
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:
parent
ead2e52253
commit
5e0eaf419e
@ -160,7 +160,7 @@ checkPage flags page =
|
||||
defaultPage : Flags -> Page
|
||||
defaultPage flags =
|
||||
if isSignedIn flags then
|
||||
HomePage Nothing
|
||||
HomePage
|
||||
|
||||
else
|
||||
LoginPage Nothing
|
||||
|
@ -31,6 +31,7 @@ import Page.UserSettings.Data
|
||||
import Page.UserSettings.Update
|
||||
import Ports
|
||||
import Url
|
||||
import Util.Maybe
|
||||
import Util.Update
|
||||
|
||||
|
||||
@ -312,8 +313,8 @@ updateHome lmsg model =
|
||||
let
|
||||
mid =
|
||||
case model.page of
|
||||
HomePage x ->
|
||||
x
|
||||
HomePage ->
|
||||
Util.Maybe.fromString model.itemDetailModel.detail.item.id
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
@ -348,7 +349,7 @@ initPage model_ page =
|
||||
{ model_ | page = page }
|
||||
in
|
||||
case page of
|
||||
HomePage _ ->
|
||||
HomePage ->
|
||||
Util.Update.andThen2
|
||||
[ updateHome Page.Home.Data.Init
|
||||
, updateQueue Page.Queue.Data.StopRefresh
|
||||
|
@ -16,6 +16,7 @@ import Page.Queue.View
|
||||
import Page.Register.View
|
||||
import Page.Upload.View
|
||||
import Page.UserSettings.View
|
||||
import Util.Maybe
|
||||
|
||||
|
||||
view : Model -> Html Msg
|
||||
@ -65,7 +66,7 @@ defaultLayout model =
|
||||
[ div [ class "ui fluid container" ]
|
||||
[ a
|
||||
[ class "header item narrow-item"
|
||||
, Page.href (HomePage Nothing)
|
||||
, Page.href HomePage
|
||||
]
|
||||
[ img
|
||||
[ class "image"
|
||||
@ -84,7 +85,7 @@ defaultLayout model =
|
||||
, id "main-content"
|
||||
]
|
||||
[ case model.page of
|
||||
HomePage _ ->
|
||||
HomePage ->
|
||||
viewHome model
|
||||
|
||||
LoginPage _ ->
|
||||
@ -180,8 +181,8 @@ viewHome model =
|
||||
let
|
||||
mid =
|
||||
case model.page of
|
||||
HomePage x ->
|
||||
x
|
||||
HomePage ->
|
||||
Util.Maybe.fromString model.itemDetailModel.detail.item.id
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
@ -218,7 +219,7 @@ loginInfo model =
|
||||
]
|
||||
]
|
||||
[ menuEntry model
|
||||
(HomePage Nothing)
|
||||
HomePage
|
||||
[ img
|
||||
[ class "image icon"
|
||||
, src (model.flags.config.docspellAssetPath ++ "/img/logo-mc-96.png")
|
||||
|
@ -632,7 +632,7 @@ update key flags inav settings msg model =
|
||||
noSub ( model, Page.set key (ItemDetailPage id) )
|
||||
|
||||
Nothing ->
|
||||
noSub ( model, Page.set key (HomePage Nothing) )
|
||||
noSub ( model, Page.set key HomePage )
|
||||
|
||||
else
|
||||
noSub ( model, Cmd.none )
|
||||
|
@ -110,7 +110,7 @@ renderDetailMenu settings inav model =
|
||||
)
|
||||
]
|
||||
]
|
||||
[ a [ class "item", Page.href (HomePage (Just model.item.id)) ]
|
||||
[ a [ class "item", Page.href HomePage ]
|
||||
[ i [ class "arrow left icon" ] []
|
||||
]
|
||||
, a
|
||||
|
@ -24,7 +24,7 @@ import Util.Maybe
|
||||
|
||||
|
||||
type Page
|
||||
= HomePage (Maybe String)
|
||||
= HomePage
|
||||
| LoginPage (Maybe Page)
|
||||
| ManageDataPage
|
||||
| CollectiveSettingPage
|
||||
@ -39,7 +39,7 @@ type Page
|
||||
isSecured : Page -> Bool
|
||||
isSecured page =
|
||||
case page of
|
||||
HomePage _ ->
|
||||
HomePage ->
|
||||
True
|
||||
|
||||
LoginPage _ ->
|
||||
@ -88,7 +88,7 @@ loginPage p =
|
||||
pageName : Page -> String
|
||||
pageName page =
|
||||
case page of
|
||||
HomePage _ ->
|
||||
HomePage ->
|
||||
"Home"
|
||||
|
||||
LoginPage _ ->
|
||||
@ -147,10 +147,7 @@ uploadId page =
|
||||
pageToString : Page -> String
|
||||
pageToString page =
|
||||
case page of
|
||||
HomePage (Just id) ->
|
||||
"/app/home?item=" ++ id
|
||||
|
||||
HomePage Nothing ->
|
||||
HomePage ->
|
||||
"/app/home"
|
||||
|
||||
LoginPage referer ->
|
||||
@ -232,8 +229,8 @@ parser =
|
||||
oneOf
|
||||
[ Parser.map HomePage
|
||||
(oneOf
|
||||
[ Parser.top <?> itemQuery
|
||||
, s pathPrefix </> s "home" <?> itemQuery
|
||||
[ Parser.top
|
||||
, s pathPrefix </> s "home"
|
||||
]
|
||||
)
|
||||
, Parser.map LoginPage (s pathPrefix </> s "login" <?> pageQuery)
|
||||
@ -271,8 +268,3 @@ pageQuery =
|
||||
in
|
||||
Query.string "r"
|
||||
|> Query.map parsePage
|
||||
|
||||
|
||||
itemQuery : Query.Parser (Maybe String)
|
||||
itemQuery =
|
||||
Query.string "item"
|
||||
|
@ -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
|
||||
|
@ -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 )
|
||||
|
@ -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
|
||||
|
@ -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 )
|
||||
|
@ -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 "
|
||||
|
Loading…
x
Reference in New Issue
Block a user