Skip to content

Commit 83086dd

Browse files
committed
added preventation for local navigation
1 parent f0c3153 commit 83086dd

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/LinkDotNet.Blog.Web/Features/Admin/BlogPostEditor/Components/CreateNewBlogPost.razor

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@using LinkDotNet.Blog.Domain
2+
@inject IToastService ToastService
23

34
<h3>@Title</h3>
45

@@ -93,6 +94,8 @@
9394

9495
private CreateNewModel model = new();
9596

97+
private bool ignoreIsDirty;
98+
9699
protected override void OnParametersSet()
97100
{
98101
if (BlogPost == null)
@@ -124,7 +127,12 @@
124127

125128
private void PreventNavigationWhenDirty(LocationChangingContext context)
126129
{
127-
if (model.IsDirty)
130+
if (model.IsDirty && !ignoreIsDirty)
131+
{
128132
context.PreventNavigation();
133+
ToastService.ShowWarning(
134+
"You have unsaved changes. Click on this message to ignore this warning the next time",
135+
onClick: () => ignoreIsDirty = true);
136+
}
129137
}
130138
}

tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/BlogPostEditor/Components/CreateNewBlogPostTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using Blazored.Toast.Services;
34
using Bunit;
45
using LinkDotNet.Blog.Domain;
56
using LinkDotNet.Blog.TestUtilities;
@@ -14,6 +15,7 @@ public class CreateNewBlogPostTests : TestContext
1415
public CreateNewBlogPostTests()
1516
{
1617
ComponentFactories.AddStub<UploadFile>();
18+
Services.AddScoped(_ => Mock.Of<IToastService>());
1719
}
1820

1921
[Fact]

0 commit comments

Comments
 (0)