Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stavroskasidis committed Aug 11, 2019
1 parent f953646 commit 9fa7af1
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 33 deletions.
2 changes: 1 addition & 1 deletion BlazorDialog/BlazorDialog.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@typeparam TInput
@inject DialogStates states
@inject IBlazorDialogService dialogService
@inherits BlazorDialogBase
@implements IDisposable

@if (Id != null && states.IsShowing.ContainsKey(Id) && states.IsShowing[Id])
Expand All @@ -22,7 +23,6 @@
}

@code{
[Parameter] protected string Id { get; set; }
[Parameter] protected RenderFragment<DialogContext<TInput>> ChildContent { get; set; }
[Parameter] protected DialogSizes Size { get; set; } = DialogSizes.Normal;
[Parameter] protected bool Centered { get; set; }
Expand Down
37 changes: 37 additions & 0 deletions BlazorDialog/BlazorDialogBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BlazorDialog
{
public abstract class BlazorDialogBase : ComponentBase
{
[Parameter] public string Id { get; protected set; }
[Parameter] protected bool IsShowing { get; set; }


public async Task Show()
{
this.IsShowing = true;
await Invoke(() => StateHasChanged());

}

//public Task Show(TInput input)
//{
// return dialogService.ShowDialog<TInput>(this.Id, input);
//}

//public void Hide<TResult>(TResult result)
//{
// dialogService.HideDialog(this.Id, result);
//}

//public void Hide()
//{
// dialogService.HideDialog(this.Id);
//}
}
}
1 change: 0 additions & 1 deletion BlazorDialog/BlazorDialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace BlazorDialog
{
public class BlazorDialogService : IBlazorDialogService
{
private readonly DialogStates _dialogStates;
private Dictionary<string, TaskCompletionSource<object>> taskCompletionSources = new Dictionary<string, TaskCompletionSource<object>>();

public BlazorDialogService(DialogStates states)
Expand Down
61 changes: 61 additions & 0 deletions BlazorDialog/BlazorDialogService2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BlazorDialog
{
public class BlazorDialogService2
{
private Dictionary<string, BlazorDialogBase> registeredDialogs = new Dictionary<string, BlazorDialogBase>();

internal void Register(BlazorDialogBase blazorDialog)
{
registeredDialogs[blazorDialog.Id] = blazorDialog;
}


internal void Unregister(BlazorDialogBase blazorDialog)
{
registeredDialogs.Remove(blazorDialog.Id);
}

public void HideDialog(string dialogId)
{
registeredDialogs[dialogId].Hide();
}

public void HideDialog(string dialogId, object result)
{
registeredDialogs[dialogId].Hide(result);
}

public async Task ShowDialog(string dialogId)
{
await ShowDialog<object>(dialogId, null);
}

public async Task<TResult> ShowDialog<TResult>(string dialogId)
{
return await ShowDialog<TResult>(dialogId, null);
}

public async Task ShowDialog(string dialogId, object input)
{
await ShowDialog<object>(dialogId, input);
}

public async Task<TResult> ShowDialog<TResult>(string dialogId, object input)
{
//if (taskCompletionSources.ContainsKey(dialogId))
//{
// taskCompletionSources[dialogId].SetCanceled();
//}
//taskCompletionSources[dialogId] = new TaskCompletionSource<object>();
//_dialogStates.ShowDialog(dialogId, input);
//return (TResult)await taskCompletionSources[dialogId].Task;

return (TResult)await registeredDialogs[dialogId].Show(input);
}
}
}
31 changes: 0 additions & 31 deletions BlazorDialog/DialogState.cs

This file was deleted.

0 comments on commit 9fa7af1

Please sign in to comment.