From a7662f699e4d122762fa5d98197384d3fd69f834 Mon Sep 17 00:00:00 2001 From: Nicolas FRANCO Date: Fri, 18 Nov 2022 11:10:21 +0100 Subject: [PATCH] modal error --- BlazorTp1/Pages/_Layout.cshtml | 72 +++++++++++++------------- BlazorTp1/Program.cs | 10 ++-- BlazorTp1/Services/DataLocalService.cs | 10 ++++ 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/BlazorTp1/Pages/_Layout.cshtml b/BlazorTp1/Pages/_Layout.cshtml index ea9b1bb..10372ee 100644 --- a/BlazorTp1/Pages/_Layout.cshtml +++ b/BlazorTp1/Pages/_Layout.cshtml @@ -4,40 +4,40 @@ - - - - - - - - - - - @RenderBody() - -
- - An error has occurred. This application may no longer respond until reloaded. - - - An unhandled exception has occurred. See browser dev tools for details. - - Reload - 🗙 -
- - - - - - - - - - - - - - + + + + + + + + + + + + @RenderBody() + +
+ + An error has occurred. This application may no longer respond until reloaded. + + + An unhandled exception has occurred. See browser dev tools for details. + + Reload + 🗙 +
+ + + + + + + + + + + + + diff --git a/BlazorTp1/Program.cs b/BlazorTp1/Program.cs index e3cd109..97cb8f6 100644 --- a/BlazorTp1/Program.cs +++ b/BlazorTp1/Program.cs @@ -1,14 +1,12 @@ using Blazored.LocalStorage; +using Blazored.Modal; using Blazorise; using Blazorise.Bootstrap; using Blazorise.Icons.FontAwesome; using BlazorTp1.Data; -using Blazored.Modal; -using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Localization; -using System.Globalization; using Microsoft.Extensions.Options; +using System.Globalization; var builder = WebApplication.CreateBuilder(args); @@ -19,6 +17,8 @@ builder.Services.AddSingleton(); builder.Services.AddHttpClient(); +builder.Services.AddBlazoredModal(); + builder.Services .AddBlazorise() .AddBootstrapProviders() @@ -28,8 +28,6 @@ builder.Services.AddBlazoredLocalStorage(); builder.Services.AddScoped(); -builder.Services.AddBlazoredModal(); - // Add the controller of the app builder.Services.AddControllers(); diff --git a/BlazorTp1/Services/DataLocalService.cs b/BlazorTp1/Services/DataLocalService.cs index 13f109d..9154eb7 100644 --- a/BlazorTp1/Services/DataLocalService.cs +++ b/BlazorTp1/Services/DataLocalService.cs @@ -55,6 +55,16 @@ public class DataLocalService : IDataService public async Task Count() { + // Load data from the local storage + var currentData = await _localStorage.GetItemAsync("data"); + + // Check if data exist in the local storage + if (currentData == null) + { + // this code add in the local storage the fake data + var originalData = await _http.GetFromJsonAsync($"{_navigationManager.BaseUri}fake-data.json"); + await _localStorage.SetItemAsync("data", originalData); + } return (await _localStorage.GetItemAsync("data")).Length; }