mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-21 22:09:36 +02:00
refactor: Add user prop to TransportationCard component for conditional rendering of actions
This commit is contained in:
parent
d5c5551ce1
commit
103500b5e1
3 changed files with 24 additions and 13 deletions
|
@ -56,10 +56,16 @@
|
|||
let id = data[1];
|
||||
let user_id = data[2];
|
||||
|
||||
if (id !== undefined && user_id !== undefined) {
|
||||
newCollection.id = id;
|
||||
newCollection.user_id = user_id;
|
||||
console.log(newCollection);
|
||||
dispatch('create', newCollection);
|
||||
addToast('success', 'Collection created successfully!');
|
||||
close();
|
||||
} else {
|
||||
addToast('error', 'Error creating collection');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
import FileDocumentEdit from '~icons/mdi/file-document-edit';
|
||||
|
||||
import { goto } from '$app/navigation';
|
||||
import type { Collection, Transportation } from '$lib/types';
|
||||
import type { Collection, Transportation, User } from '$lib/types';
|
||||
import { addToast } from '$lib/toasts';
|
||||
|
||||
import Plus from '~icons/mdi/plus';
|
||||
|
@ -15,6 +15,7 @@
|
|||
const dispatch = createEventDispatcher();
|
||||
|
||||
export let transportation: Transportation;
|
||||
export let user: User | null = null;
|
||||
|
||||
function editTransportation() {
|
||||
dispatch('edit', transportation);
|
||||
|
@ -51,6 +52,7 @@
|
|||
{#if transportation.date}
|
||||
{new Date(transportation.date).toLocaleString()}
|
||||
{/if}
|
||||
{#if user}
|
||||
<div class="card-actions justify-end">
|
||||
<button on:click={deleteTransportation} class="btn btn-secondary"
|
||||
><TrashCanOutline class="w-5 h-5 mr-1" /></button
|
||||
|
@ -59,5 +61,6 @@
|
|||
<FileDocumentEdit class="w-6 h-6" />
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -374,6 +374,7 @@
|
|||
{#each transportations as transportation}
|
||||
<TransportationCard
|
||||
{transportation}
|
||||
user={data?.user}
|
||||
on:delete={(event) => {
|
||||
transportations = transportations.filter((t) => t.id != event.detail);
|
||||
}}
|
||||
|
@ -430,6 +431,7 @@
|
|||
{#each dayTransportations as transportation}
|
||||
<TransportationCard
|
||||
{transportation}
|
||||
user={data?.user}
|
||||
on:delete={(event) => {
|
||||
transportations = transportations.filter((t) => t.id != event.detail);
|
||||
}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue