🆕 feat(news): add delete confirmation for news posts in the association news index page

This commit is contained in:
fsociety
2024-10-25 15:15:07 +02:00
parent 1bf8c66b35
commit 3fb0b1d5b8

View File

@@ -8,6 +8,7 @@ use swentel\nostr\Message\RequestMessage;
use swentel\nostr\Relay\Relay; use swentel\nostr\Relay\Relay;
use swentel\nostr\Request\Request; use swentel\nostr\Request\Request;
use swentel\nostr\Subscription\Subscription; use swentel\nostr\Subscription\Subscription;
use WireUi\Actions\Notification as WireNotification;
use function Laravel\Folio\{middleware, name}; use function Laravel\Folio\{middleware, name};
use function Livewire\Volt\{state, mount, on, computed, form, usesFileUploads}; use function Livewire\Volt\{state, mount, on, computed, form, usesFileUploads};
@@ -65,6 +66,28 @@ $save = function () {
->addMedia($this->file->getRealPath()) ->addMedia($this->file->getRealPath())
->toMediaCollection('pdf'); ->toMediaCollection('pdf');
$this->form->reset();
$this->file = null;
$this->news = \App\Models\Notification::query()->get();
};
$delete = function($id) {
$notification = new WireNotification($this);
$notification->confirm([
'title' => 'Post löschen',
'message' => 'Bist du sicher, dass du diesen Post löschen möchtest?',
'accept' => [
'label' => 'Ja, löschen',
'method' => 'deleteNow',
'params' => $id,
],
]);
};
$deleteNow = function($id) {
$notification = \App\Models\Notification::query()->find($id);
$notification->delete();
$this->news = \App\Models\Notification::query()->get(); $this->news = \App\Models\Notification::query()->get();
}; };
@@ -111,7 +134,7 @@ $save = function () {
</div> </div>
<ul class="flex flex-nowrap md:block mr-3 md:mr-0"> <ul class="flex flex-nowrap md:block mr-3 md:mr-0">
@foreach(\App\Enums\NewsCategory::selectOptions() as $category) @foreach(\App\Enums\NewsCategory::selectOptions() as $category)
<li class="mr-0.5 md:mr-0 md:mb-0.5"> <li class="mr-0.5 md:mr-0 md:mb-0.5" wire:key="category_{{ $category['value'] }}">
<a class="flex items-center px-2.5 py-2 rounded-lg whitespace-nowrap bg-white dark:bg-gray-800" <a class="flex items-center px-2.5 py-2 rounded-lg whitespace-nowrap bg-white dark:bg-gray-800"
href="#0"> href="#0">
<i class="fa-sharp-duotone fa-solid fa-{{ $category['icon'] }} shrink-0 fill-current text-amber-500 mr-2"></i> <i class="fa-sharp-duotone fa-solid fa-{{ $category['icon'] }} shrink-0 fill-current text-amber-500 mr-2"></i>
@@ -133,7 +156,7 @@ $save = function () {
<div class="space-y-2"> <div class="space-y-2">
@forelse($news as $post) @forelse($news as $post)
<article class="bg-white dark:bg-gray-800 shadow-sm rounded-xl p-5"> <article wire:key="post_{{ $post->id }}" class="bg-white dark:bg-gray-800 shadow-sm rounded-xl p-5">
<div class="flex flex-start space-x-4"> <div class="flex flex-start space-x-4">
<!-- Avatar --> <!-- Avatar -->
<div class="shrink-0 mt-1.5"> <div class="shrink-0 mt-1.5">
@@ -175,13 +198,19 @@ $save = function () {
</div> </div>
</footer> </footer>
</div> </div>
<!-- Upvote button -->
<div class="shrink-0"> <div class="shrink-0">
<x-button <x-button
target="_blank" target="_blank"
:href="$post->getFirstMediaUrl('pdf')" :href="$post->getFirstMediaUrl('pdf')"
label="Öffnen" label="Öffnen"
primary icon="cloud-arrow-down"/> primary icon="cloud-arrow-down"/>
@if($canEdit)
<x-button
xs
wire:click="delete({{ $post->id }})"
label="Löschen"
negative icon="trash"/>
@endif
</div> </div>
</div> </div>
</article> </article>