traxxx/assets/components/releases/movies.vue

123 lines
2.0 KiB
Vue
Raw Normal View History

2020-07-25 01:44:19 +00:00
<template>
<div class="movies">
2020-08-15 17:04:33 +00:00
<div class="content-inner">
<SearchBar :placeholder="`Search ${totalCount} movies`" />
<div
ref="tiles"
class="tiles"
>
2020-08-15 17:04:33 +00:00
<MovieTile
v-for="movie in movies"
:key="`movie-${movie.id}`"
:movie="movie"
/>
</div>
<Pagination
v-if="totalCount > 0"
:items-total="totalCount"
:items-per-page="limit"
class="pagination-bottom"
/>
</div>
2020-08-15 17:04:33 +00:00
<Footer />
2020-07-25 01:44:19 +00:00
</div>
</template>
<script>
import MovieTile from './movie-tile.vue';
import SearchBar from '../search/bar.vue';
import Pagination from '../pagination/pagination.vue';
async function fetchMovies() {
if (this.$route.query.query) {
await this.searchMovies();
return;
}
const { movies, totalCount } = await this.$store.dispatch('fetchMovies', {
limit: this.limit,
range: this.$route.params.range,
pageNumber: this.$route.params.pageNumber,
});
this.movies = movies;
this.totalCount = totalCount;
this.$refs.tiles.scrollIntoView();
}
async function searchMovies() {
const { movies, totalCount } = await this.$store.dispatch('searchMovies', {
query: this.$route.query.query,
limit: this.limit,
pageNumber: this.$route.params.pageNumber,
});
this.movies = movies;
this.totalCount = totalCount;
}
async function mounted() {
this.pageTitle = 'Movies';
await this.fetchMovies();
}
export default {
components: {
MovieTile,
SearchBar,
Pagination,
},
data() {
return {
movies: [],
totalCount: 0,
2021-08-22 23:45:18 +00:00
limit: 30,
};
},
watch: {
$route: fetchMovies,
},
mounted,
methods: {
fetchMovies,
searchMovies,
},
};
</script>
<style lang="scss" scoped>
@import 'breakpoints';
2020-07-25 01:44:19 +00:00
.movies {
2020-08-15 17:04:33 +00:00
display: flex;
flex-direction: column;
flex-grow: 1;
2020-07-25 01:44:19 +00:00
}
.content-inner {
padding: 0 1rem;
}
.search {
margin: 1rem 0 0 0;
}
.tiles {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(25rem, 1fr));
grid-gap: 1rem;
padding: 1rem 0;
}
@media(max-width: $breakpoint-kilo) {
.tiles {
grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
}
}
2020-07-25 01:44:19 +00:00
</style>