rvv041 - AddressBook functionality

Delete addressbook entry in progress
This commit is contained in:
Rene V. Vergara A. 2024-05-31 22:18:26 -04:00
parent bd1f4e3a5c
commit 4cb4f401a3

View file

@ -153,6 +153,7 @@ data DialogType
| AdrBook | AdrBook
| AdrBookForm | AdrBookForm
| AdrBookUpdForm | AdrBookUpdForm
| AdrBookDelForm
data DisplayType data DisplayType
= AddrDisplay = AddrDisplay
@ -403,6 +404,14 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s]
(renderForm (st ^. abForm) <=> (renderForm (st ^. abForm) <=>
C.hCenter C.hCenter
(hBox [capCommand "" " Save", capCommand3 "" "<Esc>" " Cancel"])) (hBox [capCommand "" " Save", capCommand3 "" "<Esc>" " Cancel"]))
-- Address Book edit/update entry form
AdrBookDelForm ->
D.renderDialog
(D.dialog (Just $ str " Delete Address Book Entry ") Nothing 50)
(renderForm (st ^. abForm) <=>
C.hCenter
(hBox [capCommand "" " Delete", capCommand3 "" "<Esc>" " Cancel"]))
splashDialog :: State -> Widget Name splashDialog :: State -> Widget Name
splashDialog st = splashDialog st =
@ -783,6 +792,7 @@ appEvent (BT.AppEvent t) = do
AdrBook -> return () AdrBook -> return ()
AdrBookForm -> return () AdrBookForm -> return ()
AdrBookUpdForm -> return () AdrBookUpdForm -> return ()
AdrBookDelForm -> return ()
Blank -> do Blank -> do
if s ^. timer == 90 if s ^. timer == 90
then do then do
@ -1057,10 +1067,19 @@ appEvent (BT.VtyEvent e) = do
set abForm $ set abForm $
mkNewABForm (AdrBookEntry (addressBookDescrip (entityVal a)) (addressBookAddress (entityVal a))) mkNewABForm (AdrBookEntry (addressBookDescrip (entityVal a)) (addressBookAddress (entityVal a)))
BT.modify $ set dialogBox AdrBookUpdForm BT.modify $ set dialogBox AdrBookUpdForm
_ -> do _ -> do
BT.modify $ set dialogBox Blank BT.modify $ set dialogBox Blank
-- Delete an entry from Address Book
V.EvKey (V.KChar 'd') [] -> do
case L.listSelectedElement $ s ^. abaddresses of
Just (_, a) -> do
BT.modify $ set abCurAdrs (addressBookAddress (entityVal a))
BT.modify $
set abForm $
mkNewABForm (AdrBookEntry (addressBookDescrip (entityVal a)) (addressBookAddress (entityVal a)))
BT.modify $ set dialogBox AdrBookDelForm
_ -> do
BT.modify $ set dialogBox Blank
-- Create a new entry in Address Book -- Create a new entry in Address Book
V.EvKey (V.KChar 'n') [] -> do V.EvKey (V.KChar 'n') [] -> do
BT.modify $ set abForm $ mkNewABForm (AdrBookEntry "" "") BT.modify $ set abForm $ mkNewABForm (AdrBookEntry "" "")
@ -1115,8 +1134,9 @@ appEvent (BT.VtyEvent e) = do
BT.modify $ set msg ("AddressBook entry modified!!\n" ++ T.unpack (fs ^.address)) BT.modify $ set msg ("AddressBook entry modified!!\n" ++ T.unpack (fs ^.address))
BT.modify $ set displayBox MsgDisplay BT.modify $ set displayBox MsgDisplay
-- case end -- case end
abookList <- liftIO $ getAdrBook pool (s ^. network) -- BT.modify $ set dialogBox AdrBook
let abL = L.listReplace (Vec.fromList abookList) (Just 0) (s ^. abaddresses) s' <- liftIO $ refreshAddressBook s
BT.put s'
BT.modify $ set dialogBox AdrBook BT.modify $ set dialogBox AdrBook
else do else do
BT.modify $ set msg "Invalid or missing data!!: " BT.modify $ set msg "Invalid or missing data!!: "
@ -1129,6 +1149,12 @@ appEvent (BT.VtyEvent e) = do
setFieldValid setFieldValid
(isRecipientValid (fs ^. address)) (isRecipientValid (fs ^. address))
AddressField AddressField
-- Process new address book entry
AdrBookDelForm -> do
case e of
V.EvKey V.KEsc [] -> BT.modify $ set dialogBox AdrBook
V.EvKey V.KEnter [] -> BT.modify $ set dialogBox AdrBook
ev -> BT.modify $ set dialogBox AdrBookDelForm
Blank -> do Blank -> do
case e of case e of
V.EvKey (V.KChar '\t') [] -> focusRing %= F.focusNext V.EvKey (V.KChar '\t') [] -> focusRing %= F.focusNext