@@ -38,7 +38,7 @@ import Brick (
3838 (<=>) ,
3939 )
4040import Brick qualified
41- import Brick.Widgets.Border (border )
41+ import Brick.Widgets.Border (border , hBorderWithLabel )
4242import Brick.Widgets.Border.Style (borderStyleFromChar , unicode )
4343import Brick.Widgets.List (
4444 List ,
@@ -53,9 +53,10 @@ import Brick.Widgets.List (
5353import Control.Monad (void )
5454import Data.Function ((&) )
5555import Data.Generics.Labels ()
56- import Data.Maybe ( isJust )
56+ import Data.Map.Strict qualified as Map
5757import Data.Text (Text )
5858import Data.Text qualified as Text
59+ import Data.Vector (Vector )
5960import Data.Vector qualified as Vector
6061import GHC.Generics (Generic )
6162import Graphics.Vty (
@@ -82,25 +83,44 @@ import Lens.Micro.Mtl (preuse, use, (.=))
8283import RON.Storage.FS (runStorage )
8384import RON.Storage.FS qualified as StorageFS
8485
85- import FF (fromRgaM , getDataDir , loadAllNotes , noDataDirectoryMessage )
86+ import FF (
87+ defaultNoteFilter ,
88+ fromRgaM ,
89+ getDataDir ,
90+ getUtcToday ,
91+ loadAllNotes ,
92+ noDataDirectoryMessage ,
93+ viewTaskSamples ,
94+ )
8695import FF.Config (loadConfig )
96+ import FF.Config qualified
8797import FF.Types (
8898 Entity (Entity ),
89- EntityDoc ,
99+ EntityView ,
100+ ModeMap ,
90101 Note (Note ),
91- NoteStatus (TaskStatus ),
92- Status (Active ),
102+ NoteSample ,
103+ Sample (Sample ),
104+ TaskMode ,
105+ View (NoteView ),
93106 )
94107import FF.Types qualified
108+ import FF.UI (sampleLabel )
95109
96- -- | Brick widget names
110+ -- | Widget names
97111data WN
98112 = NoteList
99113 | OpenNoteViewport
100114 deriving (Eq , Ord , Show )
101115
102116data Model = Model
103- { visibleNotes :: List WN (EntityDoc Note )
117+ { visibleNotes ::
118+ List
119+ WN
120+ ( Either
121+ TaskMode -- section title
122+ (EntityView Note ) -- item
123+ )
104124 , isNoteOpen :: Bool
105125 }
106126 deriving (Generic )
@@ -119,18 +139,29 @@ main = do
119139 dataDirM <- getDataDir cfg
120140 handleM <- traverse StorageFS. newHandle dataDirM
121141 handle <- handleM `orElse` fail noDataDirectoryMessage
122- allNotes <- runStorage handle loadAllNotes
123- let filteredNotes = filter (isNoteActive . (. entityVal)) allNotes
142+ today <- getUtcToday
143+ let limit = Nothing
144+ samples <-
145+ runStorage handle do
146+ allNotes <- loadAllNotes
147+ viewTaskSamples
148+ defaultNoteFilter
149+ cfg. ui
150+ limit
151+ today
152+ allNotes
124153 let initialModel =
125154 Model
126155 { visibleNotes =
127- list NoteList (Vector. fromList filteredNotes ) listItemHeight
156+ list NoteList (notesToModel samples ) listItemHeight
128157 , isNoteOpen = False
129158 }
130159 void $ defaultMain app initialModel
131160
132- isNoteActive :: Note -> Bool
133- isNoteActive Note {note_status} = note_status == Just (TaskStatus Active )
161+ notesToModel :: ModeMap NoteSample -> Vector (Either TaskMode (EntityView Note ))
162+ notesToModel = Vector. fromList . foldMap notesToModel' . Map. assocs
163+ where
164+ notesToModel' (taskMode, Sample {items}) = Left taskMode : map Right items
134165
135166listItemHeight :: Int
136167listItemHeight = 1
@@ -183,9 +214,9 @@ appDraw Model{visibleNotes, isNoteOpen} = [mainWidget <=> keysHelpLine]
183214
184215 openNoteContent =
185216 case listSelectedElement visibleNotes of
186- Nothing -> " "
187- Just (_, Entity _ note) ->
217+ Just (_, Right (Entity _ NoteView {note})) ->
188218 Text. pack $ clean $ fromRgaM note. note_text
219+ _ -> " "
189220
190221 keysHelpLine =
191222 hBox
@@ -199,10 +230,15 @@ appDraw Model{visibleNotes, isNoteOpen} = [mainWidget <=> keysHelpLine]
199230 [ withAttr highlightAttr (txt " ^q" )
200231 , txt " "
201232 , withAttr highlightAttr (txt " Esc" )
202- , txt " exit "
203- , withAttr highlightAttr (txt " Enter" )
204- , txt " open"
233+ , txt " exit"
205234 ]
235+ ++ case listSelectedElement visibleNotes of
236+ Just (_, Right Entity {}) ->
237+ [ txt " "
238+ , withAttr highlightAttr (txt " Enter" )
239+ , txt " open"
240+ ]
241+ _ -> []
206242
207243-- Clean string for Brick
208244clean :: String -> String
@@ -232,7 +268,10 @@ appHandleVtyEvent event = do
232268 -- open selected note
233269 selectedNoteM <-
234270 preuse $ # visibleNotes . listSelectedElementL
235- # isNoteOpen .= isJust selectedNoteM
271+ # isNoteOpen
272+ .= case selectedNoteM of
273+ Just (Right Entity {}) -> True
274+ _ -> False
236275 e -> zoom # visibleNotes $ handleListEvent e
237276
238277handleViewportEvent :: Event -> EventM ()
@@ -249,8 +288,10 @@ handleViewportEvent = \case
249288 where
250289 vps = viewportScroll OpenNoteViewport
251290
252- renderListItem :: Bool -> EntityDoc Note -> Widget
253- renderListItem _isSelected (Entity _ note) = txt $ noteTitle note
291+ renderListItem :: Bool -> Either TaskMode (EntityView Note ) -> Widget
292+ renderListItem _isSelected = \ case
293+ Left taskMode -> hBorderWithLabel $ txt $ sampleLabel taskMode
294+ Right (Entity _ NoteView {note}) -> txt $ noteTitle note
254295
255296noteTitle :: Note -> Text
256297noteTitle Note {note_text} =
0 commit comments