Ajoute les amis et les invitations temps reel
This commit is contained in:
61
ChessCubing.App/Components/PlayInviteOverlay.razor
Normal file
61
ChessCubing.App/Components/PlayInviteOverlay.razor
Normal file
@@ -0,0 +1,61 @@
|
||||
@implements IDisposable
|
||||
@inject SocialRealtimeService Realtime
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
@if (Realtime.IncomingPlayInvite is not null)
|
||||
{
|
||||
<div class="play-overlay">
|
||||
<div class="modal-backdrop"></div>
|
||||
<section class="modal-card play-overlay-card" role="dialog" aria-modal="true" aria-labelledby="playInviteTitle">
|
||||
<div class="modal-head">
|
||||
<div>
|
||||
<p class="eyebrow">Invitation de partie</p>
|
||||
<h2 id="playInviteTitle">@Realtime.IncomingPlayInvite.SenderDisplayName veut jouer</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="play-overlay-copy">
|
||||
@Realtime.IncomingPlayInvite.SenderDisplayName te propose une partie ChessCubing et te place cote @RecipientColorLabel.
|
||||
</p>
|
||||
|
||||
<div class="play-overlay-actions">
|
||||
<button class="button secondary small" type="button" @onclick="AcceptAsync">Accepter</button>
|
||||
<button class="button ghost small" type="button" @onclick="DeclineAsync">Refuser</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private string RecipientColorLabel
|
||||
=> string.Equals(Realtime.IncomingPlayInvite?.RecipientColor, "white", StringComparison.Ordinal)
|
||||
? "blanc"
|
||||
: "noir";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Realtime.Changed += HandleRealtimeChanged;
|
||||
await Realtime.EnsureStartedAsync();
|
||||
}
|
||||
|
||||
private void HandleRealtimeChanged()
|
||||
=> _ = InvokeAsync(StateHasChanged);
|
||||
|
||||
private async Task AcceptAsync()
|
||||
{
|
||||
await Realtime.RespondToIncomingPlayInviteAsync(accept: true);
|
||||
|
||||
var currentPath = new Uri(Navigation.Uri).AbsolutePath.Trim('/');
|
||||
if (!string.Equals(currentPath, "application", StringComparison.OrdinalIgnoreCase) &&
|
||||
!string.Equals(currentPath, "application.html", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Navigation.NavigateTo("/application.html");
|
||||
}
|
||||
}
|
||||
|
||||
private Task DeclineAsync()
|
||||
=> Realtime.RespondToIncomingPlayInviteAsync(accept: false);
|
||||
|
||||
public void Dispose()
|
||||
=> Realtime.Changed -= HandleRealtimeChanged;
|
||||
}
|
||||
Reference in New Issue
Block a user