11using Daybreak . Models ;
2+ using Daybreak . Shared . Extensions ;
23using Daybreak . Shared . Models . Builds ;
34using Daybreak . Shared . Models . Guildwars ;
45using Daybreak . Shared . Services . BuildTemplates ;
56using Daybreak . Shared . Services . Toolbox ;
67using Daybreak . Shared . Utils ;
8+ using Microsoft . AspNetCore . Components . Web ;
9+ using Microsoft . JSInterop ;
710using System . Core . Extensions ;
11+ using System . Drawing ;
812using System . Extensions ;
913using TrailBlazr . Services ;
1014using TrailBlazr . ViewModels ;
1115
1216namespace Daybreak . Views ;
13- public sealed class BuildListViewModel (
14- IViewManager viewManager ,
15- IBuildTemplateManager buildTemplateManager ,
16- IToolboxService toolboxService )
17+ public sealed class BuildListViewModel
1718 : ViewModelBase < BuildListViewModel , BuildListView >
1819{
19- private readonly IViewManager viewManager = viewManager . ThrowIfNull ( ) ;
20- private readonly IBuildTemplateManager buildTemplateManager = buildTemplateManager . ThrowIfNull ( ) ;
21- private readonly IToolboxService toolboxService = toolboxService . ThrowIfNull ( ) ;
20+ private readonly DotNetObjectReference < BuildListViewModel > dotNetObjectReference ;
21+ private readonly IViewManager viewManager ;
22+ private readonly IBuildTemplateManager buildTemplateManager ;
23+ private readonly IJSRuntime jsRuntime ;
24+ private readonly IToolboxService toolboxService ;
2225
2326 private readonly List < BuildListEntry > buildEntryCache = [ ] ;
2427
28+ public BuildListViewModel (
29+ IViewManager viewManager ,
30+ IBuildTemplateManager buildTemplateManager ,
31+ IJSRuntime jsRuntime ,
32+ IToolboxService toolboxService )
33+ {
34+ this . dotNetObjectReference = DotNetObjectReference . Create ( this ) ;
35+ this . viewManager = viewManager ;
36+ this . buildTemplateManager = buildTemplateManager ;
37+ this . jsRuntime = jsRuntime ;
38+ this . toolboxService = toolboxService ;
39+ }
40+
2541 public List < BuildListEntry > BuildEntries { get ; } = [ ] ;
2642
43+ public BuildListEntry ? HoveredEntry { get ; private set ; }
44+
45+ public Point ? SnippetPosition { get ; private set ; }
46+
47+ public bool ShowSnippet { get ; private set ; }
48+
2749 public bool IsLoading
2850 {
2951 get ;
@@ -86,6 +108,7 @@ public void SearchTermChanged(string searchTerm)
86108
87109 public void BuildClicked ( BuildListEntry buildListEntry )
88110 {
111+ this . CloseSnippet ( ) ;
89112 this . viewManager . ShowView < BuildRoutingView > ( ( nameof ( BuildRoutingView . BuildName ) , buildListEntry . BuildEntry . Name ?? string . Empty ) ) ;
90113 }
91114
@@ -112,6 +135,37 @@ public void CreateNewTeamBuild()
112135 this . viewManager . ShowView < BuildRoutingView > ( ( nameof ( BuildRoutingView . BuildName ) , build . Name ?? string . Empty ) ) ;
113136 }
114137
138+ public async void OpenSnippet ( BuildListEntry buildListEntry , MouseEventArgs e )
139+ {
140+ this . ShowSnippet = false ;
141+ this . HoveredEntry = buildListEntry ;
142+ this . SnippetPosition = new Point ( ( int ) e . ClientX , ( int ) e . ClientY ) ;
143+ await this . jsRuntime . HoverDelayStart ( this . dotNetObjectReference , nameof ( this . HoverComplete ) ) ;
144+ }
145+
146+ public async void CloseSnippet ( )
147+ {
148+ this . HoveredEntry = default ;
149+ this . ShowSnippet = false ;
150+ await this . jsRuntime . HoverDelayStop ( ) ;
151+ }
152+
153+ public async void MouseMoveBuildEntry ( MouseEventArgs e )
154+ {
155+ if ( ! this . ShowSnippet )
156+ {
157+ this . SnippetPosition = new Point ( ( int ) e . ClientX , ( int ) e . ClientY ) ;
158+ }
159+ }
160+
161+
162+ [ JSInvokable ]
163+ public void HoverComplete ( )
164+ {
165+ this . ShowSnippet = true ;
166+ this . RefreshView ( ) ;
167+ }
168+
115169 private async ValueTask SearchByTerm ( string term , CancellationToken cancellationToken )
116170 {
117171 if ( string . IsNullOrWhiteSpace ( term ) )
0 commit comments