Deleting an item works #23

Merged
emre.kartal merged 1 commits from Emre_DeleteItem into master 2 years ago

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

@ -18,6 +18,10 @@ namespace CraftSharp.Components
Actions.CollectionChanged += OnActionsCollectionChanged; Actions.CollectionChanged += OnActionsCollectionChanged;
this.RecipeItems = new List<Item> { null, null, null, null, null, null, null, null, null }; 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 ObservableCollection<CraftingAction> Actions { get; set; }
public Item CurrentDragItem { 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); Inventory.Add(item);
} }
public void DeleteItem(Item item)
{
Inventory.Remove(item);
}
public int getSizeInventory() public int getSizeInventory()
{ {
return Inventory.Count; return Inventory.Count;

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Loading…
Cancel
Save