module Matterhorn.Events.ChannelTopicWindow ( onEventChannelTopicWindow , channelTopicWindowMouseHandler ) where import Prelude () import Matterhorn.Prelude import Brick ( BrickEvent(VtyEvent, MouseDown) ) import Brick.Focus import Brick.Widgets.Edit ( handleEditorEvent, getEditContents ) import qualified Data.Text as T import Lens.Micro.Platform ( (%=) ) import qualified Graphics.Vty as Vty import Network.Mattermost.Types ( TeamId ) import Matterhorn.Types import Matterhorn.State.Channels ( setChannelTopic ) onEventChannelTopicWindow :: TeamId -> Vty.Event -> MH () onEventChannelTopicWindow :: TeamId -> Event -> MH () onEventChannelTopicWindow TeamId tId (Vty.EvKey (Vty.KChar Char '\t') []) = TeamId -> Lens' ChatState TeamState csTeam(TeamId tId)((TeamState -> Identity TeamState) -> ChatState -> Identity ChatState) -> ((FocusRing Name -> Identity (FocusRing Name)) -> TeamState -> Identity TeamState) -> (FocusRing Name -> Identity (FocusRing Name)) -> ChatState -> Identity ChatState forall b c a. (b -> c) -> (a -> b) -> a -> c .(ChannelTopicDialogState -> Identity ChannelTopicDialogState) -> TeamState -> Identity TeamState Lens' TeamState ChannelTopicDialogState tsChannelTopicDialog((ChannelTopicDialogState -> Identity ChannelTopicDialogState) -> TeamState -> Identity TeamState) -> ((FocusRing Name -> Identity (FocusRing Name)) -> ChannelTopicDialogState -> Identity ChannelTopicDialogState) -> (FocusRing Name -> Identity (FocusRing Name)) -> TeamState -> Identity TeamState forall b c a. (b -> c) -> (a -> b) -> a -> c .(FocusRing Name -> Identity (FocusRing Name)) -> ChannelTopicDialogState -> Identity ChannelTopicDialogState Lens' ChannelTopicDialogState (FocusRing Name) channelTopicDialogFocus ((FocusRing Name -> Identity (FocusRing Name)) -> ChatState -> Identity ChatState) -> (FocusRing Name -> FocusRing Name) -> MH () forall s (m :: * -> *) a b. MonadState s m => ASetter s s a b -> (a -> b) -> m () %= FocusRing Name -> FocusRing Name forall n. FocusRing n -> FocusRing n focusNext onEventChannelTopicWindow TeamId tId (Vty.EvKey Key Vty.KBackTab []) = TeamId -> Lens' ChatState TeamState csTeam(TeamId tId)((TeamState -> Identity TeamState) -> ChatState -> Identity ChatState) -> ((FocusRing Name -> Identity (FocusRing Name)) -> TeamState -> Identity TeamState) -> (FocusRing Name -> Identity (FocusRing Name)) -> ChatState -> Identity ChatState forall b c a. (b -> c) -> (a -> b) -> a -> c .(ChannelTopicDialogState -> Identity ChannelTopicDialogState) -> TeamState -> Identity TeamState Lens' TeamState ChannelTopicDialogState tsChannelTopicDialog((ChannelTopicDialogState -> Identity ChannelTopicDialogState) -> TeamState -> Identity TeamState) -> ((FocusRing Name -> Identity (FocusRing Name)) -> ChannelTopicDialogState -> Identity ChannelTopicDialogState) -> (FocusRing Name -> Identity (FocusRing Name)) -> TeamState -> Identity TeamState forall b c a. (b -> c) -> (a -> b) -> a -> c .(FocusRing Name -> Identity (FocusRing Name)) -> ChannelTopicDialogState -> Identity ChannelTopicDialogState Lens' ChannelTopicDialogState (FocusRing Name) channelTopicDialogFocus ((FocusRing Name -> Identity (FocusRing Name)) -> ChatState -> Identity ChatState) -> (FocusRing Name -> FocusRing Name) -> MH () forall s (m :: * -> *) a b. MonadState s m => ASetter s s a b -> (a -> b) -> m () %= FocusRing Name -> FocusRing Name forall n. FocusRing n -> FocusRing n focusPrev onEventChannelTopicWindow TeamId tId e :: Event e@(Vty.EvKey Key Vty.KEnter []) = do FocusRing Name f <- Getting (FocusRing Name) ChatState (FocusRing Name) -> MH (FocusRing Name) forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a use (TeamId -> Lens' ChatState TeamState csTeam(TeamId tId)((TeamState -> Const (FocusRing Name) TeamState) -> ChatState -> Const (FocusRing Name) ChatState) -> ((FocusRing Name -> Const (FocusRing Name) (FocusRing Name)) -> TeamState -> Const (FocusRing Name) TeamState) -> Getting (FocusRing Name) ChatState (FocusRing Name) forall b c a. (b -> c) -> (a -> b) -> a -> c .(ChannelTopicDialogState -> Const (FocusRing Name) ChannelTopicDialogState) -> TeamState -> Const (FocusRing Name) TeamState Lens' TeamState ChannelTopicDialogState tsChannelTopicDialog((ChannelTopicDialogState -> Const (FocusRing Name) ChannelTopicDialogState) -> TeamState -> Const (FocusRing Name) TeamState) -> ((FocusRing Name -> Const (FocusRing Name) (FocusRing Name)) -> ChannelTopicDialogState -> Const (FocusRing Name) ChannelTopicDialogState) -> (FocusRing Name -> Const (FocusRing Name) (FocusRing Name)) -> TeamState -> Const (FocusRing Name) TeamState forall b c a. (b -> c) -> (a -> b) -> a -> c .(FocusRing Name -> Const (FocusRing Name) (FocusRing Name)) -> ChannelTopicDialogState -> Const (FocusRing Name) ChannelTopicDialogState Lens' ChannelTopicDialogState (FocusRing Name) channelTopicDialogFocus) case FocusRing Name -> Maybe Name forall n. FocusRing n -> Maybe n focusGetCurrent FocusRing Name f of Just (ChannelTopicSaveButton {}) -> do TeamId -> MH () doSaveTopic TeamId tId Just (ChannelTopicEditor {}) -> Lens' ChatState (Editor Text Name) -> (BrickEvent Name Any -> EventM Name (Editor Text Name) ()) -> BrickEvent Name Any -> MH () forall b e. Lens' ChatState b -> (e -> EventM Name b ()) -> e -> MH () mhZoom (TeamId -> Lens' ChatState TeamState csTeam(TeamId tId)((TeamState -> f TeamState) -> ChatState -> f ChatState) -> ((Editor Text Name -> f (Editor Text Name)) -> TeamState -> f TeamState) -> (Editor Text Name -> f (Editor Text Name)) -> ChatState -> f ChatState forall b c a. (b -> c) -> (a -> b) -> a -> c .(ChannelTopicDialogState -> f ChannelTopicDialogState) -> TeamState -> f TeamState Lens' TeamState ChannelTopicDialogState tsChannelTopicDialog((ChannelTopicDialogState -> f ChannelTopicDialogState) -> TeamState -> f TeamState) -> ((Editor Text Name -> f (Editor Text Name)) -> ChannelTopicDialogState -> f ChannelTopicDialogState) -> (Editor Text Name -> f (Editor Text Name)) -> TeamState -> f TeamState forall b c a. (b -> c) -> (a -> b) -> a -> c .(Editor Text Name -> f (Editor Text Name)) -> ChannelTopicDialogState -> f ChannelTopicDialogState Lens' ChannelTopicDialogState (Editor Text Name) channelTopicDialogEditor) BrickEvent Name Any -> EventM Name (Editor Text Name) () forall n t e. (Eq n, DecodeUtf8 t, Eq t, GenericTextZipper t) => BrickEvent n e -> EventM n (Editor t n) () handleEditorEvent (Event -> BrickEvent Name Any forall n e. Event -> BrickEvent n e VtyEvent Event e) Just (ChannelTopicCancelButton {}) -> TeamId -> MH () doCancelTopicEdit TeamId tId Maybe Name _ -> TeamId -> MH () popMode TeamId tId onEventChannelTopicWindow TeamId tId (Vty.EvKey Key Vty.KEsc []) = do TeamId -> MH () popMode TeamId tId onEventChannelTopicWindow TeamId tId Event e = do FocusRing Name f <- Getting (FocusRing Name) ChatState (FocusRing Name) -> MH (FocusRing Name) forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a use (TeamId -> Lens' ChatState TeamState csTeam(TeamId tId)((TeamState -> Const (FocusRing Name) TeamState) -> ChatState -> Const (FocusRing Name) ChatState) -> ((FocusRing Name -> Const (FocusRing Name) (FocusRing Name)) -> TeamState -> Const (FocusRing Name) TeamState) -> Getting (FocusRing Name) ChatState (FocusRing Name) forall b c a. (b -> c) -> (a -> b) -> a -> c .(ChannelTopicDialogState -> Const (FocusRing Name) ChannelTopicDialogState) -> TeamState -> Const (FocusRing Name) TeamState Lens' TeamState ChannelTopicDialogState tsChannelTopicDialog((ChannelTopicDialogState -> Const (FocusRing Name) ChannelTopicDialogState) -> TeamState -> Const (FocusRing Name) TeamState) -> ((FocusRing Name -> Const (FocusRing Name) (FocusRing Name)) -> ChannelTopicDialogState -> Const (FocusRing Name) ChannelTopicDialogState) -> (FocusRing Name -> Const (FocusRing Name) (FocusRing Name)) -> TeamState -> Const (FocusRing Name) TeamState forall b c a. (b -> c) -> (a -> b) -> a -> c .(FocusRing Name -> Const (FocusRing Name) (FocusRing Name)) -> ChannelTopicDialogState -> Const (FocusRing Name) ChannelTopicDialogState Lens' ChannelTopicDialogState (FocusRing Name) channelTopicDialogFocus) case FocusRing Name -> Maybe Name forall n. FocusRing n -> Maybe n focusGetCurrent FocusRing Name f of Just (ChannelTopicEditor {}) -> Lens' ChatState (Editor Text Name) -> (BrickEvent Name Any -> EventM Name (Editor Text Name) ()) -> BrickEvent Name Any -> MH () forall b e. Lens' ChatState b -> (e -> EventM Name b ()) -> e -> MH () mhZoom (TeamId -> Lens' ChatState TeamState csTeam(TeamId tId)((TeamState -> f TeamState) -> ChatState -> f ChatState) -> ((Editor Text Name -> f (Editor Text Name)) -> TeamState -> f TeamState) -> (Editor Text Name -> f (Editor Text Name)) -> ChatState -> f ChatState forall b c a. (b -> c) -> (a -> b) -> a -> c .(ChannelTopicDialogState -> f ChannelTopicDialogState) -> TeamState -> f TeamState Lens' TeamState ChannelTopicDialogState tsChannelTopicDialog((ChannelTopicDialogState -> f ChannelTopicDialogState) -> TeamState -> f TeamState) -> ((Editor Text Name -> f (Editor Text Name)) -> ChannelTopicDialogState -> f ChannelTopicDialogState) -> (Editor Text Name -> f (Editor Text Name)) -> TeamState -> f TeamState forall b c a. (b -> c) -> (a -> b) -> a -> c .(Editor Text Name -> f (Editor Text Name)) -> ChannelTopicDialogState -> f ChannelTopicDialogState Lens' ChannelTopicDialogState (Editor Text Name) channelTopicDialogEditor) BrickEvent Name Any -> EventM Name (Editor Text Name) () forall n t e. (Eq n, DecodeUtf8 t, Eq t, GenericTextZipper t) => BrickEvent n e -> EventM n (Editor t n) () handleEditorEvent (Event -> BrickEvent Name Any forall n e. Event -> BrickEvent n e VtyEvent Event e) Maybe Name _ -> () -> MH () forall a. a -> MH a forall (m :: * -> *) a. Monad m => a -> m a return () channelTopicWindowMouseHandler :: TeamId -> BrickEvent Name MHEvent -> MH () channelTopicWindowMouseHandler :: TeamId -> BrickEvent Name MHEvent -> MH () channelTopicWindowMouseHandler TeamId tId (MouseDown (ChannelTopicSaveButton {}) Button _ [Modifier] _ Location _) = TeamId -> MH () doSaveTopic TeamId tId channelTopicWindowMouseHandler TeamId tId (MouseDown (ChannelTopicCancelButton {}) Button _ [Modifier] _ Location _) = TeamId -> MH () doCancelTopicEdit TeamId tId channelTopicWindowMouseHandler TeamId _ BrickEvent Name MHEvent _ = () -> MH () forall a. a -> MH a forall (m :: * -> *) a. Monad m => a -> m a return () doSaveTopic :: TeamId -> MH () doSaveTopic :: TeamId -> MH () doSaveTopic TeamId tId = do Editor Text Name ed <- Getting (Editor Text Name) ChatState (Editor Text Name) -> MH (Editor Text Name) forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a use (TeamId -> Lens' ChatState TeamState csTeam(TeamId tId)((TeamState -> Const (Editor Text Name) TeamState) -> ChatState -> Const (Editor Text Name) ChatState) -> ((Editor Text Name -> Const (Editor Text Name) (Editor Text Name)) -> TeamState -> Const (Editor Text Name) TeamState) -> Getting (Editor Text Name) ChatState (Editor Text Name) forall b c a. (b -> c) -> (a -> b) -> a -> c .(ChannelTopicDialogState -> Const (Editor Text Name) ChannelTopicDialogState) -> TeamState -> Const (Editor Text Name) TeamState Lens' TeamState ChannelTopicDialogState tsChannelTopicDialog((ChannelTopicDialogState -> Const (Editor Text Name) ChannelTopicDialogState) -> TeamState -> Const (Editor Text Name) TeamState) -> ((Editor Text Name -> Const (Editor Text Name) (Editor Text Name)) -> ChannelTopicDialogState -> Const (Editor Text Name) ChannelTopicDialogState) -> (Editor Text Name -> Const (Editor Text Name) (Editor Text Name)) -> TeamState -> Const (Editor Text Name) TeamState forall b c a. (b -> c) -> (a -> b) -> a -> c .(Editor Text Name -> Const (Editor Text Name) (Editor Text Name)) -> ChannelTopicDialogState -> Const (Editor Text Name) ChannelTopicDialogState Lens' ChannelTopicDialogState (Editor Text Name) channelTopicDialogEditor) let topic :: Text topic = [Text] -> Text T.unlines ([Text] -> Text) -> [Text] -> Text forall a b. (a -> b) -> a -> b $ Editor Text Name -> [Text] forall t n. Monoid t => Editor t n -> [t] getEditContents Editor Text Name ed TeamId -> Text -> MH () setChannelTopic TeamId tId Text topic TeamId -> MH () popMode TeamId tId doCancelTopicEdit :: TeamId -> MH () doCancelTopicEdit :: TeamId -> MH () doCancelTopicEdit TeamId tId = TeamId -> MH () popMode TeamId tId