2020-08-11 04:16:43 +00:00
|
|
|
<template lang="html">
|
|
|
|
<b-dropdown-item-button v-b-modal="modalId">
|
2020-08-11 23:39:11 +00:00
|
|
|
<b-icon-textarea-t /> Rename list
|
2020-08-11 04:16:43 +00:00
|
|
|
|
|
|
|
<b-modal
|
|
|
|
:id="modalId"
|
|
|
|
title="Rename list"
|
|
|
|
@shown="getListName"
|
|
|
|
>
|
|
|
|
<form ref="renameListForm" @submit.stop.prevent="submit">
|
|
|
|
<b-form-input
|
|
|
|
ref="listNameField"
|
|
|
|
autofocus
|
2020-08-11 23:39:11 +00:00
|
|
|
v-model.trim="listName"
|
2020-08-11 04:16:43 +00:00
|
|
|
placeholder="Enter your name"
|
|
|
|
required
|
|
|
|
/>
|
2020-08-11 23:39:11 +00:00
|
|
|
|
|
|
|
<b-alert
|
|
|
|
class="mt-3 mb-0"
|
|
|
|
:show="isDuplicate"
|
|
|
|
variant="warning"
|
|
|
|
>
|
|
|
|
{{ $t('list.duplicateWarning') }}
|
|
|
|
</b-alert>
|
2020-08-11 04:16:43 +00:00
|
|
|
</form>
|
|
|
|
|
|
|
|
<template v-slot:modal-footer="{ cancel }">
|
|
|
|
<b-button @click="cancel">
|
|
|
|
Cancel
|
|
|
|
</b-button>
|
|
|
|
|
|
|
|
<b-button
|
|
|
|
variant="primary"
|
2020-08-11 23:39:11 +00:00
|
|
|
:disabled="saving || !dirtied || isDuplicate"
|
2020-08-11 04:16:43 +00:00
|
|
|
@click="submit"
|
|
|
|
>
|
|
|
|
<b-spinner small v-if="saving" />
|
|
|
|
<span v-else>Save</span>
|
|
|
|
</b-button>
|
|
|
|
</template>
|
|
|
|
</b-modal>
|
|
|
|
</b-dropdown-item-button>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { mapState } from 'vuex';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
listIndex: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
default: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
listName: null,
|
|
|
|
saving: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState(['gameLists', 'platform']),
|
|
|
|
|
|
|
|
modalId() {
|
|
|
|
return `rename-list-${this.listIndex}`;
|
|
|
|
},
|
2020-08-11 23:39:11 +00:00
|
|
|
|
|
|
|
dirtied() {
|
|
|
|
const { name } = this.gameLists[this.platform.code][this.listIndex];
|
|
|
|
|
|
|
|
return this.listName && name !== this.listName;
|
|
|
|
},
|
|
|
|
|
|
|
|
existingListNames() {
|
|
|
|
const lists = this.gameLists[this.platform.code];
|
|
|
|
const currentList = lists[this.listIndex];
|
|
|
|
|
|
|
|
return lists.map(list => list.name.toLowerCase())
|
|
|
|
.filter(name => name !== currentList.name.toLowerCase());
|
|
|
|
},
|
|
|
|
|
|
|
|
isDuplicate() {
|
|
|
|
return this.listName && this.existingListNames.includes(this.listName.toLowerCase());
|
|
|
|
},
|
2020-08-11 04:16:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
getListName() {
|
|
|
|
const { name } = this.gameLists[this.platform.code][this.listIndex];
|
|
|
|
|
|
|
|
this.listName = name;
|
|
|
|
},
|
|
|
|
|
|
|
|
submit(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if (this.$refs.renameListForm.checkValidity()) {
|
|
|
|
this.save();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async save() {
|
|
|
|
this.saving = true;
|
|
|
|
|
|
|
|
const gameLists = JSON.parse(JSON.stringify(this.gameLists));
|
|
|
|
|
|
|
|
gameLists[this.platform.code][this.listIndex].name = this.listName;
|
|
|
|
|
2020-08-18 21:35:32 +00:00
|
|
|
await this.$store.dispatch('SAVE_LIST_LEGACY', gameLists)
|
2020-08-11 04:16:43 +00:00
|
|
|
.catch(() => {
|
|
|
|
this.saving = false;
|
|
|
|
|
|
|
|
this.$bvToast.toast('There was an error renaming list', {
|
|
|
|
title: 'Error',
|
|
|
|
variant: 'danger',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.saving = false;
|
|
|
|
|
|
|
|
this.$bvToast.toast('List renamed', {
|
|
|
|
title: 'Saved',
|
|
|
|
variant: 'success',
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$bvModal.hide(this.modalId);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" rel="stylesheet/scss" scoped>
|
|
|
|
</style>
|