mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-06 15:15:58 +00:00
Fix updating search view
For example, when content-search was activated the view was not correctly updated after deleting or drag-and-drop.
This commit is contained in:
parent
32c9113bd4
commit
d62c4a5a72
@ -1,6 +1,7 @@
|
|||||||
module Page.Home.Data exposing
|
module Page.Home.Data exposing
|
||||||
( Model
|
( Model
|
||||||
, Msg(..)
|
, Msg(..)
|
||||||
|
, SearchParam
|
||||||
, SearchType(..)
|
, SearchType(..)
|
||||||
, SelectActionMode(..)
|
, SelectActionMode(..)
|
||||||
, SelectViewModel
|
, SelectViewModel
|
||||||
@ -49,8 +50,8 @@ type alias Model =
|
|||||||
, moreInProgress : Bool
|
, moreInProgress : Bool
|
||||||
, throttle : Throttle Msg
|
, throttle : Throttle Msg
|
||||||
, searchTypeDropdown : Comp.FixedDropdown.Model SearchType
|
, searchTypeDropdown : Comp.FixedDropdown.Model SearchType
|
||||||
, searchType : SearchType
|
, searchTypeDropdownValue : SearchType
|
||||||
, searchTypeForm : SearchType
|
, lastSearchType : SearchType
|
||||||
, contentOnlySearch : Maybe String
|
, contentOnlySearch : Maybe String
|
||||||
, dragDropData : DD.DragDropData
|
, dragDropData : DD.DragDropData
|
||||||
, scrollToCard : Maybe String
|
, scrollToCard : Maybe String
|
||||||
@ -104,8 +105,8 @@ init flags viewMode =
|
|||||||
, searchTypeDropdown =
|
, searchTypeDropdown =
|
||||||
Comp.FixedDropdown.initMap searchTypeString
|
Comp.FixedDropdown.initMap searchTypeString
|
||||||
searchTypeOptions
|
searchTypeOptions
|
||||||
, searchType = BasicSearch
|
, searchTypeDropdownValue = defaultSearchType flags
|
||||||
, searchTypeForm = defaultSearchType flags
|
, lastSearchType = BasicSearch
|
||||||
, contentOnlySearch = Nothing
|
, contentOnlySearch = Nothing
|
||||||
, dragDropData =
|
, dragDropData =
|
||||||
DD.DragDropData DD.init Nothing
|
DD.DragDropData DD.init Nothing
|
||||||
@ -156,14 +157,14 @@ type Msg
|
|||||||
| ItemCardListMsg Comp.ItemCardList.Msg
|
| ItemCardListMsg Comp.ItemCardList.Msg
|
||||||
| ItemSearchResp Bool (Result Http.Error ItemLightList)
|
| ItemSearchResp Bool (Result Http.Error ItemLightList)
|
||||||
| ItemSearchAddResp (Result Http.Error ItemLightList)
|
| ItemSearchAddResp (Result Http.Error ItemLightList)
|
||||||
| DoSearch
|
| DoSearch SearchType
|
||||||
| ToggleSearchMenu
|
| ToggleSearchMenu
|
||||||
| ToggleSelectView
|
| ToggleSelectView
|
||||||
| LoadMore
|
| LoadMore
|
||||||
| UpdateThrottle
|
| UpdateThrottle
|
||||||
| SetBasicSearch String
|
| SetBasicSearch String
|
||||||
| SearchTypeMsg (Comp.FixedDropdown.Msg SearchType)
|
| SearchTypeMsg (Comp.FixedDropdown.Msg SearchType)
|
||||||
| KeyUpMsg (Maybe KeyCode)
|
| KeyUpSearchbarMsg (Maybe KeyCode)
|
||||||
| SetContentOnly String
|
| SetContentOnly String
|
||||||
| ScrollResult (Result Dom.Error ())
|
| ScrollResult (Result Dom.Error ())
|
||||||
| ClearItemDetailId
|
| ClearItemDetailId
|
||||||
@ -191,6 +192,15 @@ type SelectActionMode
|
|||||||
| EditSelected
|
| EditSelected
|
||||||
|
|
||||||
|
|
||||||
|
type alias SearchParam =
|
||||||
|
{ flags : Flags
|
||||||
|
, searchType : SearchType
|
||||||
|
, pageSize : Int
|
||||||
|
, offset : Int
|
||||||
|
, scroll : Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
searchTypeString : SearchType -> String
|
searchTypeString : SearchType -> String
|
||||||
searchTypeString st =
|
searchTypeString st =
|
||||||
case st of
|
case st of
|
||||||
@ -215,51 +225,51 @@ itemNav id model =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
doSearchCmd : Flags -> UiSettings -> Int -> Bool -> Model -> Cmd Msg
|
doSearchCmd : SearchParam -> Model -> Cmd Msg
|
||||||
doSearchCmd flags settings offset scroll model =
|
doSearchCmd param model =
|
||||||
case model.searchType of
|
case param.searchType of
|
||||||
BasicSearch ->
|
BasicSearch ->
|
||||||
doSearchDefaultCmd flags settings offset scroll model
|
doSearchDefaultCmd param model
|
||||||
|
|
||||||
ContentOnlySearch ->
|
ContentOnlySearch ->
|
||||||
doSearchIndexCmd flags settings offset scroll model
|
doSearchIndexCmd param model
|
||||||
|
|
||||||
|
|
||||||
doSearchDefaultCmd : Flags -> UiSettings -> Int -> Bool -> Model -> Cmd Msg
|
doSearchDefaultCmd : SearchParam -> Model -> Cmd Msg
|
||||||
doSearchDefaultCmd flags settings offset scroll model =
|
doSearchDefaultCmd param model =
|
||||||
let
|
let
|
||||||
smask =
|
smask =
|
||||||
Comp.SearchMenu.getItemSearch model.searchMenuModel
|
Comp.SearchMenu.getItemSearch model.searchMenuModel
|
||||||
|
|
||||||
mask =
|
mask =
|
||||||
{ smask
|
{ smask
|
||||||
| limit = settings.itemSearchPageSize
|
| limit = param.pageSize
|
||||||
, offset = offset
|
, offset = param.offset
|
||||||
}
|
}
|
||||||
in
|
in
|
||||||
if offset == 0 then
|
if param.offset == 0 then
|
||||||
Api.itemSearch flags mask (ItemSearchResp scroll)
|
Api.itemSearch param.flags mask (ItemSearchResp param.scroll)
|
||||||
|
|
||||||
else
|
else
|
||||||
Api.itemSearch flags mask ItemSearchAddResp
|
Api.itemSearch param.flags mask ItemSearchAddResp
|
||||||
|
|
||||||
|
|
||||||
doSearchIndexCmd : Flags -> UiSettings -> Int -> Bool -> Model -> Cmd Msg
|
doSearchIndexCmd : SearchParam -> Model -> Cmd Msg
|
||||||
doSearchIndexCmd flags settings offset scroll model =
|
doSearchIndexCmd param model =
|
||||||
case model.contentOnlySearch of
|
case model.contentOnlySearch of
|
||||||
Just q ->
|
Just q ->
|
||||||
let
|
let
|
||||||
mask =
|
mask =
|
||||||
{ query = q
|
{ query = q
|
||||||
, limit = settings.itemSearchPageSize
|
, limit = param.pageSize
|
||||||
, offset = offset
|
, offset = param.offset
|
||||||
}
|
}
|
||||||
in
|
in
|
||||||
if offset == 0 then
|
if param.offset == 0 then
|
||||||
Api.itemIndexSearch flags mask (ItemSearchResp scroll)
|
Api.itemIndexSearch param.flags mask (ItemSearchResp param.scroll)
|
||||||
|
|
||||||
else
|
else
|
||||||
Api.itemIndexSearch flags mask ItemSearchAddResp
|
Api.itemIndexSearch param.flags mask ItemSearchAddResp
|
||||||
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
-- If there is no fulltext query, render simply the most
|
-- If there is no fulltext query, render simply the most
|
||||||
@ -269,9 +279,9 @@ doSearchIndexCmd flags settings offset scroll model =
|
|||||||
Api.Model.ItemSearch.empty
|
Api.Model.ItemSearch.empty
|
||||||
|
|
||||||
mask =
|
mask =
|
||||||
{ emptyMask | limit = settings.itemSearchPageSize }
|
{ emptyMask | limit = param.pageSize }
|
||||||
in
|
in
|
||||||
Api.itemSearch flags mask (ItemSearchResp scroll)
|
Api.itemSearch param.flags mask (ItemSearchResp param.scroll)
|
||||||
|
|
||||||
|
|
||||||
resultsBelowLimit : UiSettings -> Model -> Bool
|
resultsBelowLimit : UiSettings -> Model -> Bool
|
||||||
|
@ -6,7 +6,6 @@ import Api.Model.ItemLightList exposing (ItemLightList)
|
|||||||
import Api.Model.ItemSearch
|
import Api.Model.ItemSearch
|
||||||
import Browser.Navigation as Nav
|
import Browser.Navigation as Nav
|
||||||
import Comp.FixedDropdown
|
import Comp.FixedDropdown
|
||||||
import Comp.ItemCard
|
|
||||||
import Comp.ItemCardList
|
import Comp.ItemCardList
|
||||||
import Comp.ItemDetail.EditMenu exposing (SaveNameState(..))
|
import Comp.ItemDetail.EditMenu exposing (SaveNameState(..))
|
||||||
import Comp.ItemDetail.FormChange exposing (FormChange(..))
|
import Comp.ItemDetail.FormChange exposing (FormChange(..))
|
||||||
@ -28,7 +27,6 @@ import Time
|
|||||||
import Util.Html exposing (KeyCode(..))
|
import Util.Html exposing (KeyCode(..))
|
||||||
import Util.ItemDragDrop as DD
|
import Util.ItemDragDrop as DD
|
||||||
import Util.Maybe
|
import Util.Maybe
|
||||||
import Util.String
|
|
||||||
import Util.Update
|
import Util.Update
|
||||||
|
|
||||||
|
|
||||||
@ -36,9 +34,18 @@ update : Maybe String -> Nav.Key -> Flags -> UiSettings -> Msg -> Model -> ( Mod
|
|||||||
update mId key flags settings msg model =
|
update mId key flags settings msg model =
|
||||||
case msg of
|
case msg of
|
||||||
Init ->
|
Init ->
|
||||||
|
let
|
||||||
|
searchParam =
|
||||||
|
{ flags = flags
|
||||||
|
, searchType = model.lastSearchType
|
||||||
|
, pageSize = settings.itemSearchPageSize
|
||||||
|
, offset = 0
|
||||||
|
, scroll = True
|
||||||
|
}
|
||||||
|
in
|
||||||
Util.Update.andThen2
|
Util.Update.andThen2
|
||||||
[ update mId key flags settings (SearchMenuMsg Comp.SearchMenu.Init)
|
[ update mId key flags settings (SearchMenuMsg Comp.SearchMenu.Init)
|
||||||
, doSearch flags settings True
|
, doSearch searchParam
|
||||||
]
|
]
|
||||||
model
|
model
|
||||||
|
|
||||||
@ -47,7 +54,6 @@ update mId key flags settings msg model =
|
|||||||
nm =
|
nm =
|
||||||
{ model
|
{ model
|
||||||
| searchOffset = 0
|
| searchOffset = 0
|
||||||
, searchType = defaultSearchType flags
|
|
||||||
, contentOnlySearch = Nothing
|
, contentOnlySearch = Nothing
|
||||||
}
|
}
|
||||||
in
|
in
|
||||||
@ -64,7 +70,7 @@ update mId key flags settings msg model =
|
|||||||
model.searchMenuModel
|
model.searchMenuModel
|
||||||
|
|
||||||
dropCmd =
|
dropCmd =
|
||||||
DD.makeUpdateCmd flags (\_ -> DoSearch) nextState.dragDrop.dropped
|
DD.makeUpdateCmd flags (\_ -> DoSearch model.lastSearchType) nextState.dragDrop.dropped
|
||||||
|
|
||||||
newModel =
|
newModel =
|
||||||
{ model
|
{ model
|
||||||
@ -74,7 +80,7 @@ update mId key flags settings msg model =
|
|||||||
|
|
||||||
( m2, c2, s2 ) =
|
( m2, c2, s2 ) =
|
||||||
if nextState.stateChange && not model.searchInProgress then
|
if nextState.stateChange && not model.searchInProgress then
|
||||||
doSearch flags settings False newModel
|
doSearch (SearchParam flags BasicSearch settings.itemSearchPageSize 0 False) newModel
|
||||||
|
|
||||||
else
|
else
|
||||||
withSub ( newModel, Cmd.none )
|
withSub ( newModel, Cmd.none )
|
||||||
@ -181,16 +187,24 @@ update mId key flags settings msg model =
|
|||||||
, Cmd.none
|
, Cmd.none
|
||||||
)
|
)
|
||||||
|
|
||||||
DoSearch ->
|
DoSearch stype ->
|
||||||
let
|
let
|
||||||
nm =
|
nm =
|
||||||
{ model | searchOffset = 0 }
|
{ model | searchOffset = 0 }
|
||||||
|
|
||||||
|
param =
|
||||||
|
{ flags = flags
|
||||||
|
, searchType = stype
|
||||||
|
, pageSize = settings.itemSearchPageSize
|
||||||
|
, offset = 0
|
||||||
|
, scroll = False
|
||||||
|
}
|
||||||
in
|
in
|
||||||
if model.searchInProgress then
|
if model.searchInProgress then
|
||||||
withSub ( model, Cmd.none )
|
withSub ( model, Cmd.none )
|
||||||
|
|
||||||
else
|
else
|
||||||
doSearch flags settings False nm
|
doSearch param nm
|
||||||
|
|
||||||
ToggleSearchMenu ->
|
ToggleSearchMenu ->
|
||||||
let
|
let
|
||||||
@ -247,7 +261,7 @@ update mId key flags settings msg model =
|
|||||||
SetBasicSearch str ->
|
SetBasicSearch str ->
|
||||||
let
|
let
|
||||||
smMsg =
|
smMsg =
|
||||||
case model.searchTypeForm of
|
case model.searchTypeDropdownValue of
|
||||||
BasicSearch ->
|
BasicSearch ->
|
||||||
SearchMenuMsg (Comp.SearchMenu.SetAllName str)
|
SearchMenuMsg (Comp.SearchMenu.SetAllName str)
|
||||||
|
|
||||||
@ -268,12 +282,12 @@ update mId key flags settings msg model =
|
|||||||
Comp.FixedDropdown.update lm model.searchTypeDropdown
|
Comp.FixedDropdown.update lm model.searchTypeDropdown
|
||||||
|
|
||||||
mvChange =
|
mvChange =
|
||||||
Util.Maybe.filter (\a -> a /= model.searchTypeForm) mv
|
Util.Maybe.filter (\a -> a /= model.searchTypeDropdownValue) mv
|
||||||
|
|
||||||
m0 =
|
m0 =
|
||||||
{ model
|
{ model
|
||||||
| searchTypeDropdown = sm
|
| searchTypeDropdown = sm
|
||||||
, searchTypeForm = Maybe.withDefault model.searchTypeForm mv
|
, searchTypeDropdownValue = Maybe.withDefault model.searchTypeDropdownValue mv
|
||||||
}
|
}
|
||||||
|
|
||||||
next =
|
next =
|
||||||
@ -300,10 +314,10 @@ update mId key flags settings msg model =
|
|||||||
Nothing ->
|
Nothing ->
|
||||||
withSub ( m0, Cmd.none )
|
withSub ( m0, Cmd.none )
|
||||||
|
|
||||||
KeyUpMsg (Just Enter) ->
|
KeyUpSearchbarMsg (Just Enter) ->
|
||||||
update mId key flags settings DoSearch model
|
update mId key flags settings (DoSearch model.searchTypeDropdownValue) model
|
||||||
|
|
||||||
KeyUpMsg _ ->
|
KeyUpSearchbarMsg _ ->
|
||||||
withSub ( model, Cmd.none )
|
withSub ( model, Cmd.none )
|
||||||
|
|
||||||
ScrollResult _ ->
|
ScrollResult _ ->
|
||||||
@ -390,8 +404,16 @@ update mId key flags settings msg model =
|
|||||||
let
|
let
|
||||||
nm =
|
nm =
|
||||||
{ model | viewMode = SearchView }
|
{ model | viewMode = SearchView }
|
||||||
|
|
||||||
|
param =
|
||||||
|
{ flags = flags
|
||||||
|
, searchType = model.lastSearchType
|
||||||
|
, pageSize = settings.itemSearchPageSize
|
||||||
|
, offset = 0
|
||||||
|
, scroll = False
|
||||||
|
}
|
||||||
in
|
in
|
||||||
doSearch flags settings False nm
|
doSearch param nm
|
||||||
|
|
||||||
else
|
else
|
||||||
noSub ( model, Cmd.none )
|
noSub ( model, Cmd.none )
|
||||||
@ -540,7 +562,7 @@ update mId key flags settings msg model =
|
|||||||
model_ =
|
model_ =
|
||||||
{ model | viewMode = viewMode }
|
{ model | viewMode = viewMode }
|
||||||
in
|
in
|
||||||
update mId key flags settings DoSearch model_
|
update mId key flags settings (DoSearch model.lastSearchType) model_
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -648,33 +670,24 @@ loadEditModel flags =
|
|||||||
Cmd.map EditMenuMsg (Comp.ItemDetail.EditMenu.loadModel flags)
|
Cmd.map EditMenuMsg (Comp.ItemDetail.EditMenu.loadModel flags)
|
||||||
|
|
||||||
|
|
||||||
doSearch : Flags -> UiSettings -> Bool -> Model -> ( Model, Cmd Msg, Sub Msg )
|
doSearch : SearchParam -> Model -> ( Model, Cmd Msg, Sub Msg )
|
||||||
doSearch flags settings scroll model =
|
doSearch param model =
|
||||||
let
|
let
|
||||||
stype =
|
param_ =
|
||||||
if
|
{ param | offset = 0 }
|
||||||
not (menuCollapsed model)
|
|
||||||
|| Util.String.isNothingOrBlank model.contentOnlySearch
|
|
||||||
then
|
|
||||||
BasicSearch
|
|
||||||
|
|
||||||
else
|
|
||||||
model.searchTypeForm
|
|
||||||
|
|
||||||
model_ =
|
|
||||||
{ model | searchType = stype }
|
|
||||||
|
|
||||||
searchCmd =
|
searchCmd =
|
||||||
doSearchCmd flags settings 0 scroll model_
|
doSearchCmd param_ model
|
||||||
|
|
||||||
( newThrottle, cmd ) =
|
( newThrottle, cmd ) =
|
||||||
Throttle.try searchCmd model.throttle
|
Throttle.try searchCmd model.throttle
|
||||||
in
|
in
|
||||||
withSub
|
withSub
|
||||||
( { model_
|
( { model
|
||||||
| searchInProgress = cmd /= Cmd.none
|
| searchInProgress = cmd /= Cmd.none
|
||||||
, searchOffset = 0
|
, searchOffset = 0
|
||||||
, throttle = newThrottle
|
, throttle = newThrottle
|
||||||
|
, lastSearchType = param.searchType
|
||||||
}
|
}
|
||||||
, cmd
|
, cmd
|
||||||
)
|
)
|
||||||
@ -708,8 +721,16 @@ linkTargetMsg linkTarget =
|
|||||||
doSearchMore : Flags -> UiSettings -> Model -> ( Model, Cmd Msg )
|
doSearchMore : Flags -> UiSettings -> Model -> ( Model, Cmd Msg )
|
||||||
doSearchMore flags settings model =
|
doSearchMore flags settings model =
|
||||||
let
|
let
|
||||||
|
param =
|
||||||
|
{ flags = flags
|
||||||
|
, searchType = model.lastSearchType
|
||||||
|
, pageSize = settings.itemSearchPageSize
|
||||||
|
, offset = model.searchOffset
|
||||||
|
, scroll = False
|
||||||
|
}
|
||||||
|
|
||||||
cmd =
|
cmd =
|
||||||
doSearchCmd flags settings model.searchOffset False model
|
doSearchCmd param model
|
||||||
in
|
in
|
||||||
( { model | moreInProgress = True }
|
( { model | moreInProgress = True }
|
||||||
, cmd
|
, cmd
|
||||||
|
@ -83,7 +83,7 @@ view flags settings model =
|
|||||||
]
|
]
|
||||||
, a
|
, a
|
||||||
[ class "borderless item"
|
[ class "borderless item"
|
||||||
, onClick DoSearch
|
, onClick (DoSearch BasicSearch)
|
||||||
, title "Run search query"
|
, title "Run search query"
|
||||||
, href ""
|
, href ""
|
||||||
, disabled model.searchInProgress
|
, disabled model.searchInProgress
|
||||||
@ -281,11 +281,11 @@ viewSearchBar flags model =
|
|||||||
let
|
let
|
||||||
searchTypeItem =
|
searchTypeItem =
|
||||||
Comp.FixedDropdown.Item
|
Comp.FixedDropdown.Item
|
||||||
model.searchTypeForm
|
model.searchTypeDropdownValue
|
||||||
(searchTypeString model.searchTypeForm)
|
(searchTypeString model.searchTypeDropdownValue)
|
||||||
|
|
||||||
searchInput =
|
searchInput =
|
||||||
case model.searchTypeForm of
|
case model.searchTypeDropdownValue of
|
||||||
BasicSearch ->
|
BasicSearch ->
|
||||||
model.searchMenuModel.allNameModel
|
model.searchMenuModel.allNameModel
|
||||||
|
|
||||||
@ -326,9 +326,9 @@ viewSearchBar flags model =
|
|||||||
, ( "loading spinner icon", model.searchInProgress )
|
, ( "loading spinner icon", model.searchInProgress )
|
||||||
]
|
]
|
||||||
, href "#"
|
, href "#"
|
||||||
, onClick DoSearch
|
, onClick (DoSearch model.searchTypeDropdownValue)
|
||||||
]
|
]
|
||||||
(if hasMoreSearch model && model.searchTypeForm == BasicSearch then
|
(if hasMoreSearch model && model.searchTypeDropdownValue == BasicSearch then
|
||||||
[ i [ class "icons search-corner-icons" ]
|
[ i [ class "icons search-corner-icons" ]
|
||||||
[ i [ class "tiny blue circle icon" ] []
|
[ i [ class "tiny blue circle icon" ] []
|
||||||
]
|
]
|
||||||
@ -341,7 +341,7 @@ viewSearchBar flags model =
|
|||||||
[ type_ "text"
|
[ type_ "text"
|
||||||
, placeholder "Quick Search …"
|
, placeholder "Quick Search …"
|
||||||
, onInput SetBasicSearch
|
, onInput SetBasicSearch
|
||||||
, Util.Html.onKeyUpCode KeyUpMsg
|
, Util.Html.onKeyUpCode KeyUpSearchbarMsg
|
||||||
, Maybe.map value searchInput
|
, Maybe.map value searchInput
|
||||||
|> Maybe.withDefault (value "")
|
|> Maybe.withDefault (value "")
|
||||||
]
|
]
|
||||||
@ -381,7 +381,7 @@ hasMoreSearch model =
|
|||||||
Comp.SearchMenu.getItemSearch model.searchMenuModel
|
Comp.SearchMenu.getItemSearch model.searchMenuModel
|
||||||
|
|
||||||
is_ =
|
is_ =
|
||||||
case model.searchType of
|
case model.lastSearchType of
|
||||||
BasicSearch ->
|
BasicSearch ->
|
||||||
{ is | allNames = Nothing }
|
{ is | allNames = Nothing }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user