mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-21 01:12:59 +00:00
layout sharing via url
[deploy]
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user