module Matterhorn.Draw.ChannelListWindow
( drawChannelListWindow
)
where
import Prelude ()
import Matterhorn.Prelude
import Brick
import qualified Data.Text as T
import Text.Wrap ( defaultWrapSettings, preserveIndentation )
import Network.Mattermost.Types
import Network.Mattermost.Lenses
import Matterhorn.Draw.ListWindow ( drawListWindow, WindowPosition(..) )
import Matterhorn.Types
import Matterhorn.Types.Common ( sanitizeUserText )
import Matterhorn.Themes
drawChannelListWindow :: ChatState -> TeamId -> Widget Name
drawChannelListWindow :: ChatState -> TeamId -> Widget Name
drawChannelListWindow ChatState
st TeamId
tId =
let window :: Widget Name
window = ListWindowState Channel ChannelSearchScope
-> (ChannelSearchScope -> Widget Name)
-> (ChannelSearchScope -> Widget Name)
-> (ChannelSearchScope -> Widget Name)
-> (Bool -> Channel -> Widget Name)
-> Maybe (Widget Name)
-> WindowPosition
-> Int
-> Widget Name
forall a b.
ListWindowState a b
-> (b -> Widget Name)
-> (b -> Widget Name)
-> (b -> Widget Name)
-> (Bool -> a -> Widget Name)
-> Maybe (Widget Name)
-> WindowPosition
-> Int
-> Widget Name
drawListWindow (ChatState
stChatState
-> Getting
(ListWindowState Channel ChannelSearchScope)
ChatState
(ListWindowState Channel ChannelSearchScope)
-> ListWindowState Channel ChannelSearchScope
forall s a. s -> Getting a s a -> a
^.TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState
-> Const (ListWindowState Channel ChannelSearchScope) TeamState)
-> ChatState
-> Const (ListWindowState Channel ChannelSearchScope) ChatState)
-> ((ListWindowState Channel ChannelSearchScope
-> Const
(ListWindowState Channel ChannelSearchScope)
(ListWindowState Channel ChannelSearchScope))
-> TeamState
-> Const (ListWindowState Channel ChannelSearchScope) TeamState)
-> Getting
(ListWindowState Channel ChannelSearchScope)
ChatState
(ListWindowState Channel ChannelSearchScope)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ListWindowState Channel ChannelSearchScope
-> Const
(ListWindowState Channel ChannelSearchScope)
(ListWindowState Channel ChannelSearchScope))
-> TeamState
-> Const (ListWindowState Channel ChannelSearchScope) TeamState
Lens' TeamState (ListWindowState Channel ChannelSearchScope)
tsChannelListWindow) ChannelSearchScope -> Widget Name
channelSearchScopeHeader
ChannelSearchScope -> Widget Name
channelSearchScopeNoResults ChannelSearchScope -> Widget Name
channelSearchScopePrompt
Bool -> Channel -> Widget Name
renderChannel
Maybe (Widget Name)
forall a. Maybe a
Nothing
WindowPosition
WindowCenter
Int
80
in Widget Name -> Widget Name
forall n. Widget n -> Widget n
joinBorders Widget Name
window
channelSearchScopePrompt :: ChannelSearchScope -> Widget Name
channelSearchScopePrompt :: ChannelSearchScope -> Widget Name
channelSearchScopePrompt ChannelSearchScope
scope =
Text -> Widget Name
forall n. Text -> Widget n
txt (Text -> Widget Name) -> Text -> Widget Name
forall a b. (a -> b) -> a -> b
$ case ChannelSearchScope
scope of
ChannelSearchScope
AllChannels -> Text
"Search channels:"
channelSearchScopeNoResults :: ChannelSearchScope -> Widget Name
channelSearchScopeNoResults :: ChannelSearchScope -> Widget Name
channelSearchScopeNoResults ChannelSearchScope
scope =
Text -> Widget Name
forall n. Text -> Widget n
txt (Text -> Widget Name) -> Text -> Widget Name
forall a b. (a -> b) -> a -> b
$ case ChannelSearchScope
scope of
ChannelSearchScope
AllChannels -> Text
"No matching channels found."
channelSearchScopeHeader :: ChannelSearchScope -> Widget Name
ChannelSearchScope
scope =
AttrName -> Widget Name -> Widget Name
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
clientEmphAttr (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$ Text -> Widget Name
forall n. Text -> Widget n
txt (Text -> Widget Name) -> Text -> Widget Name
forall a b. (a -> b) -> a -> b
$ case ChannelSearchScope
scope of
ChannelSearchScope
AllChannels -> Text
"Join a Channel"
renderChannel :: Bool -> Channel -> Widget Name
renderChannel :: Bool -> Channel -> Widget Name
renderChannel Bool
_ Channel
chan =
let baseStr :: Text
baseStr = (UserText -> Text
sanitizeUserText (UserText -> Text) -> UserText -> Text
forall a b. (a -> b) -> a -> b
$ Channel
chanChannel -> Getting UserText Channel UserText -> UserText
forall s a. s -> Getting a s a -> a
^.Getting UserText Channel UserText
Lens' Channel UserText
channelDisplayNameL) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text
" (" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (UserText -> Text
sanitizeUserText (UserText -> Text) -> UserText -> Text
forall a b. (a -> b) -> a -> b
$ Channel
chanChannel -> Getting UserText Channel UserText -> UserText
forall s a. s -> Getting a s a -> a
^.Getting UserText Channel UserText
Lens' Channel UserText
channelNameL) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
")"
s :: Text
s = Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (Text -> Text
T.strip (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ UserText -> Text
sanitizeUserText (UserText -> Text) -> UserText -> Text
forall a b. (a -> b) -> a -> b
$ Channel
chanChannel -> Getting UserText Channel UserText -> UserText
forall s a. s -> Getting a s a -> a
^.Getting UserText Channel UserText
Lens' Channel UserText
channelPurposeL)
in (Int -> Widget Name -> Widget Name
forall n. Int -> Widget n -> Widget n
vLimit Int
1 (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$ Padding -> Widget Name -> Widget Name
forall n. Padding -> Widget n -> Widget n
padRight Padding
Max (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$ AttrName -> Widget Name -> Widget Name
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
clientEmphAttr (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$ Text -> Widget Name
forall n. Text -> Widget n
txt Text
baseStr) Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<=>
(Int -> Widget Name -> Widget Name
forall n. Int -> Widget n -> Widget n
vLimit Int
1 (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$ WrapSettings -> Text -> Widget Name
forall n. WrapSettings -> Text -> Widget n
txtWrapWith (WrapSettings
defaultWrapSettings { preserveIndentation = True }) Text
s)