gamebrary/src/components/WallpapersList.vue

132 lines
2.8 KiB
Vue
Raw Normal View History

2021-02-18 00:50:37 +00:00
<template lang="html">
2021-02-20 16:53:38 +00:00
<div class="wallpapers">
2021-02-21 18:17:58 +00:00
<preview-wallpaper-modal
:wallpaper="activeWallpaper"
:selectable="selectable"
@selected="selected"
2021-02-21 18:17:58 +00:00
/>
2021-02-21 18:13:06 +00:00
2021-02-18 00:50:37 +00:00
<b-card
v-for="wallpaper in wallpapers"
:key="wallpaper.name"
:img-src="wallpaper.url"
:img-alt="wallpaper.name"
img-top
img-width="180"
2021-03-11 00:06:47 +00:00
class="mb-3 mx-0 p-0 overflow-hidden word-wrap clickable"
@click="openModal(wallpaper)"
2021-02-18 00:50:37 +00:00
>
<h6>
{{ wallpaper.name }}
<b-badge v-if="wallpaper.metadata && wallpaper.metadata.size">
2021-02-22 17:33:22 +00:00
{{ formatSize(wallpaper) }}
2021-02-18 00:50:37 +00:00
</b-badge>
</h6>
<b-button
variant="danger"
@click.stop="confirmDeleteWallpaper(wallpaper)"
2021-02-18 00:50:37 +00:00
>
<i class="fas fa-trash-alt fa-fw" aria-hidden />
</b-button>
<b-button
v-if="selectable"
variant="primary"
@click.stop="selected(wallpaper)"
2021-02-18 00:50:37 +00:00
>
<i
v-if="saving"
class="fas fa-sync fa-spin fa-fw"
aria-hidden
/>
<span v-else>Select</span>
</b-button>
</b-card>
</div>
</template>
<script>
2021-02-21 18:13:06 +00:00
import PreviewWallpaperModal from '@/components/Wallpapers/PreviewWallpaperModal';
2021-02-22 17:33:22 +00:00
import { bytesToSize } from '@/utils';
2021-02-18 00:50:37 +00:00
import { mapState } from 'vuex';
export default {
2021-02-21 18:13:06 +00:00
components: {
PreviewWallpaperModal,
},
2021-02-18 00:50:37 +00:00
props: {
selectable: Boolean,
saving: Boolean,
},
2021-02-21 18:13:06 +00:00
data() {
return {
activeWallpaper: false,
};
},
2021-02-18 00:50:37 +00:00
computed: {
...mapState(['wallpapers']),
},
methods: {
2021-02-21 18:13:06 +00:00
openModal(wallpaper) {
this.activeWallpaper = wallpaper;
this.$bvModal.show('previewWallpaper');
},
selected(wallpaper) {
2021-02-18 00:50:37 +00:00
if (this.selectable) {
this.$emit('selected', wallpaper);
}
},
2021-02-22 17:33:22 +00:00
formatSize(wallpaper) {
const size = wallpaper && wallpaper.metadata && wallpaper.metadata.size
? wallpaper.metadata.size
: 0;
2021-02-18 00:50:37 +00:00
2021-02-22 17:33:22 +00:00
return bytesToSize(size);
2021-02-18 00:50:37 +00:00
},
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', { variant: 'danger' });
});
this.$bvToast.toast('File deleted');
},
},
};
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
.wallpapers {
display: grid;
grid-column-gap: 1rem;
grid-template-columns: 1fr 1fr 1fr;
@media(max-width: 720px) {
2021-03-11 00:06:47 +00:00
grid-template-columns: 1fr;
2021-02-18 00:50:37 +00:00
}
}
</style>