You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Components/Services/JsApiService.cs

37 lines
1003 B

2 years ago
using System.Threading.Tasks;
using Microsoft.JSInterop;
namespace Connected
{
public interface IJsApiService
{
ValueTask CopyToClipboardAsync(string text);
ValueTask OpenInNewTabAsync(string url);
ValueTask Open(string link, string target);
}
public class JsApiService : IJsApiService
{
private readonly IJSRuntime _jsRuntime;
public JsApiService(IJSRuntime jsRuntime)
{
_jsRuntime = jsRuntime;
}
public ValueTask CopyToClipboardAsync(string text) =>
_jsRuntime.InvokeVoidAsync("mudWindow.copyToClipboard", text);
public ValueTask Open(string link, string target)
{
if (target == "_blank")
return OpenInNewTabAsync(link);
return _jsRuntime.InvokeVoidAsync("open", link, target);
}
public ValueTask OpenInNewTabAsync(string url) =>
_jsRuntime.InvokeVoidAsync("mudWindow.open", url, "_blank");
}
}