diff --git a/Pages/Profiles.razor b/Pages/Profiles.razor
index 1709474..9520ea0 100644
--- a/Pages/Profiles.razor
+++ b/Pages/Profiles.razor
@@ -10,24 +10,94 @@
Click on profile name to make it the active profile. You'll be navigated back to your prior page.
-
-
+
+
Create new profile:
-create
+➕ create
@code {
+ private ElementReference renameBox;
+
private async Task makeProfileActive(EventArgs e, string profileName)
{
appData.CurrentProfileName = profileName;
+ await LocalStorageAccessor.SetValueAsync("CurrentProfileName", profileName);
await ProfileUtilities.Load(appData);
- Navigation.NavigateTo(appData.LastPageUri);
+ if (appData.LastPageUri != null)
+ {
+ Navigation.NavigateTo(appData.LastPageUri);
+ }
+ }
+ private async Task renameProfile(EventArgs e, string profileName)
+ {
+ if (renameProfileName == null)
+ {
+ renameProfileName = profileName;
+ newName = profileName;
+ }
+ else
+ {
+ if (newName != renameProfileName && !string.IsNullOrEmpty(newName) && !appData.ProfileNames.Contains(newName))
+ {
+ await LocalStorageAccessor.RenameKey(renameProfileName, newName);
+ await ProfileUtilities.SetProfileNames(appData);
+
+ if (appData.CurrentProfileName == renameProfileName)
+ {
+ appData.CurrentProfileName = newName;
+ }
+
+ renameProfileName = null;
+ }
+ }
+ }
+ private async Task deleteProfile(EventArgs e, string profileName)
+ {
+ await LocalStorageAccessor.RemoveAsync(profileName);
+ if (appData.CurrentProfileName == profileName)
+ {
+ appData.CurrentProfileName = null;
+ appData.FamilyData = null;
+ }
+
+ await ProfileUtilities.SetProfileNames(appData);
}
private async Task createProfile()
@@ -38,9 +108,13 @@ Click on profile name to make it the active profile. You'll be navigated back to
newProfileName = "";
}
}
+
protected override async Task OnInitializedAsync()
{
}
+
private string newProfileName { get; set; }
+ private string? renameProfileName { get; set; }
+ private string? newName {get; set;}
}
\ No newline at end of file
diff --git a/Program.cs b/Program.cs
index 99b3426..d0833cb 100644
--- a/Program.cs
+++ b/Program.cs
@@ -13,11 +13,21 @@
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddScoped(sp => SearchModel.Create());
+builder.Services.AddScoped();
+var lsa = builder.Services.BuildServiceProvider().GetService();
+string? CurrentProfileName;
+try {
+ CurrentProfileName = await lsa.GetValueAsync("CurrentProfileName");
+}
+catch (Exception ex) {
+ CurrentProfileName = null;
+}
+
IRSData? irsData = await IRSData.Create(httpClient);
if (irsData != null) {
builder.Services.AddSingleton(irsData);
var appData = new AppData(new FamilyData(irsData));
- appData.CurrentProfileName = "primary";
+ appData.CurrentProfileName = CurrentProfileName;
builder.Services.AddSingleton(appData);
} else {
throw new Exception("irsData is null");
@@ -41,6 +51,4 @@
Funds.AddRange(Stocks);
builder.Services.AddSingleton>(Funds);
-builder.Services.AddScoped();
-
await builder.Build().RunAsync();
diff --git a/Shared/LocalStorageAccessor.cs b/Shared/LocalStorageAccessor.cs
index 9b8e0f5..4812188 100644
--- a/Shared/LocalStorageAccessor.cs
+++ b/Shared/LocalStorageAccessor.cs
@@ -60,4 +60,12 @@ public async Task RemoveAsync(string key)
await WaitForReference();
await _accessorJsRef.Value.InvokeVoidAsync("remove", key);
}
+
+ public async Task RenameKey(string oldName, string newName)
+ {
+ await WaitForReference();
+ var value = await GetValueAsync(oldName);
+ await SetValueAsync(newName, value);
+ await RemoveAsync(oldName);
+ }
}
\ No newline at end of file
diff --git a/Shared/Models/FamilyData/AppData.cs b/Shared/Models/FamilyData/AppData.cs
index 7f7d278..f772002 100644
--- a/Shared/Models/FamilyData/AppData.cs
+++ b/Shared/Models/FamilyData/AppData.cs
@@ -6,17 +6,6 @@ public AppData(FamilyData familyData) {
public FamilyData FamilyData { get; set; }
public List ProfileNames {get; set;}
- public string CurrentProfileName {get; set;}
+ public string? CurrentProfileName {get; set;}
public string LastPageUri {get; set;}
- public string CurrentProfileKey
- {
- get {
- switch (CurrentProfileName) {
- case "primary":
- return "localSave";
- default:
- return CurrentProfileName;
- }
- }
- }
}
\ No newline at end of file
diff --git a/Shared/Models/FamilyData/IAppData.cs b/Shared/Models/FamilyData/IAppData.cs
index ae1c1e1..6a74467 100644
--- a/Shared/Models/FamilyData/IAppData.cs
+++ b/Shared/Models/FamilyData/IAppData.cs
@@ -1,9 +1,6 @@
public interface IAppData {
public FamilyData FamilyData { get; set; }
public List ProfileNames {get; set;}
- public string CurrentProfileName {get; set;}
- public string CurrentProfileKey { get; }
+ public string? CurrentProfileName {get; set;}
public string LastPageUri {get; set;}
-
-
}
\ No newline at end of file
diff --git a/Shared/Models/ProfileUtilities.cs b/Shared/Models/ProfileUtilities.cs
index f05761c..13ab04b 100644
--- a/Shared/Models/ProfileUtilities.cs
+++ b/Shared/Models/ProfileUtilities.cs
@@ -4,7 +4,6 @@
public static class ProfileUtilities
{
- public static string Key { get; set; } = "localSave";
public static string Value { get; set; } = "";
public static string storedJson { get; set; } = "";
@@ -30,7 +29,7 @@ public static async Task Save(string key, FamilyData familyData)
public static async Task Load(IAppData appData)
{
try {
- storedJson = await LocalStorageAccessor.GetValueAsync(appData.CurrentProfileKey);
+ storedJson = await LocalStorageAccessor.GetValueAsync(appData.CurrentProfileName);
var options = new JsonSerializerOptions()
{
Converters =
@@ -48,14 +47,36 @@ public static async Task Load(IAppData appData)
}
}
- public static async Task Clear(IAppData appData, IRSData irsData)
+ public static async Task Clear(IAppData appData, string key, IRSData irsData)
{
appData.FamilyData = new FamilyData(irsData);
- await LocalStorageAccessor.RemoveAsync(Key);
+ await LocalStorageAccessor.RemoveAsync(key);
}
public static async Task ClearAllAsync()
{
await LocalStorageAccessor.Clear();
}
+
+ public static async Task SetProfileNames(IAppData appData)
+ {
+ var keys = new List();
+ var keysJsonElement = await LocalStorageAccessor.GetKeys();
+ foreach (var el in keysJsonElement.EnumerateArray())
+ {
+ string? value = el.GetString();
+ if (value != null) {
+ switch (value) {
+ case "CurrentProfileName":
+ case "i18nextLng":
+ break;
+ default:
+ keys.Add(value);
+ break;
+ }
+ }
+ }
+
+ appData.ProfileNames = keys;
+ }
}
\ No newline at end of file
diff --git a/Shared/TopLine.razor b/Shared/TopLine.razor
index 861a861..ce22041 100644
--- a/Shared/TopLine.razor
+++ b/Shared/TopLine.razor
@@ -11,41 +11,30 @@
Erase
@code{
-
private async Task Save() {
- await ProfileUtilities.Save(appData.CurrentProfileKey, appData.FamilyData);
- }
+ await ProfileUtilities.Save(appData.CurrentProfileName, appData.FamilyData);
+ }
private async Task Clear() {
- ProfileUtilities.Clear(appData, irsData);
+ ProfileUtilities.Clear(appData, appData.CurrentProfileName, irsData);
Navigation.NavigateTo("/");
}
protected override async Task OnInitializedAsync()
{
ProfileUtilities.LocalStorageAccessor = LocalStorageAccessor;
- appData.CurrentProfileName = "primary";
- await ProfileUtilities.Load(appData);
+ await ProfileUtilities.SetProfileNames(appData);
- var keys = new List();
- var keysJsonElement = await LocalStorageAccessor.GetKeys();
- foreach (var el in keysJsonElement.EnumerateArray())
+ if (appData.CurrentProfileName != null && appData.ProfileNames.Contains(appData.CurrentProfileName))
{
- string? value = el.GetString();
- if (value != null) {
- switch (value) {
- case "i18nextLng":
- break;
- case "localSave":
- keys.Add("primary");
- break;
- default:
- keys.Add(value);
- break;
- }
- }
+ await ProfileUtilities.Load(appData);
+ }
+ else
+ {
+ appData.CurrentProfileName = null;
+ await ProfileUtilities.SetProfileNames(appData);
+ appData.LastPageUri = Navigation.Uri;
+ Navigation.NavigateTo("/profiles");
}
-
- appData.ProfileNames = keys;
}
}