Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #673

Merged
merged 4 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/MatBlazor.Demo/BlazorFiddle/BaseBlazorFiddle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ protected async override Task OnFirstAfterRenderAsync()
{
await JsInvokeAsync<object>("blazorFiddle.create", Ref, new
{
Text = this.Code,
Template = this.Template,
Text = Code,
Template = Template,
});
}
catch (Exception e)
Expand Down
2 changes: 1 addition & 1 deletion src/MatBlazor.Demo/Demo/DemoFileUpload.razor
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
}
finally
{
await InvokeAsync(async () => { this.StateHasChanged(); });
await InvokeAsync(StateHasChanged);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/MatBlazor.Demo/Demo/DemoMatButton.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<h5 class="mat-h5">Example</h5>
<DemoContainer>
<Content>
@using Microsoft.AspNetCore.Components

<h4 class="mat-subtitle1">Simple use</h4>
<MatButton Icon="favorite" OnClick="@RunOnClick" Label="Simple Button"></MatButton>

Expand Down
2 changes: 1 addition & 1 deletion src/MatBlazor.Demo/Demo/DemoMatChip.razor
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
labels.Add($"Chip {counter++}");
}

private async Task OnTrailingIconClick(MatChip chip)
private void OnTrailingIconClick(MatChip chip)
{
labels.Remove(chip.Label);
chipset?.UnregisterChip(chip); // <-- to avoid memleak
Expand Down
2 changes: 0 additions & 2 deletions src/MatBlazor.Demo/Demo/DemoMatIconButton.razor
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@
<h5 class="mat-h5">Toggle Icon Button</h5>
<DemoContainer>
<Content>
@using Microsoft.AspNetCore.Components

<h5 class="mat-subtitle1">Toggled</h5>
<MatIconButton Icon="favorite_border" ToggleIcon="favorite">
</MatIconButton>
Expand Down
2 changes: 0 additions & 2 deletions src/MatBlazor.Demo/Demo/DemoMatMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@

<DemoContainer>
<Content>
@using Microsoft.AspNetCore.Components

<p>
<MatButton Label="Menu" OnClick="@OnClick2" @ref="Button2" ></MatButton>
<MatMenu @ref="Menu2" >
Expand Down
2 changes: 0 additions & 2 deletions src/MatBlazor.Demo/Demo/DemoMatNavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@
<h5 class="mat-h5">Nested Sub Menus</h5>
<DemoContainer>
<Content>
@using Microsoft.AspNetCore.Components

<div class="mat-elevation-z4" style="padding: 10px;">
<MatSlideToggle @bind-Value="MultiChecked" Label="@("Multi: " + MultiChecked)" />
<MatButton OnClick="@(() => navMenu.ToggleAllSubMenus(true))">Expand All</MatButton>
Expand Down
2 changes: 1 addition & 1 deletion src/MatBlazor.Demo/Demo/DemoVirtualScroll.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<DocVirtualScroll></DocVirtualScroll>
<DocMatVirtualScroll></DocMatVirtualScroll>

<MatH5>Example</MatH5>
<DemoContainer >
Expand Down
2 changes: 1 addition & 1 deletion src/MatBlazor.Demo/Models/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace MatBlazor.Demo.Models
{
public class AppModel
{
private object syncObj = new object();
private readonly object syncObj = new object();
private int userCount = 0;

public event EventHandler<int> UserCountChanged;
Expand Down
2 changes: 1 addition & 1 deletion src/MatBlazor.DevUtils/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public string Path
get { return System.IO.Path.GetFullPath(_path); }
}

private string _path = "../../../..";
private readonly string _path = "../../../..";

public string RepositoryPath
{
Expand Down
31 changes: 0 additions & 31 deletions src/MatBlazor.DevUtils/DemoContentGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,36 +136,5 @@ private string PrepareSourceCode(string s)
{
return $@"<BlazorFiddle Template=""MatBlazor"" Code=@(@""{s.Replace("\"", "\"\"")}"")></BlazorFiddle>";
}

