aboutsummaryrefslogtreecommitdiff
path: root/src/site/pages/dashboard/index.vue
blob: 71df7eb66ca5570564670d7f8ebb7eef042bfb67 (plain) (blame)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<template>
	<section class="section is-fullheight dashboard">
		<div class="container">
			<div class="columns is-variable is-0-mobile">
				<div class="column is-narrow">
					<Sidebar />
				</div>
				<div class="column">
					<nav class="level">
						<div class="level-left">
							<div class="level-item">
								<h2 class="subtitle">
									Your uploaded files
								</h2>
							</div>
						</div>
						<div class="level-right">
							<div class="level-item">
								<b-field>
									<b-input
										placeholder="Search"
										type="search" />
									<p class="control">
										<button
											outlined
											class="button is-primary">
											Search
										</button>
									</p>
								</b-field>
							</div>
						</div>
					</nav>
					<hr>

					<b-loading :active="images.isLoading" />

					<Grid
						v-if="totalFiles && !isLoading"
						:files="images.files"
						:enableSearch="false"
						class="grid"
						@delete="handleFileDelete">
						<template v-slot:pagination>
							<b-pagination
								v-if="shouldPaginate"
								:total="totalFiles"
								:per-page="limit"
								:current.sync="current"
								range-before="2"
								range-after="2"
								class="pagination-slot"
								icon-prev="icon-interface-arrow-left"
								icon-next="icon-interface-arrow-right"
								icon-pack="icon"
								aria-next-label="Next page"
								aria-previous-label="Previous page"
								aria-page-label="Page"
								aria-current-label="Current page" />
						</template>
					</Grid>
				</div>
			</div>
		</div>
	</section>
</template>

<script>
import { mapState, mapGetters, mapActions } from 'vuex';

import Sidebar from '~/components/sidebar/Sidebar.vue';
import Grid from '~/components/grid/Grid.vue';

export default {
	components: {
		Sidebar,
		Grid,
	},
	middleware: ['auth', ({ store }) => {
		store.dispatch('images/fetch');
	}],
	data() {
		return {
			current: 1,
			isLoading: false,
		};
	},
	computed: {
		...mapGetters({
			totalFiles: 'images/getTotalFiles',
			shouldPaginate: 'images/shouldPaginate',
			limit: 'images/getLimit',
		}),
		...mapState(['images']),
	},
	metaInfo() {
		return { title: 'Uploads' };
	},
	watch: {
		current: 'fetchPaginate',
	},
	methods: {
		...mapActions({
			fetch: 'images/fetch',
		}),
		async fetchPaginate() {
			this.isLoading = true;
			await this.fetch(this.current);
			this.isLoading = false;
		},
		handleFileDelete(file) {
			console.log('yep!', file.id);
		},
	},
};
</script>

<style lang="scss" scoped>
	div.grid {
		margin-bottom: 1rem;
	}

	.pagination-slot {
		padding: 1rem 0;
	}
</style>

<style lang="scss">
	.pagination-slot > .pagination-previous, .pagination-slot > .pagination-next {
		display: none !important;
	}
</style>