mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-05 02:49:32 +00:00
Remove a deleted item from search results
When an item is deleted in detail view, the results must be updated to reflect the new state. The results are now changed by removing the corresponding item. Fixes: #920
This commit is contained in:
parent
df5b59a7ce
commit
782ca0fa4f
@ -331,10 +331,18 @@ updateItemDetail lmsg model =
|
||||
|
||||
( hm, hc, hs ) =
|
||||
updateHome (Page.Home.Data.SetLinkTarget result.linkTarget) model_
|
||||
|
||||
( hm1, hc1, hs1 ) =
|
||||
case result.removedItem of
|
||||
Just removedId ->
|
||||
updateHome (Page.Home.Data.RemoveItem removedId) hm
|
||||
|
||||
Nothing ->
|
||||
( hm, hc, hs )
|
||||
in
|
||||
( hm
|
||||
, Cmd.batch [ Cmd.map ItemDetailMsg result.cmd, hc ]
|
||||
, Sub.batch [ Sub.map ItemDetailMsg result.sub, hs ]
|
||||
( hm1
|
||||
, Cmd.batch [ Cmd.map ItemDetailMsg result.cmd, hc, hc1 ]
|
||||
, Sub.batch [ Sub.map ItemDetailMsg result.sub, hs, hs1 ]
|
||||
)
|
||||
|
||||
|
||||
|
@ -46,6 +46,7 @@ type Msg
|
||||
= SetResults ItemLightList
|
||||
| AddResults ItemLightList
|
||||
| ItemCardMsg ItemLight Comp.ItemCard.Msg
|
||||
| RemoveItem String
|
||||
|
||||
|
||||
init : Model
|
||||
@ -145,6 +146,13 @@ updateDrag dm _ msg model =
|
||||
result.selection
|
||||
result.linkTarget
|
||||
|
||||
RemoveItem id ->
|
||||
UpdateResult { model | results = removeItemById id model.results }
|
||||
Cmd.none
|
||||
dm
|
||||
Data.ItemSelection.Inactive
|
||||
Comp.LinkTarget.LinkNone
|
||||
|
||||
|
||||
|
||||
--- View2
|
||||
@ -232,3 +240,15 @@ isMultiSelectMode cfg =
|
||||
|
||||
Data.ItemSelection.Inactive ->
|
||||
False
|
||||
|
||||
|
||||
removeItemById : String -> ItemLightList -> ItemLightList
|
||||
removeItemById id list =
|
||||
let
|
||||
filterItem item =
|
||||
item.id /= id
|
||||
|
||||
filterGroup group =
|
||||
{ group | items = List.filter filterItem group.items }
|
||||
in
|
||||
{ list | groups = List.map filterGroup list.groups }
|
||||
|
@ -276,7 +276,7 @@ type Msg
|
||||
| ItemModalCancelled
|
||||
| RequestDelete
|
||||
| SaveResp (Result Http.Error BasicResult)
|
||||
| DeleteResp (Result Http.Error BasicResult)
|
||||
| DeleteResp String (Result Http.Error BasicResult)
|
||||
| GetItemResp (Result Http.Error ItemDetail)
|
||||
| GetProposalResp (Result Http.Error ItemProposals)
|
||||
| RemoveDueDate
|
||||
@ -352,22 +352,23 @@ type alias UpdateResult =
|
||||
, cmd : Cmd Msg
|
||||
, sub : Sub Msg
|
||||
, linkTarget : LinkTarget
|
||||
, removedItem : Maybe String
|
||||
}
|
||||
|
||||
|
||||
resultModel : Model -> UpdateResult
|
||||
resultModel model =
|
||||
UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone
|
||||
UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone Nothing
|
||||
|
||||
|
||||
resultModelCmd : ( Model, Cmd Msg ) -> UpdateResult
|
||||
resultModelCmd ( model, cmd ) =
|
||||
UpdateResult model cmd Sub.none Comp.LinkTarget.LinkNone
|
||||
UpdateResult model cmd Sub.none Comp.LinkTarget.LinkNone Nothing
|
||||
|
||||
|
||||
resultModelCmdSub : ( Model, Cmd Msg, Sub Msg ) -> UpdateResult
|
||||
resultModelCmdSub ( model, cmd, sub ) =
|
||||
UpdateResult model cmd sub Comp.LinkTarget.LinkNone
|
||||
UpdateResult model cmd sub Comp.LinkTarget.LinkNone Nothing
|
||||
|
||||
|
||||
personMatchesOrg : Model -> Bool
|
||||
|
@ -279,6 +279,7 @@ update key flags inav settings msg model =
|
||||
, res9.sub
|
||||
]
|
||||
, linkTarget = Comp.LinkTarget.LinkNone
|
||||
, removedItem = Nothing
|
||||
}
|
||||
|
||||
SetActiveAttachment pos ->
|
||||
@ -560,7 +561,7 @@ update key flags inav settings msg model =
|
||||
DeleteItemConfirmed ->
|
||||
let
|
||||
cmd =
|
||||
Api.deleteItem flags model.item.id DeleteResp
|
||||
Api.deleteItem flags model.item.id (DeleteResp model.item.id)
|
||||
in
|
||||
resultModelCmd ( { model | itemModal = Nothing }, cmd )
|
||||
|
||||
@ -677,6 +678,7 @@ update key flags inav settings msg model =
|
||||
, cmd = Cmd.batch [ res1.cmd, res2.cmd ]
|
||||
, sub = Sub.batch [ res1.sub, res2.sub ]
|
||||
, linkTarget = Comp.LinkTarget.LinkNone
|
||||
, removedItem = Nothing
|
||||
}
|
||||
|
||||
GetPersonResp (Err _) ->
|
||||
@ -720,19 +722,23 @@ update key flags inav settings msg model =
|
||||
SaveNameResp (Err _) ->
|
||||
resultModel { model | nameState = SaveFailed }
|
||||
|
||||
DeleteResp (Ok res) ->
|
||||
DeleteResp removedId (Ok res) ->
|
||||
if res.success then
|
||||
case inav.next of
|
||||
Just id ->
|
||||
resultModelCmd ( model, Page.set key (ItemDetailPage id) )
|
||||
let
|
||||
result_ =
|
||||
case inav.next of
|
||||
Just id ->
|
||||
resultModelCmd ( model, Page.set key (ItemDetailPage id) )
|
||||
|
||||
Nothing ->
|
||||
resultModelCmd ( model, Page.set key HomePage )
|
||||
Nothing ->
|
||||
resultModelCmd ( model, Page.set key HomePage )
|
||||
in
|
||||
{ result_ | removedItem = Just removedId }
|
||||
|
||||
else
|
||||
resultModel model
|
||||
|
||||
DeleteResp (Err _) ->
|
||||
DeleteResp _ (Err _) ->
|
||||
resultModel model
|
||||
|
||||
GetItemResp (Ok item) ->
|
||||
@ -1421,6 +1427,7 @@ update key flags inav settings msg model =
|
||||
, cmd = Cmd.none
|
||||
, sub = Sub.none
|
||||
, linkTarget = lt
|
||||
, removedItem = Nothing
|
||||
}
|
||||
|
||||
CustomFieldMsg lm ->
|
||||
@ -1747,6 +1754,7 @@ withSub ( m, c ) =
|
||||
m.customFieldThrottle
|
||||
]
|
||||
, linkTarget = Comp.LinkTarget.LinkNone
|
||||
, removedItem = Nothing
|
||||
}
|
||||
|
||||
|
||||
|
@ -201,6 +201,7 @@ type Msg
|
||||
| RequestReprocessSelected
|
||||
| ReprocessSelectedConfirmed
|
||||
| ClientSettingsSaveResp UiSettings (Result Http.Error BasicResult)
|
||||
| RemoveItem String
|
||||
|
||||
|
||||
type SearchType
|
||||
|
@ -652,6 +652,9 @@ update mId key flags settings msg model =
|
||||
KeyUpPowerSearchbarMsg _ ->
|
||||
withSub ( model, Cmd.none )
|
||||
|
||||
RemoveItem id ->
|
||||
update mId key flags settings (ItemCardListMsg (Comp.ItemCardList.RemoveItem id)) model
|
||||
|
||||
|
||||
|
||||
--- Helpers
|
||||
|
@ -44,4 +44,5 @@ type alias UpdateResult =
|
||||
, cmd : Cmd Msg
|
||||
, sub : Sub Msg
|
||||
, linkTarget : LinkTarget
|
||||
, removedItem : Maybe String
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ update key flags inav settings msg model =
|
||||
]
|
||||
, sub = Sub.map ItemDetailMsg result.sub
|
||||
, linkTarget = result.linkTarget
|
||||
, removedItem = result.removedItem
|
||||
}
|
||||
|
||||
ItemDetailMsg lmsg ->
|
||||
@ -65,6 +66,7 @@ update key flags inav settings msg model =
|
||||
, cmd = Cmd.batch [ pageSwitch, Cmd.map ItemDetailMsg result.cmd ]
|
||||
, sub = Sub.map ItemDetailMsg result.sub
|
||||
, linkTarget = result.linkTarget
|
||||
, removedItem = result.removedItem
|
||||
}
|
||||
|
||||
ItemResp (Ok item) ->
|
||||
@ -75,10 +77,10 @@ update key flags inav settings msg model =
|
||||
update key flags inav settings (ItemDetailMsg lmsg) model
|
||||
|
||||
ItemResp (Err _) ->
|
||||
UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone
|
||||
UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone Nothing
|
||||
|
||||
ScrollResult _ ->
|
||||
UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone
|
||||
UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone Nothing
|
||||
|
||||
UiSettingsUpdated ->
|
||||
let
|
||||
|
Loading…
x
Reference in New Issue
Block a user