diff --git a/Nodexr/Nodexr.csproj b/Nodexr/Nodexr.csproj index 2977ca95..720ceb2c 100644 --- a/Nodexr/Nodexr.csproj +++ b/Nodexr/Nodexr.csproj @@ -21,6 +21,7 @@ + diff --git a/Nodexr/Program.cs b/Nodexr/Program.cs index 8a7c029e..708a4dd9 100644 --- a/Nodexr/Program.cs +++ b/Nodexr/Program.cs @@ -11,6 +11,8 @@ using Nodexr.Shared.Services; using Blazored; using Blazored.Modal; +using Blazored.Toast; +using Blazored.Toast.Services; using Blazored.Modal.Services; namespace Nodexr @@ -22,11 +24,12 @@ public static async Task Main(string[] args) var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("app"); + builder.Services.AddBlazoredToast(); builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); - builder.Services.AddSingleton(); - builder.Services.AddSingleton(); - builder.Services.AddSingleton(); - builder.Services.AddSingleton(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddBlazoredModal(); await builder.Build().RunAsync(); diff --git a/Nodexr/Shared/Components/OutputDisplay.razor b/Nodexr/Shared/Components/OutputDisplay.razor index fca4f920..a2d7e185 100644 --- a/Nodexr/Shared/Components/OutputDisplay.razor +++ b/Nodexr/Shared/Components/OutputDisplay.razor @@ -2,6 +2,7 @@ @inject IJSRuntime JSRuntime @inject IModalService ModalService @inject NavigationManager NavManager +@inject IToastService ToastService @using Microsoft.AspNetCore.WebUtilities

Output:

@@ -44,11 +45,14 @@ private async Task OnCreateLinkButtonClick() { string url = QueryHelpers.AddQueryString(NavManager.BaseUri, "parse", NodeHandler.CachedOutput.Expression); - await JSRuntime.InvokeVoidAsync("clipboardCopy.copyText", url, "Link copied to clipboard"); + await JSRuntime.InvokeVoidAsync("clipboardCopy.copyText", url, ""); + ToastService.ShowInfo("", "Link copied to clipboard"); } private async Task CopyTextToClipboard() { - await JSRuntime.InvokeVoidAsync("clipboardCopy.copyText", NodeHandler.CachedOutput.Expression, "Copied to clipboard"); + string regex = NodeHandler.CachedOutput.Expression; + await JSRuntime.InvokeVoidAsync("clipboardCopy.copyText", regex, ""); + ToastService.ShowInfo(regex, "Copied to clipboard"); } } diff --git a/Nodexr/Shared/MainLayout.razor b/Nodexr/Shared/MainLayout.razor index 13dba7b8..8c734fe1 100644 --- a/Nodexr/Shared/MainLayout.razor +++ b/Nodexr/Shared/MainLayout.razor @@ -1,4 +1,5 @@ @using Nodexr.Shared.NodeTypes; +@using Blazored.Toast.Configuration; @inject RegexReplaceHandler RegexReplaceHandler; @inherits LayoutComponentBase @@ -8,7 +9,9 @@ @**@ - + +
@Body
diff --git a/Nodexr/Shared/Services/NodeHandler.cs b/Nodexr/Shared/Services/NodeHandler.cs index dc32893a..7aff70bf 100644 --- a/Nodexr/Shared/Services/NodeHandler.cs +++ b/Nodexr/Shared/Services/NodeHandler.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.WebUtilities; using Nodexr.Shared.Nodes; using Nodexr.Shared.NodeInputs; +using Blazored.Toast.Services; namespace Nodexr.Shared.Services { @@ -53,10 +54,12 @@ private set public event EventHandler OnRequireNodeGraphRefresh; readonly NavigationManager navManager; + readonly IToastService toastService; - public NodeHandler(NavigationManager navManager) + public NodeHandler(NavigationManager navManager, IToastService toastService) { this.navManager = navManager; + this.toastService = toastService; var uri = navManager.ToAbsoluteUri(navManager.Uri); if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("parse", out var parseString)) @@ -85,6 +88,7 @@ public bool TryCreateTreeFromRegex(string regex) } else { + toastService.ShowError(parseResult.Error.ToString(), "Couldn't parse input"); Console.WriteLine("Couldn't parse input: " + parseResult.Error); return false; } diff --git a/Nodexr/_Imports.razor b/Nodexr/_Imports.razor index e8852582..72055209 100644 --- a/Nodexr/_Imports.razor +++ b/Nodexr/_Imports.razor @@ -15,4 +15,6 @@ @using Nodexr.Shared.Services @using Blazored @using Blazored.Modal -@using Blazored.Modal.Services \ No newline at end of file +@using Blazored.Modal.Services +@using Blazored.Toast +@using Blazored.Toast.Services \ No newline at end of file diff --git a/Nodexr/wwwroot/css/toast-overrides.css b/Nodexr/wwwroot/css/toast-overrides.css new file mode 100644 index 00000000..afc79633 --- /dev/null +++ b/Nodexr/wwwroot/css/toast-overrides.css @@ -0,0 +1,7 @@ +.blazored-toast-body p { + white-space: pre-wrap !important; +} + +.blazored-toast-body .blazored-toast-header h5 { + text-transform: none !important; +} \ No newline at end of file diff --git a/Nodexr/wwwroot/index.html b/Nodexr/wwwroot/index.html index 497987b8..c5bad6b6 100644 --- a/Nodexr/wwwroot/index.html +++ b/Nodexr/wwwroot/index.html @@ -10,9 +10,11 @@ + + diff --git a/Nodexr/wwwroot/js/ClipboardCopy.js b/Nodexr/wwwroot/js/ClipboardCopy.js index c48b83f6..1523d008 100644 --- a/Nodexr/wwwroot/js/ClipboardCopy.js +++ b/Nodexr/wwwroot/js/ClipboardCopy.js @@ -4,7 +4,9 @@ window.clipboardCopy = { copyText: function (text, message) { navigator.clipboard.writeText(text).then(function () { - alert(message); + if (!!message) { + alert(message); + } }) .catch(function (error) { alert(error);