2020-08-11 04:16:43 +00:00
|
|
|
<template lang="html">
|
|
|
|
<div>
|
|
|
|
<b-button
|
|
|
|
v-b-modal="modalId"
|
2020-08-11 23:39:11 +00:00
|
|
|
class="mr-3"
|
2020-08-11 04:16:43 +00:00
|
|
|
:title="title"
|
|
|
|
ref="addList"
|
|
|
|
>
|
2020-08-15 06:39:19 +00:00
|
|
|
<b-icon-plus />
|
2020-08-11 04:16:43 +00:00
|
|
|
</b-button>
|
|
|
|
|
|
|
|
<b-modal
|
|
|
|
:id="modalId"
|
|
|
|
:title="title"
|
|
|
|
@shown="reset"
|
|
|
|
>
|
|
|
|
<form ref="addListForm" @submit.stop.prevent="submit">
|
|
|
|
<b-form-input
|
|
|
|
autofocus
|
|
|
|
v-model="listName"
|
|
|
|
:placeholder="$t('list.placeholder')"
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
|
|
|
|
<b-alert
|
|
|
|
class="mt-3 mb-0"
|
2020-08-14 23:58:55 +00:00
|
|
|
:show="isDuplicate && !saving"
|
2020-08-11 04:16:43 +00:00
|
|
|
variant="warning"
|
|
|
|
>
|
|
|
|
{{ $t('list.duplicateWarning') }}
|
|
|
|
</b-alert>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<template v-slot:modal-footer="{ cancel }">
|
|
|
|
<b-button @click="cancel">
|
|
|
|
Cancel
|
|
|
|
</b-button>
|
|
|
|
|
|
|
|
<b-button
|
|
|
|
variant="primary"
|
|
|
|
:disabled="saving || isDuplicate"
|
|
|
|
@click="submit"
|
|
|
|
>
|
|
|
|
<b-spinner small v-if="saving" />
|
|
|
|
<span v-else>{{ buttonLabel }}</span>
|
|
|
|
</b-button>
|
|
|
|
</template>
|
|
|
|
</b-modal>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { mapState } from 'vuex';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
listName: '',
|
|
|
|
saving: false,
|
2020-08-18 18:55:39 +00:00
|
|
|
modalId: 'add-list',
|
2020-08-11 04:16:43 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState(['gameLists', 'platform']),
|
|
|
|
|
|
|
|
lists() {
|
|
|
|
return this.gameLists[this.platform.code];
|
|
|
|
},
|
|
|
|
|
|
|
|
title() {
|
|
|
|
return this.isEmptyBoard
|
|
|
|
? this.$t('list.addFirstTime')
|
|
|
|
: this.$t('list.add');
|
|
|
|
},
|
|
|
|
|
|
|
|
buttonLabel() {
|
|
|
|
return this.isEmptyBoard
|
|
|
|
? this.$t('list.getStarted')
|
|
|
|
: this.$t('global.save');
|
|
|
|
},
|
|
|
|
|
|
|
|
existingListNames() {
|
|
|
|
return this.lists
|
|
|
|
? this.lists.map(({ name }) => name.toLowerCase())
|
|
|
|
: [];
|
|
|
|
},
|
|
|
|
|
|
|
|
isDuplicate() {
|
|
|
|
return this.existingListNames.includes(this.listName.toLowerCase());
|
|
|
|
},
|
|
|
|
|
|
|
|
isEmptyBoard() {
|
|
|
|
const newList = this.gameLists && this.platform && !this.gameLists[this.platform.code];
|
|
|
|
const emptyList = this.gameLists[this.platform.code]
|
|
|
|
&& this.gameLists[this.platform.code].length === 0;
|
|
|
|
|
|
|
|
return newList || emptyList;
|
|
|
|
},
|
|
|
|
|
|
|
|
disabled() {
|
|
|
|
return this.isDuplicate || !this.listName;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
reset() {
|
|
|
|
this.listName = '';
|
|
|
|
},
|
|
|
|
|
|
|
|
submit(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if (this.$refs.addListForm.checkValidity()) {
|
|
|
|
this.addList();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addList() {
|
|
|
|
const list = {
|
|
|
|
games: [],
|
|
|
|
name: this.listName,
|
|
|
|
};
|
|
|
|
|
2020-08-14 23:58:55 +00:00
|
|
|
this.saving = true;
|
|
|
|
|
2020-08-18 22:01:16 +00:00
|
|
|
this.$store.dispatch('ADD_LIST_LEGACY', list)
|
2020-08-11 04:16:43 +00:00
|
|
|
.then(() => {
|
|
|
|
this.$bvToast.toast('List added', {
|
|
|
|
variant: 'success',
|
|
|
|
});
|
2020-08-14 23:58:55 +00:00
|
|
|
this.saving = true;
|
2020-08-11 04:16:43 +00:00
|
|
|
this.$bvModal.hide(this.modalId);
|
|
|
|
this.scroll();
|
|
|
|
});
|
2020-08-14 23:58:55 +00:00
|
|
|
|
|
|
|
// TODO: catch and make async
|
2020-08-11 04:16:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
scroll() {
|
|
|
|
this.$nextTick(() => {
|
2020-08-14 23:58:55 +00:00
|
|
|
const board = document.querySelector('.board');
|
2020-08-11 04:16:43 +00:00
|
|
|
|
2020-08-14 23:58:55 +00:00
|
|
|
board.scrollLeft = board.scrollWidth;
|
2020-08-11 04:16:43 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|