Skip to content

Commit

Permalink
#383 - Refactor save methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Jun 5, 2022
1 parent a98c40b commit 2c07167
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/Money.Blazor.Host/Pages/Users/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
}
</ChildContent>
<Buttons>
<button class="btn btn-primary" @onclick="SetMobileMenuAsync">Set</button>
<button class="btn btn-primary" @onclick="(async () => { await MobileMenu.SetAsync(); MobileMenuEditor.Hide(); })">Set</button>
</Buttons>
</Modal>

Expand All @@ -88,6 +88,6 @@
</div>
</ChildContent>
<Buttons>
<button class="btn btn-primary" @onclick="SetSummarySortAsync">Set</button>
<button class="btn btn-primary" @onclick="(async () => { await SummarySort.SetAsync(); SummarySortEditor.Hide(); })">Set</button>
</Buttons>
</Modal>
28 changes: 13 additions & 15 deletions src/Money.Blazor.Host/Pages/Users/Settings.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,6 @@ private T AddProperty<T>(string name, string title, Action edit, string defaultV
return (T)viewModel;
}

protected async Task SetMobileMenuAsync()
{
MobileMenu.CurrentValue = String.Join(",", MobileMenu.AvailableModels.Where(m => MobileMenu.SelectedIdentifiers.Contains(m.Identifier)).Select(m => m.Identifier));
await MobileMenu.SetAsync();
MobileMenuEditor.Hide();
}

protected async Task SetSummarySortAsync()
{
SummarySort.CurrentValue = $"{SummarySort.Property}-{SummarySort.Direction}";
await SummarySort.SetAsync();
SummarySortEditor.Hide();
}

Task IEventHandler<UserPropertyChanged>.HandleAsync(UserPropertyChanged payload)
{
var viewModel = ViewModels.FirstOrDefault(vm => vm.Key == payload.PropertyKey);
Expand Down Expand Up @@ -154,7 +140,7 @@ public string CurrentValue
set => currentValue = value;
}

public async Task SetAsync()
public virtual async Task SetAsync()
{
Console.WriteLine($"Current '{currentValue}', ModelValue '{Model?.Value}'.");

Expand Down Expand Up @@ -187,6 +173,12 @@ public async override Task InitializeAsync()
? CurrentValue.Split(',').ToList()
: new List<string>(0);
}

public override Task SetAsync()
{
CurrentValue = String.Join(",", AvailableModels.Where(m => SelectedIdentifiers.Contains(m.Identifier)).Select(m => m.Identifier));
return base.SetAsync();
}
}

public class SortPropertyViewModel<T> : PropertyViewModel
Expand Down Expand Up @@ -214,5 +206,11 @@ public async override Task InitializeAsync()
Direction = Enum.Parse<SortDirection>(parts[1]);
}
}

public override Task SetAsync()
{
CurrentValue = $"{Property}-{Direction}";
return base.SetAsync();
}
}
}

0 comments on commit 2c07167

Please sign in to comment.