Skip to content

Commit

Permalink
#115 - Update blazor application.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Apr 2, 2020
1 parent 198cf15 commit f5b9861
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 299 deletions.
12 changes: 6 additions & 6 deletions src/Recollections.Blazor.Components/Components/MapInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,34 @@ public MapInterop(IJSRuntime jsRuntime)
public ValueTask InitializeAsync(Map editor)
{
this.editor = editor;
return jsRuntime.InvokeVoidAsync("Map.Initialize", editor.Container, DotNetObjectReference.Create(this), editor.Markers, editor.IsZoomed, editor.IsResizable);
return jsRuntime.InvokeVoidAsync("MapInterop.Initialize", editor.Container, DotNetObjectReference.Create(this), editor.Markers, editor.IsZoomed, editor.IsResizable);
}

[JSInvokable("Map.MarkerMoved")]
[JSInvokable("MapInterop.MarkerMoved")]
public void MarkerMoved(int? index, double latitude, double longitude, double? altitude)
=> editor.MoveMarker(index, latitude, longitude, altitude);

[JSInvokable("Map.MarkerSelected")]
[JSInvokable("MapInterop.MarkerSelected")]
public void MarkerSelected(int index) => editor.MarkerSelected?.Invoke(index);

private TaskCompletionSource<IEnumerable<MapSearchModel>> searchCompletion;

public Task<IEnumerable<MapSearchModel>> SearchAsync(string searchQuery)
{
searchCompletion = new TaskCompletionSource<IEnumerable<MapSearchModel>>();
_ = jsRuntime.InvokeVoidAsync("Map.Search", editor.Container, searchQuery);
_ = jsRuntime.InvokeVoidAsync("MapInterop.Search", editor.Container, searchQuery);

return searchCompletion.Task;
}

[JSInvokable("Map.SearchCompleted")]
[JSInvokable("MapInterop.SearchCompleted")]
public void SearchCompleted(IEnumerable<MapSearchModel> results)
{
searchCompletion.TrySetResult(results);
searchCompletion = null;
}

public ValueTask CenterAtAsync(double latitude, double longitude)
=> jsRuntime.InvokeVoidAsync("Map.CenterAt", editor.Container, latitude, longitude);
=> jsRuntime.InvokeVoidAsync("MapInterop.CenterAt", editor.Container, latitude, longitude);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,24 @@
<RootNamespace>Neptuo.Recollections</RootNamespace>

<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>7.3</LangVersion>
<RazorLangVersion>3.0</RazorLangVersion>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommonMark.NET" Version="0.15.1" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.2.0-preview1.20073.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview3.20168.3" />
<PackageReference Include="Neptuo" Version="6.0.1" />
<PackageReference Include="Neptuo.Exceptions" Version="1.2.1" />
</ItemGroup>

<ItemGroup>
<Compile Update="**\*.razor.cs" DependentUpon="%(Filename)" />
<Watch Include="**\*.razor" />
</ItemGroup>

<ItemGroup>
<Watch Remove="Components\_Imports.razor" />
<ProjectReference Include="..\Recollections.Api.Shared\Recollections.Api.Shared.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Recollections.Api.Shared\Recollections.Api.Shared.csproj" />
<Compile Update="**\*.razor.cs" DependentUpon="%(Filename)" />
<Watch Include="**\*.razor" />
</ItemGroup>

</Project>
4 changes: 3 additions & 1 deletion src/Recollections.Blazor.UI/HttpClientProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public static class HttpClientFactoryServiceCollectionExtensions
public static IServiceCollection AddHttpClientFactory(this IServiceCollection services)
{
Ensure.NotNull(services, "services");
return services.AddSingleton<IFactory<HttpClient>, HttpClientProvider>();
return services
.AddBaseAddressHttpClient()
.AddSingleton<IFactory<HttpClient>, HttpClientProvider>();
}
}
}
2 changes: 1 addition & 1 deletion src/Recollections.Blazor.UI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Blazor.Hosting;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Neptuo.Events;
using Neptuo.Recollections.Accounts;
Expand Down
57 changes: 18 additions & 39 deletions src/Recollections.Blazor.UI/Recollections.Blazor.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,19 @@
<VersionPrefix>0.7.0</VersionPrefix>

<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>7.3</LangVersion>
<RazorLangVersion>3.0</RazorLangVersion>
<RestoreAdditionalProjectSources>
https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json;
https://dotnet.myget.org/F/blazor-dev/api/v3/index.json;
</RestoreAdditionalProjectSources>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'!='Release'">
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
</PropertyGroup>

<PropertyGroup>
<ManifestShortName>Recollections</ManifestShortName>
<ManifestLongName>Recollections by Neptuo</ManifestLongName>

<ServiceWorkerFileName>service-worker.js</ServiceWorkerFileName>
<ServiceWorkerRegisterFileName>service-worker-register.js</ServiceWorkerRegisterFileName>
<ServiceWorkerForce>true</ServiceWorkerForce>
<ServiceWorkerCacheVersion Condition="'$(Configuration)' == 'Debug'">0.0.$([System.DateTime]::Now.Ticks)</ServiceWorkerCacheVersion>
<ServiceWorkerCacheVersion Condition="'$(Configuration)' == 'Release'">$(Version)</ServiceWorkerCacheVersion>
<ServiceWorkerRegisterInstallableType>installable-blazor</ServiceWorkerRegisterInstallableType>
<ServiceWorkerBlazorInstallMethod>Pwa.Installable</ServiceWorkerBlazorInstallMethod>
<ServiceWorkerRegisterUpdateType>update-blazor</ServiceWorkerRegisterUpdateType>
</PropertyGroup>

