layout sharing via url

[deploy]
This commit is contained in:
2023-07-09 01:20:38 +02:00
parent 391c9d8837
commit 26a6f70ccb
9 changed files with 166 additions and 10 deletions

View File

@@ -1,22 +1,22 @@
<script lang="ts">
import LayoutCC1 from "$lib/components/LayoutCC1.svelte"
import {share} from "$lib/share"
import {getSharableUrl, parseSharableUrl} from "$lib/serial/serialization"
import {layout} from "$lib/serial/connection"
import type {CharaLayout} from "$lib/serial/connection"
import tippy from "tippy.js"
import {onMount} from "svelte"
import {layoutAsUrlComponent, layoutFromUrlComponent} from "$lib/serialization/layout"
onMount(async () => {
const sharedLayout = await parseSharableUrl<CharaLayout>("layout")
if (sharedLayout) {
$layout = sharedLayout
const url = new URL(window.location.href)
if (url.searchParams.has("layout")) {
$layout = await layoutFromUrlComponent(url.searchParams.get("layout")!)
}
})
async function shareLayout(event) {
const data = await getSharableUrl("layout", $layout)
await navigator.clipboard.writeText(data.toString())
const url = new URL(window.location.href)
url.searchParams.set("layout", await layoutAsUrlComponent($layout))
await navigator.clipboard.writeText(url.toString())
tippy(event.target, {
content: "Share url copied!",
hideOnClick: true,