Skip to content

Commit

Permalink
Use parent model for Alert and Confirm modals (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
fjvallarino authored May 9, 2023
1 parent fb675f9 commit a36492c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions src/Monomer/Widgets/Containers/Alert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,35 +101,35 @@ 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.
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.
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/Monomer/Widgets/Containers/Confirm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a36492c

Please sign in to comment.