feat: add ability to edit players
This commit is contained in:
parent
3eb478a060
commit
1bbaee6474
@ -10,7 +10,7 @@
|
|||||||
<span class="player-dialog__id" :class="{ 'player-dialog__id__show': showId }">{{ player.id }}</span>
|
<span class="player-dialog__id" :class="{ 'player-dialog__id__show': showId }">{{ player.id }}</span>
|
||||||
</div>
|
</div>
|
||||||
<template v-slot:footer>
|
<template v-slot:footer>
|
||||||
<Button v-for="button in buttons" :key="button.id" class="player-dialog__button" :border="button.primary"
|
<Button v-for="button in buttons" :key="button.id" class="player-dialog__button" :border="['primary', 'caution'].indexOf(button.type) >= 0"
|
||||||
@click="emit('submit', button.id)">{{ button.name }}</Button>
|
@click="emit('submit', button.id)">{{ button.name }}</Button>
|
||||||
</template>
|
</template>
|
||||||
</ModalDialog>
|
</ModalDialog>
|
||||||
@ -19,12 +19,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
import { PlayerEdit } from '@/composables/engine.d'
|
import { PlayerEdit } from '@/composables/engine.d'
|
||||||
|
import type { Button } from '@/components/admin/PlayerModal'
|
||||||
type Button = {
|
|
||||||
id: string
|
|
||||||
name: string
|
|
||||||
primary?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
title: string
|
title: string
|
||||||
|
9
client/src/components/admin/PlayerModal.d.ts
vendored
Normal file
9
client/src/components/admin/PlayerModal.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export type ButtonType = 'primary' | 'caution' | 'normal'
|
||||||
|
|
||||||
|
export type Button = {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
type: ButtonType
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ButtonAction = 'cancel' | 'create' | 'edit' | 'delete'
|
@ -8,16 +8,16 @@
|
|||||||
<th class="players-tile__table-head">{{ $t('score') }}</th>
|
<th class="players-tile__table-head">{{ $t('score') }}</th>
|
||||||
<th class="players-tile__table-head">{{ $t('last-logged-in') }}</th>
|
<th class="players-tile__table-head">{{ $t('last-logged-in') }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-for="player in players" class="players-tile__row" :key="player.id">
|
<tr v-for="player in players" class="players-tile__row" :key="player.id" @click="editPlayer(player)">
|
||||||
<td>
|
<td class="players-tile__cell">
|
||||||
{{ player.name }}
|
{{ player.name }}
|
||||||
<div v-if="player.role === 'gamemaster'" class="players-tile__is-gamemaster">
|
<div v-if="player.role === 'gamemaster'" class="players-tile__is-gamemaster">
|
||||||
<Icon name="crown" />
|
<Icon name="crown" />
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ player.numQuotes }}</td>
|
<td class="players-tile__cell">{{ player.numQuotes }}</td>
|
||||||
<td>{{ player.score }}</td>
|
<td class="players-tile__cell">{{ player.score }}</td>
|
||||||
<td>{{ player.lastLoggedIn === 0 ? '-' : datetime(player.lastLoggedIn) }}</td>
|
<td class="players-tile__cell">{{ player.lastLoggedIn === 0 ? '-' : datetime(player.lastLoggedIn) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</AdminTile>
|
</AdminTile>
|
||||||
@ -30,10 +30,9 @@
|
|||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import useI18n from '@/composables/useI18n'
|
import useI18n from '@/composables/useI18n'
|
||||||
import useDateFormatter from '@/composables/useDateFormatter';
|
import useDateFormatter from '@/composables/useDateFormatter';
|
||||||
|
import useEngine from '@/composables/useEngine';
|
||||||
import type { GameInfo, PlayerEdit } from '@/composables/engine.d'
|
import type { GameInfo, PlayerEdit } from '@/composables/engine.d'
|
||||||
import EngineDebugVue from '../EngineDebug.vue';
|
import type { Button, ButtonAction } from '@/components/admin/PlayerModal'
|
||||||
import useEngine from '~~/src/composables/useEngine';
|
|
||||||
import { EmitFlags } from 'typescript';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
gameinfo: GameInfo
|
gameinfo: GameInfo
|
||||||
@ -55,19 +54,13 @@ const players = computed(() => {
|
|||||||
const showPlayerDialog = ref(false)
|
const showPlayerDialog = ref(false)
|
||||||
const playerDialogPlayer = ref({} as PlayerEdit)
|
const playerDialogPlayer = ref({} as PlayerEdit)
|
||||||
const playerDialogTitle = ref('')
|
const playerDialogTitle = ref('')
|
||||||
type ButtonAction = 'cancel' | 'create' | 'edit' | 'delete'
|
|
||||||
type Button = {
|
|
||||||
id: ButtonAction
|
|
||||||
name: string
|
|
||||||
primary?: boolean
|
|
||||||
}
|
|
||||||
const playerDialogButtons = ref([] as Array<Button>)
|
const playerDialogButtons = ref([] as Array<Button>)
|
||||||
const addPlayer = () => {
|
const addPlayer = () => {
|
||||||
showPlayerDialog.value = true
|
showPlayerDialog.value = true
|
||||||
playerDialogTitle.value = 'Add new player'
|
playerDialogTitle.value = 'Add new player'
|
||||||
playerDialogButtons.value = [
|
playerDialogButtons.value = [
|
||||||
{ id: 'create', name: 'Create Player', primary: true },
|
{ id: 'create', name: 'Create Player', type: 'primary' },
|
||||||
{ id: 'cancel', name: 'Cancel', primary: false },
|
{ id: 'cancel', name: 'Cancel', type: 'normal' },
|
||||||
],
|
],
|
||||||
playerDialogPlayer.value = {
|
playerDialogPlayer.value = {
|
||||||
id: '',
|
id: '',
|
||||||
@ -77,6 +70,17 @@ const addPlayer = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const editPlayer = async (player: PlayerEdit): Promise<void> => {
|
||||||
|
showPlayerDialog.value = true
|
||||||
|
playerDialogTitle.value = 'Edit player'
|
||||||
|
playerDialogButtons.value =[
|
||||||
|
{ id: 'edit', name: 'Save', type: 'primary' },
|
||||||
|
{ id: 'delete', name: 'Delete', type: 'caution' },
|
||||||
|
]
|
||||||
|
playerDialogPlayer.value = {
|
||||||
|
...player,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const playerDialogSubmit = async (action: ButtonAction): Promise<void> => {
|
const playerDialogSubmit = async (action: ButtonAction): Promise<void> => {
|
||||||
showPlayerDialog.value = false
|
showPlayerDialog.value = false
|
||||||
@ -102,18 +106,26 @@ const playerDialogSubmit = async (action: ButtonAction): Promise<void> => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
&__table {
|
&__table {
|
||||||
margin: 0 0 16px -12px;
|
margin: 0 0 16px 0;
|
||||||
border-collapse: separate;
|
border-spacing: 0;
|
||||||
border-spacing: 12px 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&__table-head {
|
&__table-head {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
margin: 8px;
|
padding-right: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__row {
|
&__row {
|
||||||
height: 24px;
|
height: 24px;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #606060;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__cell {
|
||||||
|
padding-right: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__is-gamemaster {
|
&__is-gamemaster {
|
||||||
|
Loading…
Reference in New Issue
Block a user