Add copying to clipboard functionality.

This commit is contained in:
Oliver-Akins 2020-10-02 17:59:56 -06:00
parent 192cae129a
commit a8d0741436

View file

@ -3,6 +3,16 @@
<h1> <h1>
Secret Hitler Online Secret Hitler Online
</h1> </h1>
<h2>
Game Code:
<code
v-clipboard="copy_game_code"
v-clipboard:success="copy_success"
v-clipboard:error="copy_error"
>
{{ game_code }}
</code>
</h2>
<div> <div>
<h3>Players:</h3> <h3>Players:</h3>
<div <div
@ -19,7 +29,9 @@ export default {
name: 'GameLobby', name: 'GameLobby',
components: {}, components: {},
data() {return { data() {return {
players: [] game_code: ``,
is_host: false,
players: [],
}}, }},
mounted() { mounted() {
this.game_code = sessionStorage.getItem(`game-code`); this.game_code = sessionStorage.getItem(`game-code`);
@ -32,6 +44,23 @@ export default {
game_code: this.game_code, game_code: this.game_code,
}); });
}, },
copy_game_code() {
this.$clipboard(this.game_code);
},
copy_success() {
this.$emit(`alert`, {
message: `Game code copied to your clipboard.`,
classes: [`info`]
});
setTimeout(() => this.$emit(`alert`, { message: ``, classes: [] }), 2000)
},
copy_error() {
this.$emit(`alert`, {
message: `Something went wrong when copying the game code to your clipboard`,
classes: [`warning`]
});
setTimeout(() => this.$emit(`alert`, { message: ``, classes: [] }), 2000)
}
}, },
sockets: { sockets: {
PlayerListResponse(data) { PlayerListResponse(data) {