1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
<template>
<section class="hero is-fullheight dashboard">
<div class="hero-body">
<div class="container">
<div class="columns">
<div class="column is-narrow">
<Sidebar />
</div>
<div class="column">
<h2 class="subtitle">
Manage your albums
</h2>
<hr>
<div class="search-container">
<b-field>
<b-input
v-model="newAlbumName"
class="chibisafe-input"
placeholder="Album name..."
type="text"
@keyup.enter.native="createAlbum" />
<p class="control">
<button
outlined
class="button is-black"
:disabled="isCreatingAlbum"
@click="createAlbum">
Create album
</button>
</p>
</b-field>
</div>
<div class="view-container">
<AlbumEntry
v-for="album in albums.list"
:key="album.id"
:album="album" />
</div>
</div>
</div>
</div>
</div>
</section>
</template>
<script>
import { mapState, mapActions } from 'vuex';
import Sidebar from '~/components/sidebar/Sidebar.vue';
import AlbumEntry from '~/components/album/AlbumEntry.vue';
export default {
components: {
Sidebar,
AlbumEntry
},
middleware: ['auth'],
data() {
return {
newAlbumName: null,
isCreatingAlbum: false
};
},
computed: mapState(['config', 'albums']),
async asyncData({ app }) {
await app.store.dispatch('albums/fetch');
},
methods: {
...mapActions({
alert: 'alert/set'
}),
async createAlbum() {
if (!this.newAlbumName || this.newAlbumName === '') return;
this.isCreatingAlbum = true;
try {
const response = await this.$store.dispatch('albums/createAlbum', this.newAlbumName);
this.alert({ text: response.message, error: false });
} catch (e) {
this.alert({ text: e.message, error: true });
} finally {
this.isCreatingAlbum = false;
this.newAlbumName = null;
}
}
},
head() {
return {
title: 'Albums'
};
}
};
</script>
<style lang="scss" scoped>
@import '~/assets/styles/_colors.scss';
div.view-container {
padding: 2rem;
}
div.search-container {
padding: 1rem 2rem;
// background-color: $base-2;
}
div.column > h2.subtitle { padding-top: 1px; }
</style>
|