From fd7bb93be5183bbf0bca9d9a9be75a3c2b795b84 Mon Sep 17 00:00:00 2001 From: David Pine Date: Tue, 10 Jan 2023 18:33:39 -0600 Subject: [PATCH] Add server sample app, fix watch position bug, and fix publish nuget bug. --- .github/workflows/publish-nuget.yml | 2 +- blazorators.sln | 9 +- .../Blazor.ExampleConsumer/Pages/Track.razor | 38 ++ .../Pages/Track.razor.cs | 50 ++ .../Shared/NavMenu.razor | 5 + .../BlazorServer.ExampleConsumer/App.razor | 12 + .../BlazorServer.ExampleConsumer.csproj | 18 + .../Data/WeatherForecast.cs | 15 + .../Data/WeatherForecastService.cs | 22 + .../Pages/Counter.razor | 18 + .../Pages/Error.cshtml | 42 ++ .../Pages/Error.cshtml.cs | 28 + .../Pages/FetchData.razor | 47 ++ .../Pages/Index.razor | 9 + .../Pages/_Host.cshtml | 34 ++ .../BlazorServer.ExampleConsumer/Program.cs | 38 ++ .../Shared/MainLayout.razor | 19 + .../Shared/MainLayout.razor.css | 70 +++ .../Shared/NavMenu.razor | 39 ++ .../Shared/NavMenu.razor.css | 68 +++ .../Shared/SurveyPrompt.razor | 16 + .../_Imports.razor | 10 + .../appsettings.Development.json | 9 + .../appsettings.json | 9 + .../wwwroot/css/bootstrap/bootstrap.min.css | 7 + .../css/bootstrap/bootstrap.min.css.map | 1 + .../wwwroot/css/open-iconic/FONT-LICENSE | 86 +++ .../wwwroot/css/open-iconic/ICON-LICENSE | 21 + .../wwwroot/css/open-iconic/README.md | 114 ++++ .../font/css/open-iconic-bootstrap.min.css | 1 + .../open-iconic/font/fonts/open-iconic.eot | Bin 0 -> 28196 bytes .../open-iconic/font/fonts/open-iconic.otf | Bin 0 -> 20996 bytes .../open-iconic/font/fonts/open-iconic.svg | 543 ++++++++++++++++++ .../open-iconic/font/fonts/open-iconic.ttf | Bin 0 -> 28028 bytes .../open-iconic/font/fonts/open-iconic.woff | Bin 0 -> 14984 bytes .../wwwroot/css/site.css | 68 +++ .../wwwroot/favicon.png | Bin 0 -> 1148 bytes .../wwwroot/blazorators.geolocation.g.js | 2 - .../wwwroot/blazorators.geolocation.g.js | 2 - 39 files changed, 1466 insertions(+), 6 deletions(-) create mode 100644 samples/Blazor.ExampleConsumer/Pages/Track.razor create mode 100644 samples/Blazor.ExampleConsumer/Pages/Track.razor.cs create mode 100644 samples/BlazorServer.ExampleConsumer/App.razor create mode 100644 samples/BlazorServer.ExampleConsumer/BlazorServer.ExampleConsumer.csproj create mode 100644 samples/BlazorServer.ExampleConsumer/Data/WeatherForecast.cs create mode 100644 samples/BlazorServer.ExampleConsumer/Data/WeatherForecastService.cs create mode 100644 samples/BlazorServer.ExampleConsumer/Pages/Counter.razor create mode 100644 samples/BlazorServer.ExampleConsumer/Pages/Error.cshtml create mode 100644 samples/BlazorServer.ExampleConsumer/Pages/Error.cshtml.cs create mode 100644 samples/BlazorServer.ExampleConsumer/Pages/FetchData.razor create mode 100644 samples/BlazorServer.ExampleConsumer/Pages/Index.razor create mode 100644 samples/BlazorServer.ExampleConsumer/Pages/_Host.cshtml create mode 100644 samples/BlazorServer.ExampleConsumer/Program.cs create mode 100644 samples/BlazorServer.ExampleConsumer/Shared/MainLayout.razor create mode 100644 samples/BlazorServer.ExampleConsumer/Shared/MainLayout.razor.css create mode 100644 samples/BlazorServer.ExampleConsumer/Shared/NavMenu.razor create mode 100644 samples/BlazorServer.ExampleConsumer/Shared/NavMenu.razor.css create mode 100644 samples/BlazorServer.ExampleConsumer/Shared/SurveyPrompt.razor create mode 100644 samples/BlazorServer.ExampleConsumer/_Imports.razor create mode 100644 samples/BlazorServer.ExampleConsumer/appsettings.Development.json create mode 100644 samples/BlazorServer.ExampleConsumer/appsettings.json create mode 100644 samples/BlazorServer.ExampleConsumer/wwwroot/css/bootstrap/bootstrap.min.css create mode 100644 samples/BlazorServer.ExampleConsumer/wwwroot/css/bootstrap/bootstrap.min.css.map create mode 100644 samples/BlazorServer.ExampleConsumer/wwwroot/css/open-iconic/FONT-LICENSE create mode 100644 samples/BlazorServer.ExampleConsumer/wwwroot/css/open-iconic/ICON-LICENSE create mode 100644 samples/BlazorServer.ExampleConsumer/wwwroot/css/open-iconic/README.md create mode 100644 samples/BlazorServer.ExampleConsumer/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css create mode 100644 samples/BlazorServer.ExampleConsumer/wwwroot/css/open-iconic/font/fonts/open-iconic.eot create mode 100644 samples/BlazorServer.ExampleConsumer/wwwroot/css/open-iconic/font/fonts/open-iconic.otf create mode 100644 samples/BlazorServer.ExampleConsumer/wwwroot/css/open-iconic/font/fonts/open-iconic.svg create mode 100644 samples/BlazorServer.ExampleConsumer/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf create mode 100644 samples/BlazorServer.ExampleConsumer/wwwroot/css/open-iconic/font/fonts/open-iconic.woff create mode 100644 samples/BlazorServer.ExampleConsumer/wwwroot/css/site.css create mode 100644 samples/BlazorServer.ExampleConsumer/wwwroot/favicon.png diff --git a/.github/workflows/publish-nuget.yml b/.github/workflows/publish-nuget.yml index 2ee828c..fe5fdfd 100644 --- a/.github/workflows/publish-nuget.yml +++ b/.github/workflows/publish-nuget.yml @@ -28,7 +28,7 @@ jobs: run: | dotnet test ./tests/Blazor.ExampleConsumer.EndToEndTests/Blazor.ExampleConsumer.EndToEndTests.csproj --verbosity normal -publish: + publish: needs: test runs-on: ubuntu-latest strategy: diff --git a/blazorators.sln b/blazorators.sln index b56da90..ee146a1 100644 --- a/blazorators.sln +++ b/blazorators.sln @@ -54,7 +54,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.SpeechRecognition", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Permissions.WebAssembly", "src\Blazor.Permissions.WebAssembly\Blazor.Permissions.WebAssembly.csproj", "{FD387378-9B27-4852-8A77-684C33FDE844}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazor.ExampleConsumer.EndToEndTests", "tests\Blazor.ExampleConsumer.EndToEndTests\Blazor.ExampleConsumer.EndToEndTests.csproj", "{4D04B168-6971-4660-BC22-FA7F18150018}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.ExampleConsumer.EndToEndTests", "tests\Blazor.ExampleConsumer.EndToEndTests\Blazor.ExampleConsumer.EndToEndTests.csproj", "{4D04B168-6971-4660-BC22-FA7F18150018}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorServer.ExampleConsumer", "samples\BlazorServer.ExampleConsumer\BlazorServer.ExampleConsumer.csproj", "{31D54C48-6325-4591-8612-87A917D49028}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -126,6 +128,10 @@ Global {4D04B168-6971-4660-BC22-FA7F18150018}.Debug|Any CPU.Build.0 = Debug|Any CPU {4D04B168-6971-4660-BC22-FA7F18150018}.Release|Any CPU.ActiveCfg = Release|Any CPU {4D04B168-6971-4660-BC22-FA7F18150018}.Release|Any CPU.Build.0 = Release|Any CPU + {31D54C48-6325-4591-8612-87A917D49028}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {31D54C48-6325-4591-8612-87A917D49028}.Debug|Any CPU.Build.0 = Debug|Any CPU + {31D54C48-6325-4591-8612-87A917D49028}.Release|Any CPU.ActiveCfg = Release|Any CPU + {31D54C48-6325-4591-8612-87A917D49028}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -147,6 +153,7 @@ Global {7FB98CAE-0CDB-4EF8-B9BB-6C51D62252CD} = {537EB83C-6982-40B0-801A-479DF3B17DBE} {FD387378-9B27-4852-8A77-684C33FDE844} = {537EB83C-6982-40B0-801A-479DF3B17DBE} {4D04B168-6971-4660-BC22-FA7F18150018} = {A644CEC3-BD94-4EB6-9BF0-86B562806BF9} + {31D54C48-6325-4591-8612-87A917D49028} = {91A35318-B03F-4D41-AE18-2C21B9D9C3F3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3F86284A-32D2-4F79-B23C-7A0CB8775971} diff --git a/samples/Blazor.ExampleConsumer/Pages/Track.razor b/samples/Blazor.ExampleConsumer/Pages/Track.razor new file mode 100644 index 0000000..671f86d --- /dev/null +++ b/samples/Blazor.ExampleConsumer/Pages/Track.razor @@ -0,0 +1,38 @@ +@page "/track" + +@inject IGeolocationService Geolocation + +Geolocation +

