Skip to content

Commit

Permalink
Fix items
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Apr 26, 2023
1 parent 27f3b06 commit ee807d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions samples/Blazor.ExampleConsumer/Models/TodoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ namespace Blazor.ExampleConsumer.Models;
public partial record class TodoItem(
string Task,
bool IsCompleted)
{
{
internal const string IdPrefix = "todo";

[JsonIgnore]
public string Id =>
$"{IdPrefix}{AlphabetOrDigitRegex().Replace(Task, "")}";
Task is null
? "<Id>"
: $"{IdPrefix}{AlphabetOrDigitRegex().Replace(Task, "")}";

[GeneratedRegex("[^a-zA-Z0-9]")]
private static partial Regex AlphabetOrDigitRegex();
Expand Down
4 changes: 2 additions & 2 deletions samples/Blazor.ExampleConsumer/Pages/TodoList.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ void UpdateTodoItems()

foreach (var key in GetLocalStorageKeys())
{
if (TryGet(key, out TodoItem? todo))
if (TryGet(key, out TodoItem? todo) && todo is not null)
{
_localStorageItems[key] = todo.ToString();
continue;
}
if (TryGet(key, out string? @string))
if (TryGet(key, out string? @string) && @string is not null)
{
_localStorageItems[key] = @string;
continue;
Expand Down

0 comments on commit ee807d4

Please sign in to comment.