feat: chord sharing url, resolves #40

This commit is contained in:
2023-12-02 20:59:58 +01:00
parent 2ad0ef3b6d
commit eaf8028538
4 changed files with 31 additions and 6 deletions

View File

@@ -29,8 +29,6 @@ export function deserializeActionArray(raw: Uint8Array, cursor = {pos: 0}): Acti
const type = CHARA_FILE_TYPES[reader.getUint8(cursor.pos)]
cursor.pos++
console.log(cursor, raw)
if (type === "number") {
const decompressed = decompressActions(raw.slice(cursor.pos, cursor.pos + length))
cursor.pos += length

View File

@@ -2,5 +2,4 @@
import LL from "../../i18n/i18n-svelte"
</script>
<h4>{$LL.share.URL_COPIED()}</h4>
<button>{$LL.share.EXTRA_DOWNLOAD()}</button>
{$LL.share.URL_COPIED()}

View File

@@ -5,6 +5,9 @@
import ChordActionEdit from "./ChordActionEdit.svelte"
import type {Chord} from "$lib/serial/chord"
import {slide} from "svelte/transition"
import {charaFileToUriComponent} from "$lib/share/share-url"
import SharePopup from "../SharePopup.svelte"
import tippy from "tippy.js"
export let chord: ChordInfo
@@ -22,6 +25,32 @@
function restore() {
changes.update(changes => changes.filter(it => !(it.type === ChangeType.Chord && isSameChord(it, chord))))
}
async function share(event: Event) {
const url = new URL(window.location.href)
url.searchParams.set(
"import",
await charaFileToUriComponent({
charaVersion: 1,
type: "chords",
chords: [[chord.actions, chord.phrase]],
}),
)
await navigator.clipboard.writeText(url.toString())
let shareComponent: SharePopup
tippy(event.target as HTMLElement, {
onCreate(instance) {
const target = instance.popper.querySelector(".tippy-content")!
shareComponent = new SharePopup({target})
},
onHidden(instance) {
instance.destroy()
},
onDestroy(instance) {
shareComponent.$destroy()
},
}).show()
}
</script>
<th>
@@ -38,7 +67,7 @@
{/if}
<button class="icon compact" class:disabled={chord.isApplied} on:click={restore}>undo</button>
<div class="separator" />
<button class="icon compact">share</button>
<button class="icon compact" on:click={share}>share</button>
</td>
<style lang="scss">

View File

@@ -23,7 +23,6 @@
await navigator.clipboard.writeText(url.toString())
let shareComponent: SharePopup
tippy(event.target as HTMLElement, {
interactive: true,
onCreate(instance) {
const target = instance.popper.querySelector(".tippy-content")!
shareComponent = new SharePopup({target})