mastoradio/src/components/ContextMenu.svelte

58 lines
2.0 KiB
Svelte
Raw Normal View History

2020-02-22 05:08:25 +01:00
<button class="contextMenu__item" on:click={() => showModal()}>Share this song</button>
<a class="contextMenu__item" href={track.referer.url} target="_blank">Link to toot</a>
<a class="contextMenu__item" href={track.media.url} target="_blank">Link to media</a>
2020-02-22 03:50:37 +01:00
2020-02-22 04:38:33 +01:00
<!-- Sharemodal -->
<Portal target="{document.body}">
2020-02-22 05:08:25 +01:00
{#if open}
<div class="modal">
<div class="modal__overlay" tabindex="-1" on:click={() => hideModal()}></div>
<div class="modal__container" role="dialog" aria-modal="true">
<button class="modal__close" aria-label="close" on:click={() => hideModal()}></button>
<div class="modal__title">Share this song</div>
<div class="modal__content">
<input class="modalShare__input f-size-full w100" readonly type="text" value={shareUrlInput}>
<div class="modalShare__controls">
<div class="modalShare__bigplayer">
<input type="checkbox" id="bigplayer_active" bind:checked={isBigPlayer}>
<label for="bigplayer_active">active big player</label>
</div>
2020-02-23 15:22:19 +01:00
<button class="modalShare__copy" on:click={() => copyUrl()}>{ copied ? 'copied' : 'copy' }</button>
2020-02-22 04:38:33 +01:00
</div>
</div>
</div>
</div>
2020-02-22 05:08:25 +01:00
{/if}
2020-02-22 04:38:33 +01:00
</Portal>
2020-02-22 03:50:37 +01:00
<script>
2020-02-22 05:08:25 +01:00
import { getContext } from 'svelte'
import Portal from 'svelte-portal'
import copy from 'copy-to-clipboard'
2020-02-22 04:38:33 +01:00
2020-02-22 05:08:25 +01:00
export let track
2020-02-22 03:50:37 +01:00
2020-02-22 05:08:25 +01:00
let open = false
let isBigPlayer = false
2020-02-23 15:22:19 +01:00
let copied = false
2020-02-22 05:08:25 +01:00
$: shareUrlInput = track.shareUrl + (isBigPlayer ? '?large' : '')
2020-02-22 04:38:33 +01:00
2020-02-22 05:08:25 +01:00
const closeMenu = getContext('closeMenu')
2020-02-22 04:38:33 +01:00
2020-02-22 05:08:25 +01:00
function showModal () {
open = true
closeMenu()
}
2020-02-22 04:38:33 +01:00
2020-02-22 05:08:25 +01:00
function hideModal () {
open = false
}
2020-02-22 04:38:33 +01:00
2020-02-22 05:08:25 +01:00
function copyUrl () {
copy(shareUrlInput)
2020-02-23 15:22:19 +01:00
copied = true
setTimeout(() => copied = false, 2000)
2020-02-22 05:08:25 +01:00
}
2020-02-22 03:50:37 +01:00
</script>