Skip to content

Commit 17aadfc

Browse files
committed
Moved async to its own page and updated Diff to use class instead of named tuple.
1 parent e7756e5 commit 17aadfc

8 files changed

Lines changed: 96 additions & 131 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@inject HttpClient Http
2+
@page "/async"
3+
4+
<TextDiff OldText="@left" NewText="@right" CollapseContent="@collapsible">
5+
<Header>
6+
<h6 style="padding: 12px; margin: 0px;">
7+
Loaded From <a target="_blank" href="https://github.com/lzinga/TTTWeightedTraitorSelection">My Github Repo</a>
8+
9+
<span class="badge badge-primary">@($"{context.LineModificationCount} Line Modifications")</span>
10+
<span class="badge badge-danger">@($"{context.LineDeletionCount} Line Deletions")</span>
11+
<span class="badge badge-success">@($"{context.LineAdditionCount} Line Additions")</span>
12+
13+
<span class="badge badge-primary">@($"{context.WordModificationCount} Word Modifications")</span>
14+
<span class="badge badge-danger">@($"{context.WordDeletionCount} Word Deletions")</span>
15+
<span class="badge badge-success">@($"{context.WordAdditionCount} Word Additions")</span>
16+
</h6>
17+
<button type="button" @onclick="@(() => collapsible = !collapsible)">Toggle Collapse</button>
18+
</Header>
19+
</TextDiff>
20+
21+
@code {
22+
23+
string left = "";
24+
string right = "";
25+
bool collapsible = true;
26+
27+
28+
protected override async Task OnInitializedAsync()
29+
{
30+
left = await Http.GetStringAsync("https://raw.githubusercontent.com/lzinga/TTTWeightedTraitorSelection/fe20c3e645aaa20e40cecc615037d51a34f9cb4a/README.md");
31+
right = await Http.GetStringAsync("https://raw.githubusercontent.com/lzinga/TTTWeightedTraitorSelection/c763193e8a5bddfbec097c7b96ea0f875eedb01b/README.md");
32+
}
33+
}

samples/BlazorTextDiff.Web/Pages/Counter.razor

Lines changed: 0 additions & 16 deletions
This file was deleted.

samples/BlazorTextDiff.Web/Pages/FetchData.razor

Lines changed: 0 additions & 55 deletions
This file was deleted.

samples/BlazorTextDiff.Web/Pages/Index.razor

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,28 @@
33

44

55
<h1>Static</h1>
6-
<TextDiff OldText="Old Text" NewText="New Text" CollapseContent="@collapsible">
7-
<Header>
8-
<h6 style="padding: 12px; margin: 0px;">Test</h6>
9-
</Header>
10-
</TextDiff>
11-
<br />
12-
<h1>Async</h1>
136
<TextDiff OldText="@left" NewText="@right" CollapseContent="@collapsible">
147
<Header>
15-
<h6 style="padding: 12px; margin: 0px;">@context.Additions Additions @context.Modifications Modifications and @context.Deletions Deletions</h6>
16-
<button type="button" @onclick="@(() => collapsible = !collapsible)">Toggle Collapse</button>
8+
<h6 style="padding: 12px; margin: 0px;">
9+
Harry Potter and the Metabolic Stone
10+
<span class="badge badge-primary">@($"{context.LineModificationCount} Line Modifications")</span>
11+
<span class="badge badge-danger">@($"{context.LineDeletionCount} Line Deletions")</span>
12+
<span class="badge badge-success">@($"{context.LineAdditionCount} Line Additions")</span>
13+
14+
<span class="badge badge-primary">@($"{context.WordModificationCount} Word Modifications")</span>
15+
<span class="badge badge-danger">@($"{context.WordDeletionCount} Word Deletions")</span>
16+
<span class="badge badge-success">@($"{context.WordAdditionCount} Word Additions")</span>
17+
</h6>
1718
</Header>
1819
</TextDiff>
1920

