88@inject NavigationManager NavigationManager
99
1010<div class =" page-title" >
11- <div class =" page-header" >
12- <MudIconButton Icon =" @Icons.Material.Filled.ArrowBack" Title =" Back" OnClick =" Close" />
11+ <div class =" page-header" >
12+ <MudIconButton Icon =" @Icons.Material.Filled.ArrowBack" Title =" Back" OnClick =" Close" />
1313
14- <MudText Typo =" Typo.h6" >Trends</MudText >
15- </div >
14+ <MudText Typo =" Typo.h6" >Trends</MudText >
15+ </div >
1616
17- <TrendsSwitcher @bind-SelectedDates =" SelectedDates" @bind-SelectedDates:after =" LoadDates" OpenToDate =" OpenToDate" />
17+ <TrendsSwitcher @bind-SelectedDates =" SelectedDates" @bind-SelectedDates:after =" LoadDates" OpenToDate =" OpenToDate" />
1818</div >
1919
2020<div class =" page-body" >
21- <div id =" trends-category-list" >
22- @foreach ( var (category , points ) in AllPoints .OrderBy (x => x .Key .Group ).ThenBy (x => x .Key .Index ))
23- {
24- <div class =" trends-category" >
25- <MudText Typo =" Typo.h6" >@( TrendCategoryView .GetHeaderText (category )) </MudText >
26-
27- <ErrorBoundary >
28- <ChildContent >
29- <TrendCategoryView Category =" category" Dates =" SelectedDates" PointsByDay =" points" />
30- </ChildContent >
31-
32- <ErrorContent >
33- <MudText Color =" Color.Error" >💥 Failed to load .</MudText >
34- </ErrorContent >
35- </ErrorBoundary >
36- </div >
37- }
38- </div >
21+ <div id =" trends-category-list" >
22+ @foreach ( var (category , points ) in AllPoints .OrderBy (x => x .Key .Group ).ThenBy (x => x .Key .Index ))
23+ {
24+ @if (category .Group == " Notes" && Preferences .Get (" hide_notes" , false ))
25+ {
26+ continue ;
27+ }
28+
29+ <div class =" trends-category" >
30+ <MudText Typo =" Typo.h6" >@( TrendCategoryView .GetHeaderText (category )) </MudText >
31+
32+ <ErrorBoundary >
33+ <ChildContent >
34+ <TrendCategoryView Category =" category" Dates =" SelectedDates" PointsByDay =" points" />
35+ </ChildContent >
36+
37+ <ErrorContent >
38+ <MudText Color =" Color.Error" >💥 Failed to load .</MudText >
39+ </ErrorContent >
40+ </ErrorBoundary >
41+ </div >
42+ }
43+ </div >
3944</div >
4045
4146@code {
42- bool _leaving ;
43-
44- [Parameter ]
45- public string OpenToDateString { get ; set ; }
46-
47- public DateOnly OpenToDate { get ; set ; }
48-
49- public IReadOnlyList <DateOnly > SelectedDates { get ; set ; }
50-
51- Dictionary <DataPointCategory , IReadOnlyDictionary <int, IReadOnlyCollection <DataPoint >>> AllPoints = new ();
52-
53- protected override void OnInitialized ()
54- {
55- logger .LogDebug (" Initializing" );
56- base .OnInitialized ();
57-
58- KeyEventService .Entered (() => Close ());
59-
60- OpenToDate = DateOnly .ParseExact (OpenToDateString , " yyyyMMdd" );
61- logger .LogInformation ($" Opening to {OpenToDate }" );
62- }
63-
64- async Task LoadDates ()
65- {
66- logger .LogInformation ($" Loading dates <{SelectedDates [0 ]}..{SelectedDates [^ 1 ]}>" );
67- var sw = Stopwatch .StartNew ();
68-
69- await using var db = await DbFactory .CreateDbContextAsync ();
70-
71- // All the points we want to show.
72- var query = db .Points
73- .Where (p => ! p .Deleted && ! p .Category .Deleted && p .Category .Enabled && SelectedDates .Contains (p .Day .Date ))
74- .Include (p => p .Category )
75- .Include (p => p .Day )
76- .AsEnumerable ()
77- .OrderBy (p => p .Day .Date )
78- .ThenBy (p => p .CreatedAt )
79- .GroupBy (
80- p => p .Category ,
81- p => p
82- );
83-
84- // Group points by category then day number.
85- AllPoints .Clear ();
86- foreach (var group in query )
87- {
88- var pointsByDayNumber = new Dictionary <int , IReadOnlyCollection <DataPoint >>();
89-
90- foreach (var date in SelectedDates )
91- {
92- pointsByDayNumber .Add (date .Day , group .Where (p => p .Day .Date == date ).ToHashSet ());
93- }
94-
95- AllPoints .Add (group .Key , pointsByDayNumber );
96- }
97-
98- logger .LogInformation ($" Loaded dates in {sw .ElapsedMilliseconds }ms" );
99- }
100-
101- void Close ()
102- {
103- logger .LogInformation (" Going to index" );
104- _leaving = true ;
105- NavigationManager .NavigateTo (" /" , false , true );
106- }
107-
108- public void Dispose ()
109- {
110- KeyEventService .Exited ();
111- }
112-
113- protected override bool ShouldRender () => ! _leaving ;
47+ bool _leaving ;
48+
49+ [Parameter ]
50+ public string OpenToDateString { get ; set ; }
51+
52+ public DateOnly OpenToDate { get ; set ; }
53+
54+ public IReadOnlyList <DateOnly > SelectedDates { get ; set ; }
55+
56+ Dictionary <DataPointCategory , IReadOnlyDictionary <int, IReadOnlyCollection <DataPoint >>> AllPoints = new ();
57+
58+ protected override void OnInitialized ()
59+ {
60+ logger .LogDebug (" Initializing" );
61+ base .OnInitialized ();
62+
63+ KeyEventService .Entered (() => Close ());
64+
65+ OpenToDate = DateOnly .ParseExact (OpenToDateString , " yyyyMMdd" );
66+ logger .LogInformation ($" Opening to {OpenToDate }" );
67+ }
68+
69+ async Task LoadDates ()
70+ {
71+ logger .LogInformation ($" Loading dates <{SelectedDates [0 ]}..{SelectedDates [^ 1 ]}>" );
72+ var sw = Stopwatch .StartNew ();
73+
74+ await using var db = await DbFactory .CreateDbContextAsync ();
75+
76+ // All the points we want to show.
77+ var query = db .Points
78+ .Where (p => ! p .Deleted && ! p .Category .Deleted && p .Category .Enabled && SelectedDates .Contains (p .Day .Date ))
79+ .Include (p => p .Category )
80+ .Include (p => p .Day )
81+ .AsEnumerable ()
82+ .OrderBy (p => p .Day .Date )
83+ .ThenBy (p => p .CreatedAt )
84+ .GroupBy (
85+ p => p .Category ,
86+ p => p
87+ );
88+
89+ // Group points by category then day number.
90+ AllPoints .Clear ();
91+ foreach (var group in query )
92+ {
93+ var pointsByDayNumber = new Dictionary <int , IReadOnlyCollection <DataPoint >>();
94+
95+ foreach (var date in SelectedDates )
96+ {
97+ pointsByDayNumber .Add (date .Day , group .Where (p => p .Day .Date == date ).ToHashSet ());
98+ }
99+
100+ AllPoints .Add (group .Key , pointsByDayNumber );
101+ }
102+
103+ logger .LogInformation ($" Loaded dates in {sw .ElapsedMilliseconds }ms" );
104+ }
105+
106+ void Close ()
107+ {
108+ logger .LogInformation (" Going to index" );
109+ _leaving = true ;
110+ NavigationManager .NavigateTo (" /" , false , true );
111+ }
112+
113+ public void Dispose ()
114+ {
115+ KeyEventService .Exited ();
116+ }
117+
118+ protected override bool ShouldRender () => ! _leaving ;
114119}
0 commit comments