mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-03-28 17:55:06 +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 -> Page
|
||||||
defaultPage flags =
|
defaultPage flags =
|
||||||
if isSignedIn flags then
|
if isSignedIn flags then
|
||||||
HomePage Nothing
|
HomePage
|
||||||
|
|
||||||
else
|
else
|
||||||
LoginPage Nothing
|
LoginPage Nothing
|
||||||
|
@ -31,6 +31,7 @@ import Page.UserSettings.Data
|
|||||||
import Page.UserSettings.Update
|
import Page.UserSettings.Update
|
||||||
import Ports
|
import Ports
|
||||||
import Url
|
import Url
|
||||||
|
import Util.Maybe
|
||||||
import Util.Update
|
import Util.Update
|
||||||
|
|
||||||
|
|
||||||
@ -312,8 +313,8 @@ updateHome lmsg model =
|
|||||||
let
|
let
|
||||||
mid =
|
mid =
|
||||||
case model.page of
|
case model.page of
|
||||||
HomePage x ->
|
HomePage ->
|
||||||
x
|
Util.Maybe.fromString model.itemDetailModel.detail.item.id
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
Nothing
|
Nothing
|
||||||
@ -348,7 +349,7 @@ initPage model_ page =
|
|||||||
{ model_ | page = page }
|
{ model_ | page = page }
|
||||||
in
|
in
|
||||||
case page of
|
case page of
|
||||||
HomePage _ ->
|
HomePage ->
|
||||||
Util.Update.andThen2
|
Util.Update.andThen2
|
||||||
[ updateHome Page.Home.Data.Init
|
[ updateHome Page.Home.Data.Init
|
||||||
, updateQueue Page.Queue.Data.StopRefresh
|
, updateQueue Page.Queue.Data.StopRefresh
|
||||||
|
@ -16,6 +16,7 @@ import Page.Queue.View
|
|||||||
import Page.Register.View
|
import Page.Register.View
|
||||||
import Page.Upload.View
|
import Page.Upload.View
|
||||||
import Page.UserSettings.View
|
import Page.UserSettings.View
|
||||||
|
import Util.Maybe
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html Msg
|
view : Model -> Html Msg
|
||||||
@ -65,7 +66,7 @@ defaultLayout model =
|
|||||||
[ div [ class "ui fluid container" ]
|
[ div [ class "ui fluid container" ]
|
||||||
[ a
|
[ a
|
||||||
[ class "header item narrow-item"
|
[ class "header item narrow-item"
|
||||||
, Page.href (HomePage Nothing)
|
, Page.href HomePage
|
||||||
]
|
]
|
||||||
[ img
|
[ img
|
||||||
[ class "image"
|
[ class "image"
|
||||||
@ -84,7 +85,7 @@ defaultLayout model =
|
|||||||
, id "main-content"
|
, id "main-content"
|
||||||
]
|
]
|
||||||
[ case model.page of
|
[ case model.page of
|
||||||
HomePage _ ->
|
HomePage ->
|
||||||
viewHome model
|
viewHome model
|
||||||
|
|
||||||
LoginPage _ ->
|
LoginPage _ ->
|
||||||
@ -180,8 +181,8 @@ viewHome model =
|
|||||||
let
|
let
|
||||||
mid =
|
mid =
|
||||||
case model.page of
|
case model.page of
|
||||||
HomePage x ->
|
HomePage ->
|
||||||
x
|
Util.Maybe.fromString model.itemDetailModel.detail.item.id
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
Nothing
|
Nothing
|
||||||
@ -218,7 +219,7 @@ loginInfo model =
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
[ menuEntry model
|
[ menuEntry model
|
||||||
(HomePage Nothing)
|
HomePage
|
||||||
[ img
|
[ img
|
||||||
[ class "image icon"
|
[ class "image icon"
|
||||||
, src (model.flags.config.docspellAssetPath ++ "/img/logo-mc-96.png")
|
, 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) )
|
noSub ( model, Page.set key (ItemDetailPage id) )
|
||||||
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
noSub ( model, Page.set key (HomePage Nothing) )
|
noSub ( model, Page.set key HomePage )
|
||||||
|
|
||||||
else
|
else
|
||||||
noSub ( model, Cmd.none )
|
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" ] []
|
[ i [ class "arrow left icon" ] []
|
||||||
]
|
]
|
||||||
, a
|
, a
|
||||||
|
@ -24,7 +24,7 @@ import Util.Maybe
|
|||||||
|
|
||||||
|
|
||||||
type Page
|
type Page
|
||||||
= HomePage (Maybe String)
|
= HomePage
|
||||||
| LoginPage (Maybe Page)
|
| LoginPage (Maybe Page)
|
||||||
| ManageDataPage
|
| ManageDataPage
|
||||||
| CollectiveSettingPage
|
| CollectiveSettingPage
|
||||||
@ -39,7 +39,7 @@ type Page
|
|||||||
isSecured : Page -> Bool
|
isSecured : Page -> Bool
|
||||||
isSecured page =
|
isSecured page =
|
||||||
case page of
|
case page of
|
||||||
HomePage _ ->
|
HomePage ->
|
||||||
True
|
True
|
||||||
|
|
||||||
LoginPage _ ->
|
LoginPage _ ->
|
||||||
@ -88,7 +88,7 @@ loginPage p =
|
|||||||
pageName : Page -> String
|
pageName : Page -> String
|
||||||
pageName page =
|
pageName page =
|
||||||
case page of
|
case page of
|
||||||
HomePage _ ->
|
HomePage ->
|
||||||
"Home"
|
"Home"
|
||||||
|
|
||||||
LoginPage _ ->
|
LoginPage _ ->
|
||||||
@ -147,10 +147,7 @@ uploadId page =
|
|||||||
pageToString : Page -> String
|
pageToString : Page -> String
|
||||||
pageToString page =
|
pageToString page =
|
||||||
case page of
|
case page of
|
||||||
HomePage (Just id) ->
|
HomePage ->
|
||||||
"/app/home?item=" ++ id
|
|
||||||
|
|
||||||
HomePage Nothing ->
|
|
||||||
"/app/home"
|
"/app/home"
|
||||||
|
|
||||||
LoginPage referer ->
|
LoginPage referer ->
|
||||||
@ -232,8 +229,8 @@ parser =
|
|||||||
oneOf
|
oneOf
|
||||||
[ Parser.map HomePage
|
[ Parser.map HomePage
|
||||||
(oneOf
|
(oneOf
|
||||||
[ Parser.top <?> itemQuery
|
[ Parser.top
|
||||||
, s pathPrefix </> s "home" <?> itemQuery
|
, s pathPrefix </> s "home"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
, Parser.map LoginPage (s pathPrefix </> s "login" <?> pageQuery)
|
, Parser.map LoginPage (s pathPrefix </> s "login" <?> pageQuery)
|
||||||
@ -271,8 +268,3 @@ pageQuery =
|
|||||||
in
|
in
|
||||||
Query.string "r"
|
Query.string "r"
|
||||||
|> Query.map parsePage
|
|> Query.map parsePage
|
||||||
|
|
||||||
|
|
||||||
itemQuery : Query.Parser (Maybe String)
|
|
||||||
itemQuery =
|
|
||||||
Query.string "item"
|
|
||||||
|
@ -41,6 +41,7 @@ type alias Model =
|
|||||||
, searchTypeForm : SearchType
|
, searchTypeForm : SearchType
|
||||||
, contentOnlySearch : Maybe String
|
, contentOnlySearch : Maybe String
|
||||||
, dragDropData : DD.DragDropData
|
, dragDropData : DD.DragDropData
|
||||||
|
, scrollToCard : Maybe String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -70,6 +71,7 @@ init flags =
|
|||||||
, contentOnlySearch = Nothing
|
, contentOnlySearch = Nothing
|
||||||
, dragDropData =
|
, dragDropData =
|
||||||
DD.DragDropData DD.init Nothing
|
DD.DragDropData DD.init Nothing
|
||||||
|
, scrollToCard = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -98,7 +100,7 @@ type Msg
|
|||||||
| KeyUpMsg (Maybe KeyCode)
|
| KeyUpMsg (Maybe KeyCode)
|
||||||
| SetContentOnly String
|
| SetContentOnly String
|
||||||
| ScrollResult (Result Dom.Error ())
|
| ScrollResult (Result Dom.Error ())
|
||||||
| ClearItemDetailId (Maybe String)
|
| ClearItemDetailId
|
||||||
|
|
||||||
|
|
||||||
type SearchType
|
type SearchType
|
||||||
|
@ -243,18 +243,12 @@ update mId key flags settings msg model =
|
|||||||
ScrollResult _ ->
|
ScrollResult _ ->
|
||||||
let
|
let
|
||||||
cmd =
|
cmd =
|
||||||
Process.sleep 800 |> Task.perform (always (ClearItemDetailId mId))
|
Process.sleep 800 |> Task.perform (always ClearItemDetailId)
|
||||||
in
|
in
|
||||||
withSub ( model, cmd )
|
withSub ( model, cmd )
|
||||||
|
|
||||||
ClearItemDetailId id ->
|
ClearItemDetailId ->
|
||||||
-- if user clicks quickly away (e.g. on another item), the
|
noSub ( { model | scrollToCard = Nothing }, Cmd.none )
|
||||||
-- deferred command should be ignored
|
|
||||||
if mId == id then
|
|
||||||
noSub ( model, Page.set key (HomePage Nothing) )
|
|
||||||
|
|
||||||
else
|
|
||||||
noSub ( model, Cmd.none )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -269,7 +263,10 @@ scrollToCard mId model =
|
|||||||
in
|
in
|
||||||
case mId of
|
case mId of
|
||||||
Just id ->
|
Just id ->
|
||||||
( model, Task.attempt ScrollResult (scroll id), Sub.none )
|
( { model | scrollToCard = mId }
|
||||||
|
, Task.attempt ScrollResult (scroll id)
|
||||||
|
, Sub.none
|
||||||
|
)
|
||||||
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
( model, Cmd.none, Sub.none )
|
( model, Cmd.none, Sub.none )
|
||||||
|
@ -82,7 +82,7 @@ view current flags settings model =
|
|||||||
]
|
]
|
||||||
[ viewSearchBar flags model
|
[ viewSearchBar flags model
|
||||||
, Html.map ItemCardListMsg
|
, Html.map ItemCardListMsg
|
||||||
(Comp.ItemCardList.view current settings model.itemListModel)
|
(Comp.ItemCardList.view model.scrollToCard settings model.itemListModel)
|
||||||
]
|
]
|
||||||
, div
|
, div
|
||||||
[ classList
|
[ classList
|
||||||
|
@ -25,7 +25,7 @@ update referrer flags msg model =
|
|||||||
AuthResp (Ok lr) ->
|
AuthResp (Ok lr) ->
|
||||||
let
|
let
|
||||||
gotoRef =
|
gotoRef =
|
||||||
Maybe.withDefault (HomePage Nothing) referrer |> Page.goto
|
Maybe.withDefault HomePage referrer |> Page.goto
|
||||||
in
|
in
|
||||||
if lr.success then
|
if lr.success then
|
||||||
( { model | result = Just lr, password = "" }, Cmd.batch [ setAccount lr, gotoRef ], Just lr )
|
( { model | result = Just lr, password = "" }, Cmd.batch [ setAccount lr, gotoRef ], Just lr )
|
||||||
|
@ -77,7 +77,7 @@ renderSuccessMsg public _ =
|
|||||||
else
|
else
|
||||||
p []
|
p []
|
||||||
[ text "Your files have been successfully uploaded. They are now being processed. Check the "
|
[ 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 "Items page"
|
||||||
]
|
]
|
||||||
, text " later where the files will arrive eventually. Or go to the "
|
, text " later where the files will arrive eventually. Or go to the "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user