gamebrary/src/pages/Wallpapers.vue

185 lines
4.7 KiB
Vue
Raw Normal View History

<template lang="html">
2020-09-28 23:25:36 +00:00
<div>
2020-09-26 00:09:20 +00:00
<b-jumbotron
2020-10-05 18:42:04 +00:00
:header="$t('wallpapers.title')"
:lead="$t('wallpapers.subtitle')"
2020-10-14 00:35:40 +00:00
:bg-variant="nightMode ? 'dark' : ''"
:text-variant="nightMode ? 'white' : ''"
:border-variant="nightMode ? 'dark' : ''"
2020-09-26 00:09:20 +00:00
header-level="5"
fluid
/>
<!-- TODO: show space used -->
<!-- TODO: allow to apply wallpaper to board from here -->
<b-container>
2020-10-05 18:42:04 +00:00
<!-- TODO: convert to form -->
<!-- TODO: translate "browse" -->
<!-- TODO: display file names -->
2020-10-14 00:35:40 +00:00
<h5>{{ $t('wallpapers.form.label') }}</h5>
2020-10-05 18:42:04 +00:00
<b-row class="mb-3">
2020-10-14 00:35:40 +00:00
<b-col cols="12" lg="6" class="mb-4">
<b-form-group
2020-10-05 18:42:04 +00:00
:description="$t('wallpapers.form.helperText')"
>
<b-form-file
v-model="file"
accept="image/*"
2020-10-05 18:42:04 +00:00
:placeholder="$t('wallpapers.form.placeholder')"
/>
</b-form-group>
<b-alert v-if="isDuplicate && !saving" show variant="warning">
2020-10-05 18:42:04 +00:00
{{ $t('wallpapers.form.duplicateMessage', { fileName: file.name }) }}
</b-alert>
<b-button
@click="uploadWallpaper"
variant="primary"
:disabled="!Boolean(file) || saving || isDuplicate"
>
<b-spinner small v-if="saving" />
2020-10-05 18:42:04 +00:00
<span v-else>{{ $t('wallpapers.form.upload') }}</span>
</b-button>
</b-col>
</b-row>
2020-10-14 00:35:40 +00:00
<h5>{{ $t('wallpapers.list.title') }}</h5>
<b-row
v-if="wallpapers.length"
v-for="wallpaper in wallpapers"
:key="wallpaper.name"
no-gutters
class="mb-4 border-bottom pb-4"
>
<b-col cols="6" lg="3" class="pr-3">
<b-img
:src="wallpaper.url"
thumbnail
class="rounded-0"
/>
</b-col>
2020-10-14 00:35:40 +00:00
<b-col cols="6">
<p>{{ wallpaper.name }}</p>
<b-button
variant="danger"
size="sm"
@click="confirmDeleteWallpaper(wallpaper)"
>
<icon name="trash" white />
</b-button>
</b-col>
</b-row>
<!-- <b-form-row v-if="wallpapers.length">
<b-col cols="12">
</b-col>
<b-col
v-for="wallpaper in wallpapers"
:key="wallpaper.name"
cols="6"
sm="4"
lg="3"
>
<b-card
class="mb-2"
header-class="py-0 px-2"
body-class="d-flex p-0 text-center justify-content-center align-items-center"
header-tag="small"
>
2020-10-14 00:35:40 +00:00
</b-card>
</b-col>
2020-10-14 00:35:40 +00:00
</b-form-row> -->
<b-alert show v-else>You don't have any wallpapers.</b-alert>
2020-09-26 00:09:20 +00:00
</b-container>
2020-09-28 23:25:36 +00:00
</div>
</template>
<script>
2020-10-14 00:35:40 +00:00
import { mapState, mapGetters } from 'vuex';
export default {
data() {
return {
file: null,
saving: false,
loading: false,
wallpaperUrls: [],
};
},
computed: {
...mapState(['user', 'board', 'wallpapers']),
2020-10-14 00:35:40 +00:00
...mapGetters(['nightMode']),
existingFiles() {
return this.wallpapers.map(({ name }) => name);
},
isDuplicate() {
const { file, existingFiles } = this;
return file && file.name && existingFiles.includes(file.name);
},
},
methods: {
async uploadWallpaper() {
const { file } = this;
this.saving = true;
await this.$store.dispatch('UPLOAD_WALLPAPER', file)
.catch(() => {
this.saving = false;
this.$bvToast.toast('There was an error uploading wallpaper', { title: 'Error', variant: 'danger' });
});
this.file = null;
this.saving = false;
this.$bvToast.toast(file.name, { title: 'File uploaded', variant: 'success' });
this.$bus.$emit('WALLPAPER_UPLOADED');
},
confirmDeleteWallpaper(file) {
this.$bvModal.msgBoxConfirm('Wallpaper will be permanently removed', {
title: 'Are you sure you want to delete this file?',
okVariant: 'danger',
okTitle: 'Yes',
})
.then((value) => {
if (value) {
this.deleteFile(file);
}
});
},
async deleteFile(file) {
await this.$store.dispatch('DELETE_WALLPAPER', file)
.catch(() => {
this.$bvToast.toast('There was an error deleting wallpaper', { title: 'Error', variant: 'danger' });
});
this.$bvToast.toast(file.name, { title: 'File deleted', variant: 'success' });
// const { board } = this;
// TODO: handle wallpapers in use
// if (board.wallpaper && this.board.wallpaper === file.path) {
// this.$bus.$emit('RELOAD_WALLPAPER');
// }
},
},
};
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
.delete-file {
bottom: .5rem;
right: .5rem;
}
</style>