11package app
22
33import (
4+ "fmt"
5+
46 "github.com/charmbracelet/bubbles/key"
57 tea "github.com/charmbracelet/bubbletea"
68
79 "github.com/hedhyw/json-log-viewer/internal/pkg/events"
810 "github.com/hedhyw/json-log-viewer/internal/pkg/source"
911)
1012
11- // StateFiltered is a state that shows filtered records.
12- type StateFiltered struct {
13+ // StateFilteredModel is a state that shows filtered records.
14+ type StateFilteredModel struct {
1315 helper
1416
15- previousState StateLoaded
17+ previousState StateLoadedModel
1618 table logsTableModel
1719 logEntries source.LazyLogEntries
1820
@@ -22,10 +24,10 @@ type StateFiltered struct {
2224
2325func newStateFiltered (
2426 application Application ,
25- previousState StateLoaded ,
27+ previousState StateLoadedModel ,
2628 filterText string ,
27- ) StateFiltered {
28- return StateFiltered {
29+ ) StateFilteredModel {
30+ return StateFilteredModel {
2931 helper : helper {Application : application },
3032
3133 previousState : previousState ,
@@ -37,7 +39,7 @@ func newStateFiltered(
3739}
3840
3941// Init initializes component. It implements tea.Model.
40- func (s StateFiltered ) Init () tea.Cmd {
42+ func (s StateFilteredModel ) Init () tea.Cmd {
4143 return func () tea.Msg {
4244 return events .LogEntriesLoadedMsg (
4345 s .previousState .logEntries .Filter (s .filterText ),
@@ -46,14 +48,16 @@ func (s StateFiltered) Init() tea.Cmd {
4648}
4749
4850// View renders component. It implements tea.Model.
49- func (s StateFiltered ) View () string {
50- footer := s .Application .FooterStyle .Render (" filtered by: " + s .filterText )
51+ func (s StateFilteredModel ) View () string {
52+ footer := s .Application .FooterStyle .Render (
53+ fmt .Sprintf ("filtered %d by: %s" , len (s .logEntries ), s .filterText ),
54+ )
5155
5256 return s .BaseStyle .Render (s .table .View ()) + "\n " + footer
5357}
5458
5559// Update handles events. It implements tea.Model.
56- func (s StateFiltered ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
60+ func (s StateFilteredModel ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
5761 var cmdBatch []tea.Cmd
5862
5963 s .helper = s .helper .Update (msg )
@@ -86,7 +90,7 @@ func (s StateFiltered) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
8690 return s , tea .Batch (cmdBatch ... )
8791}
8892
89- func (s StateFiltered ) handleLogEntriesLoadedMsg (
93+ func (s StateFilteredModel ) handleLogEntriesLoadedMsg (
9094 msg events.LogEntriesLoadedMsg ,
9195) (tea.Model , tea.Cmd ) {
9296 s .logEntries = source .LazyLogEntries (msg )
@@ -95,7 +99,7 @@ func (s StateFiltered) handleLogEntriesLoadedMsg(
9599 return s , s .table .Init ()
96100}
97101
98- func (s StateFiltered ) handleFilterKeyClickedMsg () (tea.Model , tea.Cmd ) {
102+ func (s StateFilteredModel ) handleFilterKeyClickedMsg () (tea.Model , tea.Cmd ) {
99103 state := newStateFiltering (
100104 s .Application ,
101105 s .previousState ,
@@ -104,15 +108,15 @@ func (s StateFiltered) handleFilterKeyClickedMsg() (tea.Model, tea.Cmd) {
104108 return initializeModel (state )
105109}
106110
107- func (s StateFiltered ) handleRequestOpenJSON () (tea.Model , tea.Cmd ) {
111+ func (s StateFilteredModel ) handleRequestOpenJSON () (tea.Model , tea.Cmd ) {
108112 if len (s .logEntries ) == 0 {
109113 return s , events .BackKeyClicked
110114 }
111115
112116 return s , events .OpenJSONRowRequested (s .logEntries , s .table .Cursor ())
113117}
114118
115- func (s StateFiltered ) withApplication (application Application ) (state , tea.Cmd ) {
119+ func (s StateFilteredModel ) withApplication (application Application ) (stateModel , tea.Cmd ) {
116120 s .Application = application
117121
118122 var cmd tea.Cmd
@@ -122,6 +126,6 @@ func (s StateFiltered) withApplication(application Application) (state, tea.Cmd)
122126}
123127
124128// String implements fmt.Stringer.
125- func (s StateFiltered ) String () string {
129+ func (s StateFilteredModel ) String () string {
126130 return modelValue (s )
127131}
0 commit comments