<commit_before>{-# LANGUAGE OverloadedStrings #-}
module Draw.JoinChannel
    ( drawJoinChannel
    )
where

import Brick
import Brick.Widgets.List
import Brick.Widgets.Center
import Brick.Widgets.Border
import Data.Monoid ((<>))
import Lens.Micro.Platform ((^.))

import Network.Mattermost (Channel)
import Network.Mattermost.Lenses (channelDisplayNameL, channelNameL)

import Types
import Themes
import Draw.Main

drawJoinChannel :: ChatState -> [Widget Name]
drawJoinChannel st = joinChannelBox st : (forceAttr "invalid" <$> drawMain st)

joinChannelBox :: ChatState -> Widget Name
joinChannelBox st =
    let chList = case st^.csJoinChannelList of
          Nothing -> center $ withDefAttr dialogEmphAttr $ txt "[Loading channel list]"
          Just chanList -> renderList renderJoinListItem True chanList
        highlight = withDefAttr dialogEmphAttr
    in centerLayer $
       vLimit 20 $
       hLimit 60 $
       withDefAttr dialogAttr $
       borderWithLabel (txt "Join Channel") $
       vBox [ chList
            , padTop (Pad 1) $
              hCenter $ txt "Use " <+> (highlight $ txt "arrow keys") <+> txt " and " <+>
                        (highlight $ txt "Enter") <+> txt " to select a team"
            , hCenter $ txt "to join or press " <+> (highlight $ txt "Esc") <+> txt " to cancel."
            ]

renderJoinListItem :: Bool -> Channel -> Widget Name
renderJoinListItem _ chan =
    padRight Max $ txt $ chan^.channelNameL <> " (" <> chan^.channelDisplayNameL <> ")"<commit_msg>Join channel: show channel cursor extent<commit_after>{-# LANGUAGE OverloadedStrings #-}
module Draw.JoinChannel
    ( drawJoinChannel
    )
where

import Brick
import Brick.Widgets.List
import Brick.Widgets.Center
import Brick.Widgets.Border
import Data.Monoid ((<>))
import Lens.Micro.Platform ((^.))
import qualified Data.Vector as V

import Network.Mattermost (Channel)
import Network.Mattermost.Lenses (channelDisplayNameL, channelNameL)

import Types
import Themes
import Draw.Main

drawJoinChannel :: ChatState -> [Widget Name]
drawJoinChannel st = joinChannelBox st : (forceAttr "invalid" <$> drawMain st)

joinChannelBox :: ChatState -> Widget Name
joinChannelBox st =
    let chList = case st^.csJoinChannelList of
          Nothing -> center $ withDefAttr dialogEmphAttr $ txt "[Loading channel list]"
          Just chanList -> renderList renderJoinListItem True chanList
        highlight = withDefAttr dialogEmphAttr
        cur = maybe 0 ((+1) . fst) (listSelectedElement =<< st^.csJoinChannelList)
        len = maybe 0 (\l -> V.length $ l^.listElementsL) $ st^.csJoinChannelList
    in centerLayer $
       vLimit 20 $
       hLimit 60 $
       withDefAttr dialogAttr $
       borderWithLabel (txt "Join Channel") $
       vBox [ chList
            , hBorderWithLabel (str $ (show cur) <> "/" <> (show len))
            , padTop (Pad 1) $
              hCenter $ txt "Use " <+> (highlight $ txt "arrow keys") <+> txt " and " <+>
                        (highlight $ txt "Enter") <+> txt " to select a team"
            , hCenter $ txt "to join or press " <+> (highlight $ txt "Esc") <+> txt " to cancel."
            ]

renderJoinListItem :: Bool -> Channel -> Widget Name
renderJoinListItem _ chan =
    padRight Max $ txt $ chan^.channelNameL <> " (" <> chan^.channelDisplayNameL <> ")"
{'fraction_non_alphanumeric': 0.1116812556595231, 'fraction_numerical': 0.00392393600965892, 'mean_word_length': 2.964114832535885, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4191918', 'n_tokens_mistral': 1011, 'n_tokens_neox': 957, 'n_words': 290}