2020-07-25 01:44:19 +00:00
|
|
|
<template>
|
|
|
|
<div class="movies">
|
2020-08-15 17:04:33 +00:00
|
|
|
<div class="content-inner">
|
2021-08-21 23:26:09 +00:00
|
|
|
<SearchBar :placeholder="`Search ${totalCount} movies`" />
|
2021-08-21 22:40:22 +00:00
|
|
|
|
2020-08-15 17:04:33 +00:00
|
|
|
<div class="tiles">
|
|
|
|
<MovieTile
|
|
|
|
v-for="movie in movies"
|
|
|
|
:key="`movie-${movie.id}`"
|
|
|
|
:movie="movie"
|
|
|
|
/>
|
|
|
|
</div>
|
2021-08-21 22:40:22 +00:00
|
|
|
|
|
|
|
<Pagination
|
|
|
|
v-if="totalCount > 0"
|
|
|
|
:items-total="totalCount"
|
|
|
|
:items-per-page="limit"
|
|
|
|
class="pagination-bottom"
|
|
|
|
/>
|
2020-08-01 13:11:07 +00:00
|
|
|
</div>
|
2020-08-15 17:04:33 +00:00
|
|
|
|
|
|
|
<Footer />
|
2020-07-25 01:44:19 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2020-08-01 13:11:07 +00:00
|
|
|
<script>
|
2020-08-12 01:30:20 +00:00
|
|
|
import MovieTile from './movie-tile.vue';
|
2021-08-21 23:26:09 +00:00
|
|
|
import SearchBar from '../search/bar.vue';
|
2021-08-21 22:40:22 +00:00
|
|
|
import Pagination from '../pagination/pagination.vue';
|
|
|
|
|
|
|
|
async function fetchMovies() {
|
|
|
|
if (this.$route.query.query) {
|
|
|
|
await this.searchMovies();
|
|
|
|
return;
|
|
|
|
}
|
2020-08-01 13:11:07 +00:00
|
|
|
|
|
|
|
const { movies, totalCount } = await this.$store.dispatch('fetchMovies', {
|
2021-08-21 22:40:22 +00:00
|
|
|
limit: this.limit,
|
|
|
|
range: this.$route.params.range,
|
|
|
|
pageNumber: this.$route.params.pageNumber,
|
2020-08-01 13:11:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.movies = movies;
|
|
|
|
this.totalCount = totalCount;
|
|
|
|
}
|
|
|
|
|
2021-08-21 22:40:22 +00:00
|
|
|
async function searchMovies() {
|
2021-08-22 20:25:20 +00:00
|
|
|
const { movies, totalCount } = await this.$store.dispatch('searchMovies', {
|
2021-08-21 22:40:22 +00:00
|
|
|
query: this.$route.query.query,
|
|
|
|
limit: this.limit,
|
2021-08-22 20:25:20 +00:00
|
|
|
pageNumber: this.$route.params.pageNumber,
|
2021-08-21 22:40:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.movies = movies;
|
2021-08-22 20:25:20 +00:00
|
|
|
this.totalCount = totalCount;
|
2021-08-21 22:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function mounted() {
|
|
|
|
this.pageTitle = 'Movies';
|
|
|
|
|
|
|
|
await this.fetchMovies();
|
|
|
|
}
|
|
|
|
|
2020-08-01 13:11:07 +00:00
|
|
|
export default {
|
|
|
|
components: {
|
2020-08-12 01:30:20 +00:00
|
|
|
MovieTile,
|
2021-08-21 23:26:09 +00:00
|
|
|
SearchBar,
|
2021-08-21 22:40:22 +00:00
|
|
|
Pagination,
|
2020-08-01 13:11:07 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
movies: [],
|
|
|
|
totalCount: 0,
|
2021-08-21 22:40:22 +00:00
|
|
|
limit: 30,
|
2020-08-01 13:11:07 +00:00
|
|
|
};
|
|
|
|
},
|
2021-08-21 22:40:22 +00:00
|
|
|
watch: {
|
|
|
|
$route: fetchMovies,
|
|
|
|
},
|
2020-08-01 13:11:07 +00:00
|
|
|
mounted,
|
2021-08-21 22:40:22 +00:00
|
|
|
methods: {
|
|
|
|
fetchMovies,
|
|
|
|
searchMovies,
|
|
|
|
},
|
2020-08-01 13:11:07 +00:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
2020-08-12 01:30:20 +00:00
|
|
|
<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
|
|
|
}
|
2020-08-01 13:11:07 +00:00
|
|
|
|
2021-08-21 22:40:22 +00:00
|
|
|
.content-inner {
|
|
|
|
padding: 0 1rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.search {
|
|
|
|
margin: 1rem 0;
|
|
|
|
}
|
|
|
|
|
2020-08-01 13:11:07 +00:00
|
|
|
.tiles {
|
|
|
|
display: grid;
|
2020-08-10 19:39:55 +00:00
|
|
|
grid-template-columns: repeat(auto-fill, minmax(25rem, 1fr));
|
2020-08-08 16:10:59 +00:00
|
|
|
grid-gap: 1rem;
|
2021-08-21 22:40:22 +00:00
|
|
|
margin: 0 0 1rem 0;
|
2020-08-01 13:11:07 +00:00
|
|
|
}
|
2020-08-12 01:30:20 +00:00
|
|
|
|
2021-08-21 22:40:22 +00:00
|
|
|
@media(max-width: $breakpoint-kilo) {
|
2020-08-12 01:30:20 +00:00
|
|
|
.tiles {
|
|
|
|
grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
|
|
|
|
}
|
|
|
|
}
|
2020-07-25 01:44:19 +00:00
|
|
|
</style>
|