rvv041 - Address Book - Edit Address Book Description working

- Delete Address Book Entry working
This commit is contained in:
Rene V. Vergara A. 2024-09-08 17:21:17 -04:00
parent 185738eccc
commit 06b2cd9222

View file

@ -118,12 +118,15 @@ data AppEvent
| CheckValidAddress !T.Text | CheckValidAddress !T.Text
| CheckValidDescrip !T.Text | CheckValidDescrip !T.Text
| SaveNewABEntry | SaveNewABEntry
| SaveABDescription !T.Text
| UpdateABEntry !T.Text !T.Text | UpdateABEntry !T.Text !T.Text
| CloseUpdABEntry | CloseUpdABEntry
| ShowMessage !T.Text | ShowMessage !T.Text
| ShowABAddress !T.Text !T.Text | ShowABAddress !T.Text !T.Text
| CloseShowABAddress | CloseShowABAddress
| CopyABAdress !T.Text | CopyABAdress !T.Text
| DeleteABEntry !T.Text
| UpdateABDescrip !T.Text !T.Text
deriving (Eq, Show) deriving (Eq, Show)
data AppModel = AppModel data AppModel = AppModel
@ -887,8 +890,8 @@ buildUI wenv model = widgetTree
, spacer , spacer
, hstack , hstack
[ filler [ filler
, button "Save" NotImplemented , button "Save" (UpdateABDescrip abd aba) `nodeEnabled`
-- ((model ^. abAddressValid) && (model ^. abDescripValid)) (model ^. abDescripValid)
, spacer , spacer
, button "Cancel" CloseUpdABEntry `nodeEnabled` True , button "Cancel" CloseUpdABEntry `nodeEnabled` True
, filler , filler
@ -921,7 +924,7 @@ buildUI wenv model = widgetTree
, spacer , spacer
, button "Copy Address" $ CopyABAdress aba , button "Copy Address" $ CopyABAdress aba
, spacer , spacer
, button "Delete Entry" $ NotImplemented , button "Delete Entry" $ DeleteABEntry aba
, filler , filler
] ]
] ]
@ -1292,6 +1295,14 @@ handleEvent wenv node model evt =
, setClipboardData $ ClipboardText a , setClipboardData $ ClipboardText a
, Event $ ShowMessage "Address copied!!" , Event $ ShowMessage "Address copied!!"
] ]
DeleteABEntry a ->
[ Task $ deleteAdrBook (model ^. configuration) a
, Model $ model & abdescrip .~ "" & abaddress .~ "" & showABAddress .~ False
, Task $ do
dbPool <- runNoLoggingT $ initPool $ c_dbPath $ model ^. configuration
abList <- getAdrBook dbPool $ model ^. network
return $ LoadAbList abList
]
ShowMessage a -> [Model $ model & msgAB ?~ a & menuPopup .~ False] ShowMessage a -> [Model $ model & msgAB ?~ a & menuPopup .~ False]
NotImplemented -> NotImplemented ->
[ Model $ [ Model $
@ -1299,6 +1310,22 @@ handleEvent wenv node model evt =
] ]
CloseMsgAB -> [Model $ model & msgAB .~ Nothing & inError .~ False] CloseMsgAB -> [Model $ model & msgAB .~ Nothing & inError .~ False]
LoadAbList a -> [Model $ model & abaddressList .~ a] LoadAbList a -> [Model $ model & abaddressList .~ a]
UpdateABDescrip d a ->
[ Task $
updAddrBookDescrip
(model ^. configuration)
d
a
, Model $
model & abdescrip .~ ""
& abaddress .~ ""
& updateABAddress .~ False
& showABAddress .~ False
, Task $ do
dbPool <- runNoLoggingT $ initPool $ c_dbPath $ model ^. configuration
abList <- getAdrBook dbPool $ model ^. network
return $ LoadAbList abList
]
where where
currentWallet = currentWallet =
if null (model ^. wallets) if null (model ^. wallets)
@ -1394,10 +1421,25 @@ handleEvent wenv node model evt =
pool <- runNoLoggingT $ initPool $ c_dbPath config pool <- runNoLoggingT $ initPool $ c_dbPath config
res <- liftIO $ saveAdrsInAdrBook pool $ AddressBook n d a res <- liftIO $ saveAdrsInAdrBook pool $ AddressBook n d a
case res of case res of
Nothing -> return $ ShowMessage "Error saving the AddressBook entry..." Nothing -> return $ ShowMessage "Error saving AddressBook entry..."
Just _ -> return $ ShowMessage "New Address Book entry added!!" Just _ -> return $ ShowMessage "New Address Book entry added!!"
-- | -- |
-- | Address Book -> save new entry into database
-- |
deleteAdrBook :: Config -> T.Text -> IO AppEvent
deleteAdrBook config a = do
pool <- runNoLoggingT $ initPool $ c_dbPath config
res <- liftIO $ deleteAdrsFromAB pool a
return $ ShowMessage "Address Book entry deleted!!"
-- |
-- | Address Book -> save new entry into database
-- |
updAddrBookDescrip :: Config -> T.Text -> T.Text -> IO AppEvent
updAddrBookDescrip config d a = do
pool <- runNoLoggingT $ initPool $ c_dbPath config
res <- liftIO $ updateAdrsInAdrBook pool d a a
return $ ShowMessage "Address Book entry updated!!"
scanZebra :: T.Text -> T.Text -> Int -> (AppEvent -> IO ()) -> IO () scanZebra :: T.Text -> T.Text -> Int -> (AppEvent -> IO ()) -> IO ()
scanZebra dbPath zHost zPort sendMsg = do scanZebra dbPath zHost zPort sendMsg = do
_ <- liftIO $ initDb dbPath _ <- liftIO $ initDb dbPath