From fc5035ea8d25cd188bd18bf97bd86df983df86a9 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sun, 18 Oct 2020 14:09:52 +0200 Subject: [PATCH 1/3] Use anchor links instead of javascript to go to detail view --- .../webapp/src/main/elm/Comp/ItemCardList.elm | 22 +++++++------------ .../webapp/src/main/elm/Page/Home/Update.elm | 10 +-------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/modules/webapp/src/main/elm/Comp/ItemCardList.elm b/modules/webapp/src/main/elm/Comp/ItemCardList.elm index 17c4bf5d..945febf5 100644 --- a/modules/webapp/src/main/elm/Comp/ItemCardList.elm +++ b/modules/webapp/src/main/elm/Comp/ItemCardList.elm @@ -21,8 +21,8 @@ import Data.Items import Data.UiSettings exposing (UiSettings) import Html exposing (..) import Html.Attributes exposing (..) -import Html.Events exposing (onClick) import Markdown +import Page exposing (Page(..)) import Util.ItemDragDrop as DD import Util.List import Util.String @@ -37,7 +37,6 @@ type alias Model = type Msg = SetResults ItemLightList | AddResults ItemLightList - | SelectItem ItemLight | ItemDDMsg DD.Msg @@ -63,19 +62,18 @@ prevItem model id = --- Update -update : Flags -> Msg -> Model -> ( Model, Cmd Msg, Maybe ItemLight ) +update : Flags -> Msg -> Model -> ( Model, Cmd Msg ) update flags msg model = let res = updateDrag DD.init flags msg model in - ( res.model, res.cmd, res.selected ) + ( res.model, res.cmd ) type alias UpdateResult = { model : Model , cmd : Cmd Msg - , selected : Maybe ItemLight , dragModel : DD.Model } @@ -93,28 +91,25 @@ updateDrag dm _ msg model = newModel = { model | results = list } in - UpdateResult newModel Cmd.none Nothing dm + UpdateResult newModel Cmd.none dm AddResults list -> if list.groups == [] then - UpdateResult model Cmd.none Nothing dm + UpdateResult model Cmd.none dm else let newModel = { model | results = Data.Items.concat model.results list } in - UpdateResult newModel Cmd.none Nothing dm - - SelectItem item -> - UpdateResult model Cmd.none (Just item) dm + UpdateResult newModel Cmd.none dm ItemDDMsg lm -> let ddd = DD.update lm dm in - UpdateResult model Cmd.none Nothing ddd.model + UpdateResult model Cmd.none ddd.model @@ -181,8 +176,7 @@ viewItem current settings item = , ( "current", current == Just item.id ) ] , id item.id - , href "#" - , onClick (SelectItem item) + , Page.href (ItemDetailPage item.id) ] ++ DD.draggable ItemDDMsg item.id ) diff --git a/modules/webapp/src/main/elm/Page/Home/Update.elm b/modules/webapp/src/main/elm/Page/Home/Update.elm index 4a92ade6..2382929a 100644 --- a/modules/webapp/src/main/elm/Page/Home/Update.elm +++ b/modules/webapp/src/main/elm/Page/Home/Update.elm @@ -82,21 +82,13 @@ update mId key flags settings msg model = flags m model.itemListModel - - ( cmd, id ) = - case result.selected of - Just item -> - ( Page.set key (ItemDetailPage item.id), Just item.id ) - - Nothing -> - ( Cmd.none, Nothing ) in withSub ( { model | itemListModel = result.model , dragDropData = DD.DragDropData result.dragModel Nothing } - , Cmd.batch [ Cmd.map ItemCardListMsg result.cmd, cmd ] + , Cmd.batch [ Cmd.map ItemCardListMsg result.cmd ] ) ItemSearchResp (Ok list) -> From ead2e5225347343d62b5a082e2b9dfe99a9ff2a9 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sun, 18 Oct 2020 14:26:18 +0200 Subject: [PATCH 2/3] Show item name in document title --- modules/webapp/src/main/elm/Main.elm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/webapp/src/main/elm/Main.elm b/modules/webapp/src/main/elm/Main.elm index fbc29b5e..773c6297 100644 --- a/modules/webapp/src/main/elm/Main.elm +++ b/modules/webapp/src/main/elm/Main.elm @@ -11,7 +11,7 @@ import Data.UiSettings import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) -import Page +import Page exposing (Page(..)) import Ports import Url exposing (Url) @@ -73,7 +73,16 @@ init flags url key = viewDoc : Model -> Document Msg viewDoc model = - { title = model.flags.config.appName ++ ": " ++ Page.pageName model.page + let + title = + case model.page of + ItemDetailPage _ -> + model.itemDetailModel.detail.item.name + + _ -> + Page.pageName model.page + in + { title = model.flags.config.appName ++ ": " ++ title , body = [ view model ] } From 5e0eaf419ea02e687adad949dd4c3ad6b9553e0b Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sun, 18 Oct 2020 21:32:37 +0200 Subject: [PATCH 3/3] 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. --- modules/webapp/src/main/elm/App/Data.elm | 2 +- modules/webapp/src/main/elm/App/Update.elm | 7 ++++--- modules/webapp/src/main/elm/App/View.elm | 11 +++++----- .../src/main/elm/Comp/ItemDetail/Update.elm | 2 +- .../src/main/elm/Comp/ItemDetail/View.elm | 2 +- modules/webapp/src/main/elm/Page.elm | 20 ++++++------------- .../webapp/src/main/elm/Page/Home/Data.elm | 4 +++- .../webapp/src/main/elm/Page/Home/Update.elm | 17 +++++++--------- .../webapp/src/main/elm/Page/Home/View.elm | 2 +- .../webapp/src/main/elm/Page/Login/Update.elm | 2 +- .../webapp/src/main/elm/Page/Upload/View.elm | 2 +- 11 files changed, 32 insertions(+), 39 deletions(-) diff --git a/modules/webapp/src/main/elm/App/Data.elm b/modules/webapp/src/main/elm/App/Data.elm index c461fadc..28fbd8d4 100644 --- a/modules/webapp/src/main/elm/App/Data.elm +++ b/modules/webapp/src/main/elm/App/Data.elm @@ -160,7 +160,7 @@ checkPage flags page = defaultPage : Flags -> Page defaultPage flags = if isSignedIn flags then - HomePage Nothing + HomePage else LoginPage Nothing diff --git a/modules/webapp/src/main/elm/App/Update.elm b/modules/webapp/src/main/elm/App/Update.elm index dfdf5316..e261463b 100644 --- a/modules/webapp/src/main/elm/App/Update.elm +++ b/modules/webapp/src/main/elm/App/Update.elm @@ -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 diff --git a/modules/webapp/src/main/elm/App/View.elm b/modules/webapp/src/main/elm/App/View.elm index afd850d7..2223a342 100644 --- a/modules/webapp/src/main/elm/App/View.elm +++ b/modules/webapp/src/main/elm/App/View.elm @@ -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") diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm index f6a8f5a9..5fddccca 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm @@ -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 ) diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm index 131c1c8f..ba2b76b9 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/View.elm @@ -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 diff --git a/modules/webapp/src/main/elm/Page.elm b/modules/webapp/src/main/elm/Page.elm index 7308e1a2..286d35bf 100644 --- a/modules/webapp/src/main/elm/Page.elm +++ b/modules/webapp/src/main/elm/Page.elm @@ -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" diff --git a/modules/webapp/src/main/elm/Page/Home/Data.elm b/modules/webapp/src/main/elm/Page/Home/Data.elm index eda1efbf..cb671eb5 100644 --- a/modules/webapp/src/main/elm/Page/Home/Data.elm +++ b/modules/webapp/src/main/elm/Page/Home/Data.elm @@ -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 diff --git a/modules/webapp/src/main/elm/Page/Home/Update.elm b/modules/webapp/src/main/elm/Page/Home/Update.elm index 2382929a..edb3d70b 100644 --- a/modules/webapp/src/main/elm/Page/Home/Update.elm +++ b/modules/webapp/src/main/elm/Page/Home/Update.elm @@ -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 ) diff --git a/modules/webapp/src/main/elm/Page/Home/View.elm b/modules/webapp/src/main/elm/Page/Home/View.elm index 69f0b2d4..32653c43 100644 --- a/modules/webapp/src/main/elm/Page/Home/View.elm +++ b/modules/webapp/src/main/elm/Page/Home/View.elm @@ -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 diff --git a/modules/webapp/src/main/elm/Page/Login/Update.elm b/modules/webapp/src/main/elm/Page/Login/Update.elm index 54145cd8..539d2f02 100644 --- a/modules/webapp/src/main/elm/Page/Login/Update.elm +++ b/modules/webapp/src/main/elm/Page/Login/Update.elm @@ -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 ) diff --git a/modules/webapp/src/main/elm/Page/Upload/View.elm b/modules/webapp/src/main/elm/Page/Upload/View.elm index f45873da..a297fb28 100644 --- a/modules/webapp/src/main/elm/Page/Upload/View.elm +++ b/modules/webapp/src/main/elm/Page/Upload/View.elm @@ -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 "