Used AI to change project to blazor webassembly.
This commit is contained in:
49
Services/ScrollService.cs
Normal file
49
Services/ScrollService.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace DouwcoWebsite;
|
||||
|
||||
public class ScrollService : IDisposable
|
||||
{
|
||||
private readonly IJSRuntime _jsRuntime;
|
||||
private DotNetObjectReference<ScrollService>? _dotNetObjectReference;
|
||||
private IJSObjectReference? _module;
|
||||
|
||||
public event Action<string>? OnSectionChanged;
|
||||
|
||||
public ScrollService(IJSRuntime jsRuntime)
|
||||
{
|
||||
_jsRuntime = jsRuntime;
|
||||
_dotNetObjectReference = DotNetObjectReference.Create(this);
|
||||
}
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
_module = await _jsRuntime.InvokeAsync<IJSObjectReference>(
|
||||
"import", "./js/scrollService.js");
|
||||
|
||||
await _module.InvokeVoidAsync("initialize", _dotNetObjectReference);
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public void HandleSectionChange(string sectionId)
|
||||
{
|
||||
OnSectionChanged?.Invoke(sectionId);
|
||||
}
|
||||
|
||||
public async Task ScrollToSection(string sectionId)
|
||||
{
|
||||
if (_module != null)
|
||||
{
|
||||
await _module.InvokeVoidAsync("scrollToSection", sectionId);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_dotNetObjectReference?.Dispose();
|
||||
if (_module != null)
|
||||
{
|
||||
_module.InvokeVoidAsync("dispose");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user