Skip to content

Commit

Permalink
Code(WEB::AttachmentPreview): Move draft to separate component named …
Browse files Browse the repository at this point in the history
…AttachmentPreview
  • Loading branch information
ktutak1337 committed Sep 4, 2024
1 parent 08f8457 commit 8cd65bd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<div class="relative" style="width: 64px; height: 64px; margin-left: 12px;"
@onmouseover="() => HandleMouseOverAttachment(Attachment)"
@onmouseout="() => HandleMouseOutAttachment(Attachment)">
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" Class="absolute close-button" Style="color: white; top: -2px; right: -2px; z-index: 2;" OnClick="() => RemoveAttachment(Attachment)" />
<div class="relative" style="width: 64px; height: 64px;">
@if (Attachment.IsLoading)
{
<MudProgressCircular Color="Color.Default" Indeterminate="true" Class="absolute" Style="top: 50%; left: 50%; transform: translate(-50%, -50%);" />
}
else if (Attachment.Url != null)
{
<MudImage Src="@Attachment.Url" Alt="Image preview" Width="64" Height="64" Elevation="25" Class="rounded-lg" />
@if (Attachment.IsHovering)
{
<div class="rounded-lg" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 1; pointer-events: none;"></div>
}
}
else
{
<MudIcon Icon="@Icons.Material.Filled.Image" Class="absolute" Style="top: 50%; left: 50%; transform: translate(-50%, -50%);" />
}
</div>
</div>

@code
{
[Parameter] public Attachment? Attachment { get; set; }
[Parameter] public EventCallback<Attachment> OnRemove { get; set; }

private void HandleMouseOverAttachment(Attachment attachment)
{
attachment.IsHovering = true;
}

private void HandleMouseOutAttachment(Attachment attachment)
{
attachment.IsHovering = false;
}

private async Task RemoveAttachment(Attachment attachment)
{
await OnRemove.InvokeAsync(attachment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,7 @@
<MudItem xs="12" Class="d-flex flex-wrap">
@foreach (var attachment in Attachments)
{
<div class="relative" style="width: 64px; height: 64px; margin-left: 12px;"
@onmouseover="() => HandleMouseOverAttachment(attachment)"
@onmouseout="() => HandleMouseOutAttachment(attachment)">

<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" Class="absolute close-button" Style="color: white; top: -2px; right: -2px; z-index: 2;" OnClick="() => RemoveAttachment(attachment)" />

<div class="relative" style="width: 64px; height: 64px;">
@if (attachment.IsLoading)
{
<MudProgressCircular Color="Color.Default" Indeterminate="true" Class="absolute" Style="top: 50%; left: 50%; transform: translate(-50%, -50%);" />
}
else if (attachment.Url != null)
{
<MudImage Src="@attachment.Url" Alt="Image preview" Width="64" Height="64" Elevation="25" Class="rounded-lg" />
@if (attachment.IsHovering)
{
<div class="rounded-lg" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 1; pointer-events: none;"></div>
}
}
else
{
<MudIcon Icon="@Icons.Material.Filled.Image" Class="absolute" Style="top: 50%; left: 50%; transform: translate(-50%, -50%);" />
}
</div>
</div>
<AttachmentPreview Attachment="attachment" OnRemove="RemoveAttachment" />
}
</MudItem>
</MudGrid>
Expand Down Expand Up @@ -150,17 +126,6 @@
}
}

// private async Task AttachFiles(InputFileChangeEventArgs e)
// {
// var file = e.File;
// if (file is not null)
// {
// var response = await _storageService.UploadFileAsync(file, "avatar");
// Attachments.Add(response.Url);
// }
// }
private async Task AttachFiles(InputFileChangeEventArgs e)
{
var file = e.File;
Expand All @@ -179,29 +144,10 @@
{
// call to api to remove an attachment
Attachments.Remove(attachment);
// isHovering = false;
attachment.IsHovering = false;
await Task.CompletedTask;
}

// private void HandleMouseOverAttachment()
// {
// isHovering = true;
// }
// private void HandleMouseOutAttachment()
// {
// isHovering = false;
// }
private void HandleMouseOverAttachment(Attachment attachment)
{
attachment.IsHovering = true;
}
private void HandleMouseOutAttachment(Attachment attachment)
{
attachment.IsHovering = false;
}

private string GetImageStyle(Attachment attachment)
{
return attachment.IsHovering ? "background-color: rgba(0, 0, 0, 0.5);" : string.Empty;
Expand Down Expand Up @@ -246,11 +192,4 @@
{
_chatState.ActionIdChanged -= StateHasChanged;
}

private class Attachment
{
public bool IsLoading { get; set; }
public string? Url { get; set; }
public bool IsHovering { get; set; }
}
}
8 changes: 8 additions & 0 deletions src/Client/StellarChat.Client.Web/Models/Attachment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace StellarChat.Client.Web.Models;

public class Attachment
{
public bool IsLoading { get; set; }
public string? Url { get; set; }
public bool IsHovering { get; set; }
}

0 comments on commit 8cd65bd

Please sign in to comment.