-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
154 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@page "/profiles" | ||
@inject IAppData appData | ||
@inject NavigationManager Navigation | ||
@inject LocalStorageAccessor LocalStorageAccessor | ||
@inject IRSData irsData | ||
|
||
<PageTitle>bogle.tools profiles</PageTitle> | ||
|
||
<h1>bogle.tools profiles</h1> | ||
|
||
|
||
Profiles:<br/> | ||
<ul> | ||
|
||
@foreach(var profileName in appData.ProfileNames) | ||
{ | ||
<li><a href=/portfolio @onclick="@(e=>gotoProfile(e,profileName))" @onclick:preventDefault>@profileName</a></li> | ||
} | ||
|
||
</ul> | ||
|
||
<label>Create new profile:</label><br/> | ||
<InputText placeholder="name" @bind-Value="@newProfileName" /><button @onclick="createProfile">create</button> | ||
|
||
@code { | ||
private async Task gotoProfile(EventArgs e, string profileName) | ||
{ | ||
appData.CurrentProfileName = profileName; | ||
await ProfileUtilities.Load(appData); | ||
Navigation.NavigateTo("/portfolio"); | ||
} | ||
private async Task createProfile() | ||
{ | ||
if (!string.IsNullOrEmpty(newProfileName)) { | ||
appData.ProfileNames.Add(newProfileName); | ||
await ProfileUtilities.Save(newProfileName, new FamilyData(irsData)); | ||
newProfileName = ""; | ||
} | ||
} | ||
protected override async Task OnInitializedAsync() | ||
{ | ||
|
||
} | ||
private string newProfileName { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
public interface IAppData { | ||
public FamilyData FamilyData { get; set; } | ||
public List<string> ProfileNames {get; set;} | ||
public string CurrentProfileName {get; set;} | ||
public string CurrentProfileKey { get; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using IRS; | ||
|
||
public static class ProfileUtilities | ||
{ | ||
public static string Key { get; set; } = "localSave"; | ||
public static string Value { get; set; } = ""; | ||
public static string storedJson { get; set; } = ""; | ||
|
||
public static LocalStorageAccessor? LocalStorageAccessor { get; set; } | ||
|
||
public static async Task Save(string key, FamilyData familyData) | ||
{ | ||
var options = new JsonSerializerOptions() | ||
{ | ||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault, | ||
IgnoreReadOnlyProperties = true, | ||
WriteIndented = true, | ||
Converters = | ||
{ | ||
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) | ||
} | ||
}; | ||
var jsonOut = JsonSerializer.Serialize(familyData, options); | ||
|
||
await LocalStorageAccessor.SetValueAsync(key, jsonOut); | ||
} | ||
|
||
public static async Task Load(IAppData appData) | ||
{ | ||
try { | ||
storedJson = await LocalStorageAccessor.GetValueAsync<string>(appData.CurrentProfileKey); | ||
var options = new JsonSerializerOptions() | ||
{ | ||
Converters = | ||
{ | ||
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) | ||
} | ||
}; | ||
|
||
appData.FamilyData = FamilyData.LoadFromJson(appData.FamilyData, storedJson, options); | ||
} | ||
catch (Exception e) | ||
{ | ||
// Key + " in local storage not found...loading default." | ||
Console.WriteLine(e.GetType().Name + " " + e.Message); | ||
} | ||
} | ||
|
||
public static async Task Clear(IAppData appData, IRSData irsData) | ||
{ | ||
appData.FamilyData = new FamilyData(irsData); | ||
await LocalStorageAccessor.RemoveAsync(Key); | ||
} | ||
|
||
public static async Task ClearAllAsync() | ||
{ | ||
await LocalStorageAccessor.Clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters