Skip to content

Commit

Permalink
#412 - Duplicate expense from overview.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Jun 3, 2022
1 parent 05e7582 commit 26329ca
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/Money.Blazor.Host/Components/ExpenseCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<div class="col-12 col-sm-auto controls text-right">
@if (Context.HasEdit)
{
<IconButton Icon="clone" ToolTip="Duplicate" Click="@OnDuplicate" />
<IconButton Icon="dollar-sign" ToolTip="Change Amount" Click="@OnEditAmount" />
<IconButton Icon="comment" ToolTip="Change Description" Click="@OnEditDescription" />
<IconButton Icon="calendar" ToolTip="Change When" Click="@OnEditWhen" />
Expand Down
4 changes: 4 additions & 0 deletions src/Money.Blazor.Host/Components/ExpenseCard.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface IContext

CurrencyFormatter CurrencyFormatter { get; }

void Duplicate(OutcomeOverviewModel model);
void EditAmount(OutcomeOverviewModel model);
void EditDescription(OutcomeOverviewModel model);
void EditWhen(OutcomeOverviewModel model);
Expand All @@ -46,6 +47,9 @@ protected override async Task OnParametersSetAsync()
CategoryColor = await Queries.QueryAsync(new GetCategoryColor(Model.CategoryKey));
}

protected void OnDuplicate()
=> Context.Duplicate(Model);

protected void OnEditAmount()
=> Context.EditAmount(Model);

Expand Down
1 change: 1 addition & 0 deletions src/Money.Blazor.Host/Components/ExpenseCardContext.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
<OutcomeAmount @ref="AmountEditModal" OutcomeKey="@SelectedItem?.Key" Amount="@(SelectedItem?.Amount?.Value ?? 0)" Currency="@SelectedItem?.Amount?.Currency" />
<OutcomeDescription @ref="DescriptionEditModal" OutcomeKey="@SelectedItem?.Key" Description="@SelectedItem?.Description" />
<OutcomeWhen @ref="WhenEditModal" OutcomeKey="@SelectedItem?.Key" When="@(SelectedItem?.When ?? DateTime.MinValue)" />
<OutcomeCreate @ref="DuplicateModal" Amount="@(SelectedItem?.Amount?.Value ?? 0)" Currency="@SelectedItem?.Amount?.Currency" When="@(SelectedItem?.When ?? DateTime.Today)" Description="@SelectedItem?.Description" />
13 changes: 11 additions & 2 deletions src/Money.Blazor.Host/Components/ExpenseCardContext.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public partial class ExpenseCardContext : ExpenseCard.IContext

bool ExpenseCard.IContext.HasEdit => true;

void ExpenseCard.IContext.Duplicate(OutcomeOverviewModel model)
=> OnActionClick(model, DuplicateModal, (modal, model) => modal.Show(model.CategoryKey));

void ExpenseCard.IContext.EditAmount(OutcomeOverviewModel model)
=> OnActionClick(model, AmountEditModal);

Expand All @@ -44,6 +47,7 @@ void ExpenseCard.IContext.Delete(OutcomeOverviewModel model)

#endregion

protected OutcomeCreate DuplicateModal { get; set; }
protected ModalDialog AmountEditModal { get; set; }
protected ModalDialog DescriptionEditModal { get; set; }
protected ModalDialog WhenEditModal { get; set; }
Expand All @@ -58,10 +62,15 @@ protected override async Task OnInitializedAsync()
currencyFormatter = await CurrencyFormatterFactory.CreateAsync();
}

protected void OnActionClick(OutcomeOverviewModel model, ModalDialog modal)
protected void OnActionClick<T>(OutcomeOverviewModel model, T modal, Action<T, OutcomeOverviewModel> showHandler = null)
where T : ModalDialog
{
SelectedItem = model;
modal.Show();
if (showHandler == null)
modal.Show();
else
showHandler(modal, model);

StateHasChanged();
}

Expand Down
4 changes: 3 additions & 1 deletion src/Money.Blazor.Host/Components/OutcomeCreate.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<Modal @ref="Modal" Title="@Title">
@inherits ModalDialog

<Modal @ref="Modal" Title="@Title">
<ChildContent>
<Validation ErrorMessages="@ErrorMessages" />
<div class="form-row">
Expand Down
4 changes: 0 additions & 4 deletions src/Money.Blazor.Host/Components/OutcomeCreate.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public partial class OutcomeCreate
[Inject]
protected Navigator.ModalContainer ModalContainer { get; set; }

protected Modal Modal { get; set; }

protected string Title { get; set; }
protected string SaveButtonText { get; set; }
protected List<string> ErrorMessages { get; } = new List<string>();
Expand Down Expand Up @@ -128,8 +126,6 @@ public async void Show(IKey categoryKey)
StateHasChanged();
}

public void Hide() => Modal.Hide();

protected void OnPrerequisitesConfirmed()
{
if (Currencies == null || Currencies.Count == 0)
Expand Down
3 changes: 3 additions & 0 deletions src/Money.Blazor.Host/Pages/ExpenseBag.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ async Task IEventHandler<LocallyStoredExpensesPublished>.HandleAsync(LocallyStor

bool ExpenseCard.IContext.HasEdit => true;

void ExpenseCard.IContext.Duplicate(OutcomeOverviewModel model)
{ }

void ExpenseCard.IContext.EditAmount(OutcomeOverviewModel model)
{ }

Expand Down

0 comments on commit 26329ca

Please sign in to comment.