Use parent model for Alert and Confirm modals (#268)

This commit is contained in:
Francisco Vallarino 2023-05-08 21:37:43 -03:00 committed by GitHub
parent fb675f9128
commit a36492cb73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 17 deletions

View File

@ -101,27 +101,27 @@ instance CmbCloseCaption AlertCfg where
-- | Creates an alert dialog with the provided content.
alert
:: (WidgetModel s, WidgetEvent e)
:: (CompositeModel s, WidgetEvent e)
=> e -- ^ The event to raise when the dialog is closed.
-> WidgetNode () e -- ^ The content to display in the dialog.
-> WidgetNode s e -- ^ The content to display in the dialog.
-> WidgetNode s e -- ^ The created dialog.
alert evt dialogBody = alert_ evt def dialogBody
-- | Creates an alert dialog with the provided content. Accepts config.
alert_
:: (WidgetModel s, WidgetEvent e)
:: (CompositeModel s, WidgetEvent e)
=> e -- ^ The event to raise when the dialog is closed.
-> [AlertCfg] -- ^ The config options for the dialog.
-> WidgetNode () e -- ^ The content to display in the dialog.
-> WidgetNode s e -- ^ The content to display in the dialog.
-> WidgetNode s e -- ^ The created dialog.
alert_ evt configs dialogBody = newNode where
config = mconcat configs
createUI = buildUI (const dialogBody) evt config
newNode = compositeD_ "alert" (WidgetValue ()) createUI handleEvent []
newNode = compositeD_ "alert" (WidgetLens id) createUI handleEvent []
-- | Creates an alert dialog with a text message as content.
alertMsg
:: (WidgetModel s, WidgetEvent e)
:: (CompositeModel s, WidgetEvent e)
=> Text -- ^ The message to display.
-> e -- ^ The event to raise when the dialog is closed.
-> WidgetNode s e -- ^ The created dialog.
@ -129,7 +129,7 @@ alertMsg message evt = alertMsg_ message evt def
-- | Creates an alert dialog with a text message as content. Accepts config.
alertMsg_
:: (WidgetModel s, WidgetEvent e)
:: (CompositeModel s, WidgetEvent e)
=> Text -- ^ The message to display.
-> e -- ^ The event to raise when the dialog is closed.
-> [AlertCfg] -- ^ The config options for the dialog.
@ -142,7 +142,7 @@ alertMsg_ message evt configs = newNode where
newNode = compositeD_ "alert" (WidgetValue ()) createUI handleEvent []
buildUI
:: (WidgetModel s, WidgetEvent ep)
:: (CompositeModel s, WidgetEvent ep)
=> (WidgetEnv s ep -> WidgetNode s ep)
-> ep
-> AlertCfg

View File

@ -124,31 +124,31 @@ newtype InnerConfirmEvt e
-- | Creates a confirm dialog with the provided content.
confirm
:: (WidgetModel s, WidgetEvent e)
:: (CompositeModel s, WidgetEvent e)
=> e -- ^ The accept button event.
-> e -- ^ The cancel button event.
-> WidgetNode () (InnerConfirmEvt e) -- ^ Content to display in the dialog.
-> WidgetNode s (InnerConfirmEvt e) -- ^ Content to display in the dialog.
-> WidgetNode s e -- ^ The created dialog.
confirm acceptEvt cancelEvt dialogBody = newNode where
newNode = confirm_ acceptEvt cancelEvt def dialogBody
-- | Creates a confirm dialog with the provided content. Accepts config.
confirm_
:: (WidgetModel s, WidgetEvent e)
:: (CompositeModel s, WidgetEvent e)
=> e -- ^ The accept button event.
-> e -- ^ The cancel button event.
-> [ConfirmCfg] -- ^ The config options for the dialog.
-> WidgetNode () (InnerConfirmEvt e) -- ^ Content to display in the dialog.
-> WidgetNode s (InnerConfirmEvt e) -- ^ Content to display in the dialog.
-> WidgetNode s e -- ^ The created dialog.
confirm_ acceptEvt cancelEvt configs dialogBody = newNode where
config = mconcat configs
createUI = buildUI (const dialogBody) acceptEvt cancelEvt config
compCfg = [compositeMergeReqs mergeReqs]
newNode = compositeD_ "confirm" (WidgetValue ()) createUI handleEvent compCfg
newNode = compositeD_ "confirm" (WidgetLens id) createUI handleEvent compCfg
-- | Creates a confirm dialog with a text message as content.
confirmMsg
:: (WidgetModel s, WidgetEvent e)
:: (CompositeModel s, WidgetEvent e)
=> Text -- ^ The message to display in the dialog.
-> e -- ^ The accept button event.
-> e -- ^ The cancel button event.
@ -157,7 +157,7 @@ confirmMsg msg acceptEvt cancelEvt = confirmMsg_ msg acceptEvt cancelEvt def
-- | Creates a confirm dialog with a text message as content. Accepts config.
confirmMsg_
:: (WidgetModel s, WidgetEvent e)
:: (CompositeModel s, WidgetEvent e)
=> Text -- ^ The message to display in the dialog.
-> e -- ^ The accept button event.
-> e -- ^ The cancel button event.
@ -169,7 +169,7 @@ confirmMsg_ message acceptEvt cancelEvt configs = newNode where
& L.info . L.style .~ collectTheme wenv L.dialogMsgBodyStyle
createUI = buildUI dialogBody acceptEvt cancelEvt config
compCfg = [compositeMergeReqs mergeReqs]
newNode = compositeD_ "confirm" (WidgetValue ()) createUI handleEvent compCfg
newNode = compositeD_ "confirm" (WidgetLens id) createUI handleEvent compCfg
mergeReqs :: MergeReqsHandler s e sp
mergeReqs wenv newNode oldNode parentModel oldModel model = reqs where
@ -180,7 +180,7 @@ mergeReqs wenv newNode oldNode parentModel oldModel model = reqs where
| otherwise = []
buildUI
:: (WidgetModel s, WidgetEvent ep)
:: (CompositeModel s, WidgetEvent ep)
=> (WidgetEnv s (InnerConfirmEvt ep) -> WidgetNode s (InnerConfirmEvt ep))
-> ep
-> ep