20-
@code {
2121

22-
23-
string left = "";
24-
string right = "";
22+
@code {
23+
string left = @"Mr. and Mrs. Fursley, of number six, Sunset Drive, were proud to say that they were almost perfectly normal. They were the last people you'd expect to be involved in anything weird or mysterious, because they just didn't hold with such nonsense.
24+
Mr. Fursley was the director of a firm called Brunings, which made hatchets. He was a big, well fed man with no neck, although he did have a very large mustache. Mrs. Fursley was petite and blonde and had nearly twice the usual amount of neck, which came in very useful as she spent so much of her time bending over garden fences, spying on the neighbors. The Fursley's had a small son called Fudley and in their opinion there was no finer boy anywhere.
25+
The Dursleys had everything they wanted...";
26+
string right = @"Mr. and Mrs. Dursley, of number four, Privet Drive, were proud to say that they were perfectly normal, thank you very much. They were the last people you'd expect to be involved in anything strange or mysterious, because they just didn't hold with such nonsense.
27+
Mr. Dursley was the director of a firm called Grunnings, which made drills. He was a big, beefy man with hardly any neck, although he did have a very large mustache. Mrs. Dursley was thin and blonde and had nearly twice the usual amount of neck, which came in very useful as she spent so much of her time craning over garden fences, spying on the neighbors. The Dursleys had a small son called Dudley and in their opinion there was no finer boy anywhere.
28+
The Dursleys had everything they wanted...";
2529
bool collapsible = true;
26-
27-
28-
protected override async Task OnInitializedAsync()
29-
{
30-
left = await Http.GetStringAsync("https://raw.githubusercontent.com/lzinga/TTTWeightedTraitorSelection/fe20c3e645aaa20e40cecc615037d51a34f9cb4a/README.md");
31-
right = await Http.GetStringAsync("https://raw.githubusercontent.com/lzinga/TTTWeightedTraitorSelection/c763193e8a5bddfbec097c7b96ea0f875eedb01b/README.md");
32-
}
3330
}

samples/BlazorTextDiff.Web/Shared/NavMenu.razor

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
99
<ul class="nav flex-column">
1010
<li class="nav-item px-3">
11-
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
11+
<NavLink class="nav-link" href="/" Match="NavLinkMatch.All">
1212
<span class="oi oi-home" aria-hidden="true"></span> Home
1313
</NavLink>
1414
</li>
15+
<li class="nav-item px-3">
16+
<NavLink class="nav-link" href="/async">
17+
<span class="oi oi-home" aria-hidden="true"></span> Async
18+
</NavLink>
19+
</li>
1520
</ul>
1621
</div>
1722

src/DiffStats.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using DiffPlex.DiffBuilder.Model;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
7+
namespace BlazorTextDiff
8+
{
9+
public class DiffStats
10+
{
11+
public int LineAdditionCount { get; set; }
12+
public int LineModificationCount { get; set; }
13+
public int LineDeletionCount { get; set; }
14+
15+
public int WordAdditionCount { get; set; }
16+
public int WordModificationCount { get; set; }
17+
public int WordDeletionCount { get; set; }
18+
19+
public DiffStats()
20+
{
21+
22+
}
23+
24+
public DiffStats(DiffPaneModel diff)
25+
{
26+
this.LineAdditionCount = diff.Lines.Count(x => x.Type == ChangeType.Inserted);
27+
this.LineModificationCount = diff.Lines.Count(x => x.Type == ChangeType.Modified);
28+
this.LineDeletionCount = diff.Lines.Count(x => x.Type == ChangeType.Deleted);
29+
30+
this.WordAdditionCount = diff.Lines.SelectMany(i => i.SubPieces).Count(i => i.Type == ChangeType.Inserted);
31+
this.WordModificationCount = diff.Lines.SelectMany(i => i.SubPieces).Count(i => i.Type == ChangeType.Modified);
32+
this.WordDeletionCount = diff.Lines.SelectMany(i => i.SubPieces).Count(i => i.Type == ChangeType.Deleted);
33+
}
34+
}
35+
}

src/TextDiff.razor

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
<div class="diff-container">
88
<div class="diff-header">
9-
@Header((Additions, Deletions, Modifications))
10-
( @paneHeight )
9+
@Header(new DiffStats(diff.NewText))
1110
</div>
1211
<CascadingValue Value="ShowWhiteSpace" Name="ShowWhiteSpace">
1312
<CascadingValue Value="CollapseContent" Name="CollapseContent">
@@ -50,35 +49,12 @@
5049
/// The text after any changes.
5150
/// </summary>
5251
[Parameter] public string NewText { get; set; }
53-
[Parameter] public RenderFragment<(int Additions, int Deletions, int Modifications)> Header { get; set; }
52+
[Parameter] public RenderFragment<DiffStats> Header { get; set; }
5453

5554
private SideBySideDiffModel diff;
5655
private ElementReference pane;
5756
private int paneHeight;
5857

59-
private int Additions
60-
{
61-
get
62-
{
63-
return diff.NewText.Lines.Count(x => x.Type == ChangeType.Inserted);
64-
}
65-
}
66-
67-
private int Modifications
68-
{
69-
get
70-
{
71-
return diff.NewText.Lines.Count(x => x.Type == ChangeType.Modified);
72-
}
73-
}
74-
75-
private int Deletions
76-
{
77-
get
78-
{
79-
return diff.NewText.Lines.Count(x => x.Type == ChangeType.Deleted);
80-
}
81-
}
8258

8359
/// <summary>
8460
/// When parameters set update the component.

src/TextDiffLine.razor

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,20 @@
1010
{
1111
if (ShowWhiteSpace)
1212
{
13-
@((MarkupString)Model.Text.Replace(" ", spaceValue).Replace("\t", tabValue))
13+
@((MarkupString)Model.Text.Replace(" ", spaceValue).Replace("\t", tabValue).Trim())
1414
}
1515
else
1616
{
17-
@((MarkupString)Model.Text)
17+
@((MarkupString)Model.Text.Trim())
1818
}
19-
2019
}
2120
else if (Model.Type == ChangeType.Modified)
2221
{
2322
foreach (var character in Model.SubPieces)
2423
{
2524
if (character.Type == ChangeType.Imaginary) { continue; }
2625

27-
<span class="@character.Type.ToString().ToLower()-character">
28-
@if (ShowWhiteSpace)
29-
{
30-
@character.Text.Replace(" ", spaceValue.ToString())
31-
}
32-
else
33-
{
34-
@character.Text
35-
}
36-
</span>
26+
<span class="@character.Type.ToString().ToLower()-character"> @(ShowWhiteSpace ? character.Text.Replace(" ", spaceValue.ToString()).Trim() : character.Text.Trim())</span>
3727
}
3828
}
3929

0 commit comments

Comments
 (0)