private string EscapeString1(string s)
{
// XmlDocument doc = new XmlDocument();
// XmlAttribute attr = doc.CreateAttribute("attr");
// attr.InnerText = s;
// s = attr.InnerXml;
//
// s = s.Replace("\r", "&#xD;").Replace("\n", "&#xA;").Replace("\"", "&quot;");
//
// return $"<pre data=\"{s}\"></pre>";


var f = System.Uri.EscapeDataString(s);

s = HttpUtility.HtmlEncode(s);
var sb = new StringBuilder();
if (s != null)
{
foreach (var ch in s)
{
sb.Append("\\u" + ((int) ch).ToString("X4"));
}
}

s = sb.ToString();


return
$"<div style=\"white-space: pre-wrap;\">@((MarkupString) \"{s}\")</div><a href=\"https://localhost:44367/t-MatBlazor/?f={f}\">Test</a>";
}
}
}
3 changes: 1 addition & 2 deletions src/MatBlazor.DevUtils/MatThemesGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public void Generate()
{
Console.WriteLine($"{line.Groups["color"]} {line.Groups["shade"]} {line.Groups["value"]}");
var colorName = line.Groups["color"].Value;
Dictionary<string, string> c;
if (!colors.TryGetValue(colorName, out c))
if (!colors.TryGetValue(colorName, out var c))
{
c = new Dictionary<string, string>();
colors.Add(colorName, c);
Expand Down
13 changes: 5 additions & 8 deletions src/MatBlazor/Components/Base/BaseMatComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public abstract class BaseMatComponent : ComponentBase, IBaseMatComponent, IDisp
protected bool Rendered { get; private set; }


private Queue<Func<Task>> afterRenderCallQuene = new Queue<Func<Task>>();
private readonly Queue<Func<Task>> afterRenderCallQueue = new Queue<Func<Task>>();

protected void CallAfterRender(Func<Task> action)
{
afterRenderCallQuene.Enqueue(action);
afterRenderCallQueue.Enqueue(action);
}


Expand All @@ -31,10 +31,10 @@ protected async override Task OnAfterRenderAsync(bool firstRender)
await OnFirstAfterRenderAsync();
}

if (afterRenderCallQuene.Count > 0)
if (afterRenderCallQueue.Count > 0)
{
var actions = afterRenderCallQuene.ToArray();
afterRenderCallQuene.Clear();
var actions = afterRenderCallQueue.ToArray();
afterRenderCallQueue.Clear();

foreach (var action in actions)
{
Expand Down Expand Up @@ -97,9 +97,6 @@ protected async Task<T> JsInvokeAsync<T>(string code, params object[] args)
Console.WriteLine(e);
throw;
}


return default(T);
}

#region Hack to fix https: //github.com/aspnet/AspNetCore/issues/11159
Expand Down
20 changes: 3 additions & 17 deletions src/MatBlazor/Components/Base/BaseMatDomComponent.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;

namespace MatBlazor
{
Expand Down Expand Up @@ -52,27 +49,16 @@ protected BaseMatDomComponent()
/// Specifies one or more classnames for an DOM element.
/// </summary>
[Parameter]
public string Class
{
get => _class;
set { _class = value; }
}
public string Class { get; set; }


/// <summary>
/// Specifies an inline style for an DOM element.
/// </summary>
[Parameter]
public string Style
{
get => _style;
set { _style = value; }
}
public string Style { get; set; }


protected StyleMapper StyleMapper = new StyleMapper();

private string _class;
private string _style;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ protected virtual string FormatValueAsString(T value)
}

/// <summary>
/// Parses a string to create an instance of <typeparamref name="TValue"/>. Derived classes can override this to change how
/// Parses a string to create an instance of <typeparamref name="T"/>. Derived classes can override this to change how
/// <see cref="CurrentValueAsString"/> interprets incoming values.
/// </summary>
/// <param name="value">The string value to be parsed.</param>
/// <param name="result">An instance of <typeparamref name="TValue"/>.</param>
/// <param name="result">An instance of <typeparamref name="T"/>.</param>
/// <param name="validationErrorMessage">If the value could not be parsed, provides a validation error message.</param>
/// <returns>True if the value could be parsed; otherwise false.</returns>
protected virtual bool TryParseValueFromString(string value, out T result, out string validationErrorMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
CallAfterRender(async () => { await JsInvokeAsync<object>("matBlazor.matAccordion.initSummary", Ref); });
}

protected async void OnClickHandler(MouseEventArgs e)
protected void OnClickHandler(MouseEventArgs e)
{
this.ExpansionPanel.ToggleAsync();
}
Expand Down
5 changes: 4 additions & 1 deletion src/MatBlazor/Components/MatAnchor/MatAnchorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ protected override void OnInitialized()
protected override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
ScrollToAnchor(forceScroll: true);

}
return base.OnAfterRenderAsync(firstRender);
}

Expand All @@ -44,7 +45,9 @@ void OnLocationChanged(object sender, LocationChangedEventArgs args)
void ScrollToAnchor(string anchor = "", bool forceScroll = false)
{
if (!string.IsNullOrEmpty(anchor) || forceScroll)
{
JSRuntime.InvokeAsync<string>("matBlazor.matAnchor.scrollToAnchor", anchor);
}
}

void IDisposable.Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ public async void OnKeyDown(KeyboardEventArgs ev)
{
if (ev.Key == null || // google autofill sends null key
ev.Key == "Tab") // user navigates to next field
{
return;

}
var currentIndex = await ListRef.GetSelectedIndex();
var wasCurrentIndexChanged = false;

Expand Down
Loading