<Target Name="PWACustomise" BeforeTargets="CreatePWA">
<PropertyGroup>
<ServiceWorkerPreCacheExcludeFiles>
$(WWWRoot)**\*.scss;
</ServiceWorkerPreCacheExcludeFiles>
</PropertyGroup>
<Message Importance="high" Text="Removing: $(ServiceWorkerPreCacheExcludeFiles)" />
</Target>

<ItemGroup>
<PackageReference Include="BlazorPWA.MSBuild" Version="1.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.2.0-preview1.20073.1" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.2.0-preview1.20073.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview2.20160.5" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.2.0-preview1.20073.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview3.20168.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview3.20168.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview3.20168.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview3.20168.3" PrivateAssets="all" />
<PackageReference Include="Neptuo" Version="6.0.1" />
<PackageReference Include="Neptuo.Events" Version="1.3.1" />
<PackageReference Include="Neptuo.Exceptions" Version="1.2.1" />
Expand All @@ -58,12 +28,21 @@
<ProjectReference Include="..\Recollections.Blazor.Components\Recollections.Blazor.Components.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="wwwroot\index.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<!-- PWA -->
<PropertyGroup>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
</PropertyGroup>
<ItemGroup Condition="'$(DesignTimeBuild)' != 'true'">
<!-- When publishing, swap service-worker.published.js in place of service-worker.js -->
<Content Remove="wwwroot\service-worker.js" />
<Content Update="wwwroot\service-worker.published.js" Link="wwwroot\service-worker.js" />
</ItemGroup>

<ItemGroup>
<Content Update="wwwroot\index.html" CopyToOutputDirectory="PreserveNewest" />
<Content Remove="**\*.svg" />
<Compile Update="**\*.razor.cs" DependentUpon="%(Filename)" />
<None Update="**\*.json.defaults" DependentUpon="%(Filename)" />
<Watch Include="**\*.razor" />
</ItemGroup>
</Project>
11 changes: 6 additions & 5 deletions src/Recollections.Blazor.UI/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="theme-color" content="#343A40" />

<title>Recollections</title>
<base href="/" />
<link href="/manifest.json" rel="manifest" />
<link rel="icon" href="/img/logo.png" type="image/png" />
<meta name="theme-color" content="#343A40" />

<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="css/bootstrap-datepicker/bootstrap-datepicker.min.css" rel="stylesheet" />
<link href="css/open-iconic/css/open-iconic-bootstrap.min.css" rel="stylesheet" />
<link href="css/easymde/easymde.min.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro&display=swap" rel="stylesheet">
<link href="css/site.css" rel="stylesheet" />
<title>Recollections</title>
<link href="/manifest.json" rel="manifest" />
</head>
<body>
<app>
Expand All @@ -26,8 +28,6 @@
</div>
</app>

<script src="service-worker-register.js"></script>
<script src="service-worker-update.js"></script>
<script src="js/jquery/jquery.min.js"></script>
<script src="js/popper/popper.min.js"></script>
<script src="js/bootstrap/bootstrap.min.js"></script>
Expand All @@ -38,5 +38,6 @@
<script type="text/javascript" src="https://api.mapy.cz/loader.js"></script>
<script type="text/javascript">Loader.load();</script>
<script src="js/site.js"></script>
<script src="/service-worker.register.js"></script>
</body>
</html>
14 changes: 7 additions & 7 deletions src/Recollections.Blazor.UI/wwwroot/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ window.Downloader = {
}
};

window.Map = {
window.MapInterop = {
Initialize: function (container, interop, markers, isZoomed, isResizable) {
var model = null;

Expand Down Expand Up @@ -366,11 +366,11 @@ window.Map = {
};
$container.data('map', model);

Map._BindEvents(model);
MapInterop._BindEvents(model);
}

model = $container.data('map');
var points = Map._SetMarkers(model, markers);
var points = MapInterop._SetMarkers(model, markers);

model.isAdding = false;
model.isEmptyPoint = points.length == 0 && !model.isAdditive;
Expand All @@ -383,7 +383,7 @@ window.Map = {
model.map.setCursor("move");
if (!isZoomed) {
var centerZoom = model.map.computeCenterZoom(points);
centerZoom[1] = Map._EnsureMaxCenterZoom(centerZoom[1]);
centerZoom[1] = MapInterop._EnsureMaxCenterZoom(centerZoom[1]);
model.map.setCenterZoom(centerZoom[0], centerZoom[1]);
}
}
Expand Down Expand Up @@ -424,15 +424,15 @@ window.Map = {

function markerClick(e) {
var id = Number.parseInt(e.target.getId());
model.interop.invokeMethodAsync("Map.MarkerSelected", id);
model.interop.invokeMethodAsync("MapInterop.MarkerSelected", id);
}

function moveMarkerOnCoords(id, coords) {
var latitude = coords.y;
var longitude = coords.x;

coords.getAltitude().then(function (altitude) {
model.interop.invokeMethodAsync("Map.MarkerMoved", id, latitude, longitude, altitude);
model.interop.invokeMethodAsync("MapInterop.MarkerMoved", id, latitude, longitude, altitude);
});
}

Expand Down Expand Up @@ -496,7 +496,7 @@ window.Map = {
});
}

model.interop.invokeMethodAsync("Map.SearchCompleted", data);
model.interop.invokeMethodAsync("MapInterop.SearchCompleted", data);
});
},
CenterAt: function (container, latitude, longitude) {
Expand Down
62 changes: 0 additions & 62 deletions src/Recollections.Blazor.UI/wwwroot/service-worker-register.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/Recollections.Blazor.UI/wwwroot/service-worker-update.js

This file was deleted.

Loading

0 comments on commit f5b9861

Please sign in to comment.