mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-22 06:19:38 +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 id = data[1];
|
||||||
let user_id = data[2];
|
let user_id = data[2];
|
||||||
|
|
||||||
|
if (id !== undefined && user_id !== undefined) {
|
||||||
|
newCollection.id = id;
|
||||||
|
newCollection.user_id = user_id;
|
||||||
console.log(newCollection);
|
console.log(newCollection);
|
||||||
dispatch('create', newCollection);
|
dispatch('create', newCollection);
|
||||||
addToast('success', 'Collection created successfully!');
|
addToast('success', 'Collection created successfully!');
|
||||||
close();
|
close();
|
||||||
|
} else {
|
||||||
|
addToast('error', 'Error creating collection');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
import FileDocumentEdit from '~icons/mdi/file-document-edit';
|
import FileDocumentEdit from '~icons/mdi/file-document-edit';
|
||||||
|
|
||||||
import { goto } from '$app/navigation';
|
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 { addToast } from '$lib/toasts';
|
||||||
|
|
||||||
import Plus from '~icons/mdi/plus';
|
import Plus from '~icons/mdi/plus';
|
||||||
|
@ -15,6 +15,7 @@
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
export let transportation: Transportation;
|
export let transportation: Transportation;
|
||||||
|
export let user: User | null = null;
|
||||||
|
|
||||||
function editTransportation() {
|
function editTransportation() {
|
||||||
dispatch('edit', transportation);
|
dispatch('edit', transportation);
|
||||||
|
@ -51,6 +52,7 @@
|
||||||
{#if transportation.date}
|
{#if transportation.date}
|
||||||
{new Date(transportation.date).toLocaleString()}
|
{new Date(transportation.date).toLocaleString()}
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if user}
|
||||||
<div class="card-actions justify-end">
|
<div class="card-actions justify-end">
|
||||||
<button on:click={deleteTransportation} class="btn btn-secondary"
|
<button on:click={deleteTransportation} class="btn btn-secondary"
|
||||||
><TrashCanOutline class="w-5 h-5 mr-1" /></button
|
><TrashCanOutline class="w-5 h-5 mr-1" /></button
|
||||||
|
@ -59,5 +61,6 @@
|
||||||
<FileDocumentEdit class="w-6 h-6" />
|
<FileDocumentEdit class="w-6 h-6" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -374,6 +374,7 @@
|
||||||
{#each transportations as transportation}
|
{#each transportations as transportation}
|
||||||
<TransportationCard
|
<TransportationCard
|
||||||
{transportation}
|
{transportation}
|
||||||
|
user={data?.user}
|
||||||
on:delete={(event) => {
|
on:delete={(event) => {
|
||||||
transportations = transportations.filter((t) => t.id != event.detail);
|
transportations = transportations.filter((t) => t.id != event.detail);
|
||||||
}}
|
}}
|
||||||
|
@ -430,6 +431,7 @@
|
||||||
{#each dayTransportations as transportation}
|
{#each dayTransportations as transportation}
|
||||||
<TransportationCard
|
<TransportationCard
|
||||||
{transportation}
|
{transportation}
|
||||||
|
user={data?.user}
|
||||||
on:delete={(event) => {
|
on:delete={(event) => {
|
||||||
transportations = transportations.filter((t) => t.id != event.detail);
|
transportations = transportations.filter((t) => t.id != event.detail);
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue