workadventure/front/src/Components/Menu/GuestSubMenu.svelte

140 lines
4.1 KiB
Svelte
Raw Normal View History

<script lang="ts">
2022-01-21 17:06:03 +01:00
import LL from "../../i18n/i18n-svelte";
2022-02-09 13:03:14 +01:00
import { gameManager } from "../../Phaser/Game/GameManager";
import { startLayerNamesStore } from "../../Stores/StartLayerNamesStore";
let entryPoint: string = $startLayerNamesStore[0];
let walkAutomatically: boolean = false;
const currentPlayer = gameManager.getCurrentGameScene().CurrentPlayer;
const playerPos = { x: Math.floor(currentPlayer.x), y: Math.floor(currentPlayer.y) };
2021-12-19 16:01:51 +01:00
function copyLink() {
2021-12-06 16:12:37 +01:00
const input: HTMLInputElement = document.getElementById("input-share-link") as HTMLInputElement;
input.focus();
input.select();
2021-12-06 16:12:37 +01:00
document.execCommand("copy");
}
2022-02-09 13:03:14 +01:00
function getLink() {
return `${location.origin}${location.pathname}#${entryPoint}${
walkAutomatically ? `&moveTo=${playerPos.x},${playerPos.y}` : ""
}`;
}
function updateInputFieldValue() {
const input = document.getElementById("input-share-link");
if (input) {
(input as HTMLInputElement).value = getLink();
}
}
let canShare = navigator.share !== undefined;
2022-02-11 15:37:23 +01:00
async function shareLink() {
2022-02-09 13:03:14 +01:00
const shareData = { url: getLink() };
try {
await navigator.share(shareData);
} catch (err) {
2021-12-06 16:12:37 +01:00
console.error("Error: " + err);
copyLink();
}
}
</script>
<div class="guest-main">
<section class="container-overflow">
{#if !canShare}
<section class="share-url not-mobile">
<h3>{$LL.menu.invite.description()}</h3>
<input type="text" readonly id="input-share-link" class="link-url" value={location.toString()} />
<button type="button" class="nes-btn is-primary" on:click={copyLink}>{$LL.menu.invite.copy()}</button>
</section>
2022-02-11 15:37:23 +01:00
{:else}
<section class="is-mobile">
<h3>{$LL.menu.invite.description()}</h3>
<input type="hidden" readonly id="input-share-link" value={location.toString()} />
<button type="button" class="nes-btn is-primary" on:click={shareLink}>{$LL.menu.invite.share()}</button>
</section>
2022-02-11 15:37:23 +01:00
{/if}
2022-02-09 13:03:14 +01:00
<h3>Select an entry point</h3>
2022-02-11 15:37:23 +01:00
<section class="nes-select is-dark starting-points">
2022-02-09 13:03:14 +01:00
<select
bind:value={entryPoint}
on:blur={() => {
updateInputFieldValue();
}}
>
{#each $startLayerNamesStore as entryPointName}
<option value={entryPointName}>{entryPointName}</option>
{/each}
</select>
</section>
<label>
<input
type="checkbox"
class="nes-checkbox is-dark"
bind:checked={walkAutomatically}
on:change={() => {
updateInputFieldValue();
}}
/>
<span>{$LL.menu.invite.walk_automatically_to_position()}</span>
2022-02-09 13:03:14 +01:00
</label>
</section>
</div>
<style lang="scss">
2022-01-05 10:27:40 +01:00
@import "../../../style/breakpoints.scss";
div.guest-main {
2022-02-11 15:37:23 +01:00
width: 50%;
margin-left: auto;
margin-right: auto;
2021-12-06 16:12:37 +01:00
height: calc(100% - 56px);
2022-02-11 15:37:23 +01:00
input.link-url {
width: calc(100% - 200px);
}
.starting-points {
width: 80%;
}
2021-12-06 16:12:37 +01:00
section {
margin-bottom: 50px;
}
2022-02-09 13:03:14 +01:00
section.nes-select select:focus {
outline: none;
}
2021-12-06 16:12:37 +01:00
section.container-overflow {
height: 100%;
margin: 0;
padding: 0;
overflow: auto;
}
2021-12-06 16:12:37 +01:00
section.is-mobile {
2022-02-11 15:37:23 +01:00
display: block;
text-align: center;
margin-bottom: 20px;
2021-12-06 16:12:37 +01:00
}
}
2022-01-05 10:27:40 +01:00
@include media-breakpoint-up(md) {
2021-12-06 16:12:37 +01:00
div.guest-main {
section.container-overflow {
height: calc(100% - 120px);
}
}
}
2022-02-11 15:37:23 +01:00
@include media-breakpoint-up(lg) {
div.guest-main {
width: 100%;
}
2022-02-11 15:37:23 +01:00
}
2021-12-06 16:12:37 +01:00
</style>