(Merge) Deleting an item works (#23) from Emre_DeleteItem into master

Reviewed-on: #23
Emre_LanguePageConnectionInscription
Emre KARTAL 2 years ago
commit c22fd74fe1

@ -20,9 +20,16 @@
</div>
<div>@Localizer["Result"]</div>
<div>
<div class="row">
<div class="col-2">
<CraftingItem Item="RecipeResult" />
</div>
<div class="col-2">
<DeleteItem />
</div>
</div>
</div>
<div >

@ -18,6 +18,10 @@ namespace CraftSharp.Components
Actions.CollectionChanged += OnActionsCollectionChanged;
this.RecipeItems = new List<Item> { null, null, null, null, null, null, null, null, null };
}
public void Suppression()
{
StateHasChanged();
}
public ObservableCollection<CraftingAction> Actions { get; set; }
public Item CurrentDragItem { get; set; }

@ -0,0 +1,12 @@
@using CraftSharp.Models
<div class="item"
ondragover="event.preventDefault();"
@ondrop="@OnDrop">
<img src="/Images/Trash.png" title="Delete" alt="Delete" style="min-width: 64px; max-width: 64px" />
<p>Delete</p>
</div>

@ -0,0 +1,45 @@
using CraftSharp.Components;
using CraftSharp.Models;
using CraftSharp.Services;
using Microsoft.AspNetCore.Components;
namespace CraftSharp.Components
{
public partial class DeleteItem
{
[Parameter]
public int Index { get; set; }
[Parameter]
public Item Item { get; set; }
[Parameter]
public bool NoDrop { get; set; }
[CascadingParameter]
public Crafting Parent { get; set; }
[Inject]
public CustomStateProvider AuthStateProvider { get; set; }
internal void OnDrop()
{
if (NoDrop)
{
return;
}
this.Item = Parent.CurrentDragItem;
if (AuthStateProvider.GetCurrentUser().Inventory.Any(n => n.Id == this.Item.Id))
{
AuthStateProvider.GetCurrentUser().DeleteItem(this.Item);
this.Item = null;
Parent.Suppression();
}
}
}
}

@ -0,0 +1,19 @@
.item {
width: 64px;
height: 64px;
border: 1px solid;
overflow: hidden;
position: relative;
}
p {
position: absolute;
top: 0;
color: red;
text-align: center;
background-color: rgba(0, 0, 0, .4);
width: 64px;
font-size: .75em;
}

@ -14,7 +14,10 @@
{
Inventory.Add(item);
}
public void DeleteItem(Item item)
{
Inventory.Remove(item);
}
public int getSizeInventory()
{
return Inventory.Count;

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Loading…
Cancel
Save