finishes trails page
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { goto } from "$app/navigation";
|
||||
import type { Trail } from "$lib/models/trail";
|
||||
import { trails_delete, trails_index } from "$lib/stores/trail_store";
|
||||
import { currentUser } from "$lib/stores/user_store";
|
||||
import { formatMeters, formatTimeHHMM } from "$lib/util/format_util";
|
||||
import Dropdown from "../base/dropdown.svelte";
|
||||
@@ -11,6 +13,18 @@
|
||||
{ text: "Edit", value: "edit" },
|
||||
{ text: "Delete", value: "delete" },
|
||||
];
|
||||
|
||||
async function handleDropdownClick(
|
||||
currentTrail: Trail,
|
||||
item: { text: string; value: any },
|
||||
) {
|
||||
if (item.value == "edit") {
|
||||
goto(`/trail/edit/${currentTrail.id}`);
|
||||
} else if (item.value == "delete") {
|
||||
await trails_delete(currentTrail);
|
||||
await trails_index();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="trail-card rounded-2xl shadow-md sm:w-72 cursor-pointer">
|
||||
@@ -22,7 +36,7 @@
|
||||
<div class="flex justify-between items-center">
|
||||
<h4 class="font-semibold text-lg">{trail.name}</h4>
|
||||
{#if $currentUser && $currentUser.id == trail.author && mode == "edit"}
|
||||
<Dropdown on:change items={dropdownItems}></Dropdown>
|
||||
<Dropdown on:change={(e) => handleDropdownClick(trail, e.detail)} items={dropdownItems}></Dropdown>
|
||||
{/if}
|
||||
</div>
|
||||
<h5><i class="fa fa-location-dot mr-3"></i>{trail.location}</h5>
|
||||
|
||||
Reference in New Issue
Block a user