@page "/Share"
@rendermode InteractiveServer
@using BlazorBootstrap;
@using Microsoft.AspNetCore.WebUtilities
@using ModelsLib
@using PhotoShareHelri.Components.Blocs
@using System.Text
@inject NavigationManager NavManager
@inject EmailService mailService
@inject PhotoService ShootingDb
@inject IJSRuntime JS
@using MudBlazor
Résultat du shooting
@Title
@for (int index = 0; index < Images.Count; index++)
{
var img = Images[index];
OpenModalZoom(img)" />
}
@* Modal de zoom sur une image *@
@code {
#region Variables
HashSet SelectedImages = new();
private int MaxSelect = 1;
// Liste des images disponibles
private List Images = new();
public string Title { get; set; }
bool IsModalZoomOpen = false;
string? CurrentImage;
int CurrentIndex =>
CurrentImage == null ? -1 : Images.IndexOf(CurrentImage);
bool CanNext => CurrentIndex >= 0 && CurrentIndex < Images.Count - 1;
bool CanPrevious => CurrentIndex > 0;
private string ShootingId;
#endregion
#region modal zoom
///
/// Ouverture de la modal à partir du clic sur image voulu
///
void OpenModalZoom(string img)
{
CurrentImage = img;
IsModalZoomOpen = true;
}
///
/// fermeture de la modal
///
void CloseModalZoom()
{
IsModalZoomOpen = false;
}
///
/// photo suivante dans la modal
/// dans la liste des photos affichés
///
void NextModalZoom()
{
if (CanNext)
CurrentImage = Images[CurrentIndex + 1];
}
///
/// photo précédente
///
void PreviousModalZoom()
{
if (CanPrevious)
CurrentImage = Images[CurrentIndex - 1];
}
#endregion
///
/// arrivé sur la page
///
protected override async Task OnInitializedAsync()
{
//récupération de l'identifiant de shooting, si identifiant null ou si recherche inexistante redirection vers la page de recherche de shooting
var uri = NavManager.ToAbsoluteUri(NavManager.Uri);
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("Id", out var id))
{
if (!string.IsNullOrEmpty(id))
{
ShootingId = id;
Images = ShootingDb.LireContenu(ShootingId, true);
}
}
// Code exécuté au chargement du composant
}
///
/// Déclenche le téléchargement de l'image originale sur la modal de visualisation
///
/// image sélectionné par son hash
private async Task ToggleImage(string img)
{
var filePath = $"{img}"; // chemin dans wwwroot
await JS.InvokeVoidAsync("downloadFile", filePath, $"{img}");
}
}