Skip to content

Commit

Permalink
Fix user issue
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Feb 7, 2023
1 parent 7743b38 commit 6878d13
Show file tree
Hide file tree
Showing 138 changed files with 6,446 additions and 5,657 deletions.
24 changes: 12 additions & 12 deletions samples/Blazor.ExampleConsumer/App.razor
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
36 changes: 18 additions & 18 deletions samples/Blazor.ExampleConsumer/Components/BingMap.razor
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
@inject IJSInProcessRuntime JavaScript

<div id="map" style="width: 100%; height: 45vh;"></div>

@code {
@inject IJSInProcessRuntime JavaScript

<div id="map" style="width: 100%; height: 45vh;"></div>

@code {
[Parameter, EditorRequired]
public GeolocationPosition Position { get; set; } = null!;

protected override void OnParametersSet()
{
if (Position is null or { Coords: null })
{
return;
}

JavaScript.InvokeVoid(
"app.loadMap", "map", Position.Coords.Latitude, Position.Coords.Longitude);
}
}
public GeolocationPosition Position { get; set; } = null!;

protected override void OnParametersSet()
{
if (Position is null or { Coords: null })
{
return;
}

JavaScript.InvokeVoid(
"app.loadMap", "map", Position.Coords.Latitude, Position.Coords.Longitude);
}
}
56 changes: 28 additions & 28 deletions samples/Blazor.ExampleConsumer/Components/Code.razor
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
@typeparam T where T : class

