2024-02-10 18:30:47 +01:00
|
|
|
|
<template>
|
|
|
|
|
<h1>Création d’une campagne</h1>
|
2024-02-14 06:58:17 +01:00
|
|
|
|
<form @submit.prevent="createCampaign" class="flex-col gap-2rem card" autocomplete="off">
|
2024-02-17 04:28:53 +01:00
|
|
|
|
<label for="campaign-name">Nom de la nouvelle campagne</label>
|
|
|
|
|
<div>
|
|
|
|
|
<input
|
|
|
|
|
name="campaign-name"
|
|
|
|
|
type="text"
|
|
|
|
|
v-model="campaign.name"
|
|
|
|
|
autocomplete="off"
|
|
|
|
|
placeholder="Nom de la nouvelle campagne" />
|
|
|
|
|
</div>
|
2024-02-14 06:58:17 +01:00
|
|
|
|
|
2024-02-17 04:28:53 +01:00
|
|
|
|
<fieldset class="player-selection">
|
|
|
|
|
<legend class="highlight" for="players" autocomplete="off">Joueurs</legend>
|
|
|
|
|
<div v-for="user in users" :key="user.id" class="player">
|
|
|
|
|
<input type="checkbox" v-model="players" :name="user.id" :value="user.id" :id="user.id" />
|
|
|
|
|
<label :for="user.id">{{ user.displayName() }}</label>
|
|
|
|
|
</div>
|
|
|
|
|
</fieldset>
|
2024-02-10 18:30:47 +01:00
|
|
|
|
<div class="buttons gap-1rem">
|
|
|
|
|
<RouterLink :to="{ name: 'home' }" class="button faded">Annuler</RouterLink>
|
|
|
|
|
<button type="submit">Envoyer</button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { onMounted, ref } from 'vue';
|
2024-02-14 06:58:17 +01:00
|
|
|
|
import router from '@/router';
|
|
|
|
|
import { usePocketbaseStore } from '@/stores/pocketbase';
|
|
|
|
|
import { type NewCampaign } from '@/models/Campaign';
|
2024-02-16 21:44:36 +01:00
|
|
|
|
import { type SimpleUser } from '@/models/User';
|
2024-02-10 18:30:47 +01:00
|
|
|
|
|
|
|
|
|
const pbStore = usePocketbaseStore();
|
2024-02-14 06:58:17 +01:00
|
|
|
|
const users = ref<SimpleUser[]>([]);
|
2024-02-17 04:28:53 +01:00
|
|
|
|
const players = ref([]);
|
2024-02-10 18:30:47 +01:00
|
|
|
|
|
|
|
|
|
const campaign = ref<NewCampaign>({
|
|
|
|
|
name: null,
|
|
|
|
|
game_master: pbStore.auth.userId,
|
2024-02-14 06:58:17 +01:00
|
|
|
|
players: [],
|
2024-02-10 18:30:47 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const createCampaign = () => {
|
2024-02-17 04:28:53 +01:00
|
|
|
|
campaign.value.players = [...players.value];
|
2024-02-16 21:44:36 +01:00
|
|
|
|
pbStore.campaigns.create(campaign.value).subscribe({
|
2024-02-10 18:30:47 +01:00
|
|
|
|
next: () => {
|
|
|
|
|
router.push({ name: 'home' });
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
2024-02-16 21:44:36 +01:00
|
|
|
|
pbStore.users.listSimple().subscribe({
|
|
|
|
|
next: (results) => {
|
|
|
|
|
users.value = results.filter((user) => user.id !== pbStore.auth.userId);
|
|
|
|
|
},
|
2024-02-14 06:58:17 +01:00
|
|
|
|
error: (err) => console.warn('Failed to fetch all users', err),
|
2024-02-10 18:30:47 +01:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="less">
|
2024-02-17 04:28:53 +01:00
|
|
|
|
@import '@/assets/main';
|
|
|
|
|
|
2024-02-10 18:30:47 +01:00
|
|
|
|
form {
|
|
|
|
|
min-width: 90%;
|
|
|
|
|
}
|
2024-02-17 04:28:53 +01:00
|
|
|
|
|
|
|
|
|
.player-selection {
|
|
|
|
|
border: none;
|
|
|
|
|
.card;
|
|
|
|
|
.more;
|
|
|
|
|
.flex-col;
|
|
|
|
|
.gap-1rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.player {
|
|
|
|
|
.flex-row;
|
|
|
|
|
gap: 0.5rem;
|
|
|
|
|
}
|
2024-02-10 18:30:47 +01:00
|
|
|
|
</style>
|