From 5810eac899269bc917fecf9a84e4d1833f232840 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sat, 8 Aug 2020 17:24:27 +0200 Subject: [PATCH] Fix remembering selection when going to detail view --- .../webapp/src/main/elm/Comp/FolderSelect.elm | 6 ++--- .../webapp/src/main/elm/Comp/SearchMenu.elm | 8 +++---- .../webapp/src/main/elm/Comp/TagSelect.elm | 24 +++++++++++++++---- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/modules/webapp/src/main/elm/Comp/FolderSelect.elm b/modules/webapp/src/main/elm/Comp/FolderSelect.elm index 9ca36a80..35d4a3da 100644 --- a/modules/webapp/src/main/elm/Comp/FolderSelect.elm +++ b/modules/webapp/src/main/elm/Comp/FolderSelect.elm @@ -24,10 +24,10 @@ type alias Model = } -init : List FolderItem -> Model -init all = +init : Maybe FolderItem -> List FolderItem -> Model +init selected all = { all = List.sortBy .name all - , selected = Nothing + , selected = Maybe.map .id selected , expanded = False } diff --git a/modules/webapp/src/main/elm/Comp/SearchMenu.elm b/modules/webapp/src/main/elm/Comp/SearchMenu.elm index 93d680f6..a829a8b2 100644 --- a/modules/webapp/src/main/elm/Comp/SearchMenu.elm +++ b/modules/webapp/src/main/elm/Comp/SearchMenu.elm @@ -71,7 +71,7 @@ type alias Model = init : Model init = - { tagSelectModel = Comp.TagSelect.init [] + { tagSelectModel = Comp.TagSelect.init Comp.TagSelect.emptySelection [] , tagSelection = Comp.TagSelect.emptySelection , directionModel = Comp.Dropdown.makeSingleList @@ -111,7 +111,7 @@ init = , labelColor = \_ -> \_ -> "" , placeholder = "Choose an equipment" } - , folderList = Comp.FolderSelect.init [] + , folderList = Comp.FolderSelect.init Nothing [] , selectedFolder = Nothing , inboxCheckbox = False , fromDateModel = Comp.DatePicker.emptyModel @@ -288,7 +288,7 @@ updateDrop ddm flags settings msg model = selectModel = List.sortBy .count tags.items |> List.reverse - |> Comp.TagSelect.init + |> Comp.TagSelect.init model.tagSelection model_ = { model | tagSelectModel = selectModel } @@ -571,7 +571,7 @@ updateDrop ddm flags settings msg model = { model | folderList = Util.Folder.onlyVisible flags fs.items - |> Comp.FolderSelect.init + |> Comp.FolderSelect.init model.selectedFolder } in { model = model_ diff --git a/modules/webapp/src/main/elm/Comp/TagSelect.elm b/modules/webapp/src/main/elm/Comp/TagSelect.elm index 26fd1358..a8286d58 100644 --- a/modules/webapp/src/main/elm/Comp/TagSelect.elm +++ b/modules/webapp/src/main/elm/Comp/TagSelect.elm @@ -41,12 +41,28 @@ type alias Category = } -init : List TagCount -> Model -init tags = +init : Selection -> List TagCount -> Model +init sel tags = + let + tagId t = + t.tag.id + + constDict mkId flag list = + List.map (\e -> ( mkId e, flag )) list + |> Dict.fromList + + selTag = + constDict tagId True sel.includeTags + |> Dict.union (constDict tagId False sel.excludeTags) + + selCat = + constDict .name True sel.includeCats + |> Dict.union (constDict .name False sel.excludeCats) + in { all = tags , categories = sumCategories tags - , selectedTags = Dict.empty - , selectedCats = Dict.empty + , selectedTags = selTag + , selectedCats = selCat , expandedTags = False , expandedCats = False }