+ Geolocation + @if (_isLoading) + { + + Loading... + + } + @if (_position is not null) + { + : + + @(_position.TimestampAsUtcDateTime.ToLocalTime().ToString()) + + + + + + } +

+ +@if (_isLoading) +{ +

This page demonstrates the source generated Blazor.Geolocation.WebAssembly package.

+} + +@{ + + + + +} \ No newline at end of file diff --git a/samples/Blazor.ExampleConsumer/Pages/Track.razor.cs b/samples/Blazor.ExampleConsumer/Pages/Track.razor.cs new file mode 100644 index 0000000..08c58a3 --- /dev/null +++ b/samples/Blazor.ExampleConsumer/Pages/Track.razor.cs @@ -0,0 +1,50 @@ +// Copyright (c) David Pine. All rights reserved. +// Licensed under the MIT License. + +namespace Blazor.ExampleConsumer.Pages; + +public partial class Track : IDisposable +{ + readonly JsonSerializerOptions _opts = new() + { + WriteIndented = true, + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull + }; + readonly PositionOptions _options = new() + { + EnableHighAccuracy = true, + MaximumAge = null, + Timeout = 15_000 + }; + + GeolocationPosition? _position; + GeolocationPositionError? _positionError; + double _watchId; + bool _isLoading = true; + + protected override void OnInitialized() => + _watchId = Geolocation.WatchPosition( + component: this, + onSuccessCallbackMethodName: nameof(OnPositionRecieved), + onErrorCallbackMethodName: nameof(OnPositionError), + options: _options); + + [JSInvokable] + public void OnPositionRecieved(GeolocationPosition position) + { + _isLoading = false; + _position = position; + StateHasChanged(); + } + + [JSInvokable] + public void OnPositionError(GeolocationPositionError positionError) + { + _isLoading = false; + _positionError = positionError; + StateHasChanged(); + } + + public void Dispose() => Geolocation.ClearWatch(_watchId); +} diff --git a/samples/Blazor.ExampleConsumer/Shared/NavMenu.razor b/samples/Blazor.ExampleConsumer/Shared/NavMenu.razor index 2411876..c60ba28 100644 --- a/samples/Blazor.ExampleConsumer/Shared/NavMenu.razor +++ b/samples/Blazor.ExampleConsumer/Shared/NavMenu.razor @@ -37,6 +37,11 @@ Speech-to-text +