@if (Value is not null)
{
<pre class="bg-dark @(_textClass) fs-4 p-4">
<code>
@{
var opts = new JsonSerializerOptions()
{
WriteIndented = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
}
@Value?.ToJson(opts)
</code>
</pre>
}

@code {
[Parameter, EditorRequired]
public T? Value { get; set; } = default!;

[Parameter]
public bool IsError { get; set; }

string _textClass => IsError ? "text-warning" : "text-info";
}
@typeparam T where T : class

@if (Value is not null)
{
<pre class="bg-dark @(_textClass) fs-4 p-4">
<code>
@{
var opts = new JsonSerializerOptions()
{
WriteIndented = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
}
@Value?.ToJson(opts)
</code>
</pre>
}

@code {
[Parameter, EditorRequired]
public T? Value { get; set; } = default!;

[Parameter]
public bool IsError { get; set; }

string _textClass => IsError ? "text-warning" : "text-info";
}
64 changes: 32 additions & 32 deletions samples/Blazor.ExampleConsumer/Components/StorageCheckbox.razor
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
@inject ILocalStorageService LocalStorage

<label class="ps-2 fs-5 selectable flex-fill" for="@Item.Id">
<input type="checkbox" class="form-check-input"
value=@Item.IsCompleted
checked=@Item.IsCompleted
id="@Item.Id" @onchange=@OnIsCompletedChanged />
<span class="ps-3">@Item.Task</span>
</label>
@if (EndContent is not null)
{
@EndContent
}

@code {
@inject ILocalStorageService LocalStorage

<label class="ps-2 fs-5 selectable flex-fill" for="@Item.Id">
<input type="checkbox" class="form-check-input"
value=@Item.IsCompleted
checked=@Item.IsCompleted
id="@Item.Id" @onchange=@OnIsCompletedChanged />
<span class="ps-3">@Item.Task</span>
</label>
@if (EndContent is not null)
{
@EndContent
}

@code {
[Parameter, EditorRequired]
public TodoItem Item { get; set; } = null!;

[Parameter]
[Parameter]
public RenderFragment EndContent { get; set; } = null!;

[Parameter]
public EventCallback<TodoItem> ItemChanged { get; set; }

Task OnIsCompletedChanged(ChangeEventArgs args)
{
if (bool.TryParse(args?.Value?.ToString(), out var isCompleted))
{
LocalStorage.SetItem(
Item.Id,
Item = Item with { IsCompleted = isCompleted });

if (ItemChanged.HasDelegate)
{
return ItemChanged.InvokeAsync(Item);
}
}

return Task.CompletedTask;
}
Task OnIsCompletedChanged(ChangeEventArgs args)
{
if (bool.TryParse(args?.Value?.ToString(), out var isCompleted))
{
LocalStorage.SetItem(
Item.Id,
Item = Item with { IsCompleted = isCompleted });

if (ItemChanged.HasDelegate)
{
return ItemChanged.InvokeAsync(Item);
}
}

return Task.CompletedTask;
}
}
16 changes: 8 additions & 8 deletions samples/Blazor.ExampleConsumer/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License.

global using System.Text.Json;
global using System.Text.Json.Serialization;
global using Microsoft.JSInterop;
global using Microsoft.AspNetCore.Components;
global using static System.Globalization.CultureInfo;
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License.

global using System.Text.Json;
global using System.Text.Json.Serialization;
global using Microsoft.JSInterop;
global using Microsoft.AspNetCore.Components;
global using static System.Globalization.CultureInfo;
40 changes: 20 additions & 20 deletions samples/Blazor.ExampleConsumer/Models/TodoItem.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License.

using System.Text.RegularExpressions;

namespace Blazor.ExampleConsumer.Models;

public partial record class TodoItem(
string Task,
bool IsCompleted)
{
internal const string IdPrefix = "todo";

[JsonIgnore]
public string Id =>
$"{IdPrefix}{AlphabetOrDigitRegex().Replace(Task, "")}";

[GeneratedRegex("[^a-zA-Z0-9]")]
private static partial Regex AlphabetOrDigitRegex();
}
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License.

using System.Text.RegularExpressions;

namespace Blazor.ExampleConsumer.Models;

public partial record class TodoItem(
string Task,
bool IsCompleted)
{
internal const string IdPrefix = "todo";

[JsonIgnore]
public string Id =>
$"{IdPrefix}{AlphabetOrDigitRegex().Replace(Task, "")}";

[GeneratedRegex("[^a-zA-Z0-9]")]
private static partial Regex AlphabetOrDigitRegex();
}
74 changes: 37 additions & 37 deletions samples/Blazor.ExampleConsumer/Pages/ClientPosition.razor
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
@page "/geolocation"

@inject IGeolocationService Geolocation

<PageTitle>Geolocation</PageTitle>
<h1>
Geolocation
@if (_isLoading)
{
<span class="spinner-border text-primary" style="border-width: .12em;" role="status">
<span class="visually-hidden">Loading...</span>
</span>
}
@if (_position is not null)
{
<span class="pe-1">:
<code>
@(_position.TimestampAsUtcDateTime.ToLocalTime().ToString())
</code>
</span>
<a href="https://www.nuget.org/packages/Blazor.LocalStorage.WebAssembly" target="_blank"
rel="noopener noreferrer nofollow">
<span class="oi oi-external-link"></span>
</a>
}
</h1>

@if (_isLoading)
{
<p>This page demonstrates the source generated <code>Blazor.Geolocation.WebAssembly</code> package.</p>
}

@{
<Code Value=@_position T=GeolocationPosition IsError=false />
<Code Value=@_positionError T=GeolocationPositionError IsError=true />

<BingMap Position=@_position />
@page "/geolocation"

@inject IGeolocationService Geolocation

<PageTitle>Geolocation</PageTitle>
<h1>
Geolocation
@if (_isLoading)
{
<span class="spinner-border text-primary" style="border-width: .12em;" role="status">
<span class="visually-hidden">Loading...</span>
</span>
}
@if (_position is not null)
{
<span class="pe-1">:
<code>
@(_position.TimestampAsUtcDateTime.ToLocalTime().ToString())
</code>
</span>
<a href="https://www.nuget.org/packages/Blazor.LocalStorage.WebAssembly" target="_blank"
rel="noopener noreferrer nofollow">
<span class="oi oi-external-link"></span>
</a>
}
</h1>

@if (_isLoading)
{
<p>This page demonstrates the source generated <code>Blazor.Geolocation.WebAssembly</code> package.</p>
}

@{
<Code Value=@_position T=GeolocationPosition IsError=false />
<Code Value=@_positionError T=GeolocationPositionError IsError=true />

<BingMap Position=@_position />
}
Loading

0 comments on commit 6878d13

Please sign in to comment.