implements trail sharing

This commit is contained in:
Christian Beutel
2024-06-06 02:02:23 +02:00
parent 5d46ad96b4
commit ad5a4e668b
44 changed files with 1257 additions and 308 deletions

View File

@@ -19,6 +19,8 @@
import JSZip from "jszip";
import { getFileURL, saveAs } from "$lib/util/file_util";
import TrailShareModal from "./trail_share_modal.svelte";
import { currentUser } from "$lib/stores/user_store";
import { pb } from "$lib/pocketbase";
export let trail: Trail;
export let mode: "overview" | "map";
@@ -28,6 +30,10 @@
let openExportModal: () => void;
let openShareModal: () => void;
const allowEdit =
trail.author == $currentUser?.id ||
trail.expand.trail_share_via_trail?.some((s) => s.permission == "edit");
const dropdownItems: DropdownItem[] = [
mode == "overview"
? { text: $_("show-on-map"), value: "show", icon: "map" }
@@ -49,9 +55,15 @@
: []),
{ text: $_("print"), value: "print", icon: "print" },
{ text: $_("add-to-list"), value: "list", icon: "bookmark" },
{ text: $_("share"), value: "share", icon: "share" },
{ text: $_("edit"), value: "edit", icon: "pen" },
{ text: $_("delete"), value: "delete", icon: "trash" },
...(trail.author != pb.authStore.model?.id
? []
: [{ text: $_("share"), value: "share", icon: "share" }]),
...(allowEdit
? [{ text: $_("edit"), value: "edit", icon: "pen" }]
: []),
...(trail.author == $currentUser?.id
? [{ text: $_("delete"), value: "delete", icon: "trash" }]
: []),
];
async function handleDropdownClick(item: { text: string; value: any }) {
@@ -72,7 +84,7 @@
?.focus();
} else if (item.value == "print") {
goto(`/map/trail/${trail.id}/print`);
} else if (item.value == "share") {
} else if (item.value == "share") {
openShareModal();
} else if (item.value == "download") {
openExportModal();
@@ -189,4 +201,4 @@
bind:openModal={openExportModal}
on:export={(e) => exportTrail(e.detail)}
></TrailExportModal>
<TrailShareModal bind:openModal={openShareModal}></TrailShareModal>
<TrailShareModal {trail} bind:openShareModal></TrailShareModal>