file: create movies for movie app
This commit is contained in:
1 parent
81b2cf2bd7
commit
0e4cc5842a
17 files changed
+28727
No files matched your search
+268
@@ -0,0 +1,268 @@
|
||||
<template>
|
||||
<div class="home">
|
||||
<!-- Hero -->
|
||||
<Hero />
|
||||
|
||||
<!-- Search -->
|
||||
<div class="container search">
|
||||
<input
|
||||
v-model.lazy="searchInput"
|
||||
type="text"
|
||||
placeholder="Search"
|
||||
@keyup.enter="$fetch"
|
||||
/>
|
||||
<button v-show="searchInput !== ''" class="button" @click="clearSearch">
|
||||
Clear Search
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Loading -->
|
||||
<BaseLoader v-if="$fetchState.pending" />
|
||||
|
||||
<!-- Movies -->
|
||||
<div v-else class="container movies">
|
||||
<!-- Searched Movies -->
|
||||
<div v-if="searchInput !== ''" id="movie-grid" class="movies-grid">
|
||||
<div
|
||||
v-for="(movie, index) in searchedMovies"
|
||||
:key="index"
|
||||
class="movie"
|
||||
>
|
||||
<div class="movie-img">
|
||||
<img
|
||||
:src="`https://image.tmdb.org/t/p/w500${movie.poster_path}`"
|
||||
alt=""
|
||||
/>
|
||||
<p class="review">{{ movie.vote_average }}</p>
|
||||
<p class="overview">{{ movie.overview }}</p>
|
||||
</div>
|
||||
<div class="info">
|
||||
<p class="title">
|
||||
{{ movie.title.slice(0, 25) }}
|
||||
<span v-if="movie.title.length > 25">...</span>
|
||||
</p>
|
||||
<p class="release">
|
||||
Released:
|
||||
{{
|
||||
new Date(movie.release_date).toLocaleString('en-us', {
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
})
|
||||
}}
|
||||
</p>
|
||||
<NuxtLink
|
||||
class="button button-light"
|
||||
:to="{ name: 'movies-movieid', params: { movieid: movie.id } }"
|
||||
>
|
||||
Get More Info
|
||||
</NuxtLink>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Now Streaming -->
|
||||
<div v-else id="movie-grid" class="movies-grid">
|
||||
<div v-for="(movie, index) in movies" :key="index" class="movie">
|
||||
<div class="movie-img">
|
||||
<img
|
||||
:src="`https://image.tmdb.org/t/p/w500${movie.poster_path}`"
|
||||
alt=""
|
||||
/>
|
||||
<p class="review">{{ movie.vote_average }}</p>
|
||||
<p class="overview">{{ movie.overview }}</p>
|
||||
</div>
|
||||
<div class="info">
|
||||
<p class="title">
|
||||
{{ movie.title.slice(0, 25) }}
|
||||
<span v-if="movie.title.length > 25">...</span>
|
||||
</p>
|
||||
<p class="release">
|
||||
Released:
|
||||
{{
|
||||
new Date(movie.release_date).toLocaleString('en-us', {
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
})
|
||||
}}
|
||||
</p>
|
||||
<NuxtLink
|
||||
class="button button-light"
|
||||
:to="{ name: 'movies-movieid', params: { movieid: movie.id } }"
|
||||
>
|
||||
Get More Info
|
||||
</NuxtLink>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from 'axios'
|
||||
|
||||
export default {
|
||||
name: 'IndexPage',
|
||||
data() {
|
||||
return {
|
||||
movies: [],
|
||||
searchInput: '',
|
||||
searchedMovies: [],
|
||||
}
|
||||
},
|
||||
async fetch() {
|
||||
if (this.searchInput === '') {
|
||||
await this.getMovies()
|
||||
} else {
|
||||
await this.searchMovies()
|
||||
}
|
||||
},
|
||||
fetchDelay: 1000,
|
||||
head() {
|
||||
return {
|
||||
title: 'Movie App - Latest Streaming Movie Info',
|
||||
meta: [
|
||||
{
|
||||
hid: 'description',
|
||||
name: 'description',
|
||||
content: 'Get all the latest streaming movies in theaters & online',
|
||||
},
|
||||
{
|
||||
hid: 'keywords',
|
||||
name: 'keywords',
|
||||
content: 'movie, stream, streaming',
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async getMovies() {
|
||||
const data = axios.get(
|
||||
`https://api.themoviedb.org/3/movie/now_playing?api_key=${process.env.NUXT_ENV_MOVIE_DB_API}&language=en-US&page=1`
|
||||
)
|
||||
const result = await data
|
||||
result.data.results.forEach((movie) => {
|
||||
this.movies.push(movie)
|
||||
})
|
||||
},
|
||||
async searchMovies() {
|
||||
const data = axios.get(
|
||||
`https://api.themoviedb.org/3/search/movie?api_key=${process.env.NUXT_ENV_MOVIE_DB_API}&language=en-US&page=1&query=${this.searchInput}`
|
||||
)
|
||||
const result = await data
|
||||
result.data.results.forEach((movie) => {
|
||||
this.searchedMovies.push(movie)
|
||||
})
|
||||
},
|
||||
clearSearch() {
|
||||
this.searchInput = ''
|
||||
this.searchedMovies = []
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.home {
|
||||
.loading {
|
||||
padding-top: 120px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.search {
|
||||
display: flex;
|
||||
padding: 32px 16px;
|
||||
input {
|
||||
max-width: 350px;
|
||||
width: 100%;
|
||||
padding: 12px 6px;
|
||||
font-size: 14px;
|
||||
border: none;
|
||||
&:focus {
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
.button {
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
}
|
||||
.movies {
|
||||
padding: 32px 16px;
|
||||
.movies-grid {
|
||||
display: grid;
|
||||
column-gap: 32px;
|
||||
row-gap: 64px;
|
||||
grid-template-columns: 1fr;
|
||||
@media (min-width: 500px) {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
@media (min-width: 750px) {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
@media (min-width: 1100px) {
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
}
|
||||
.movie {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
.movie-img {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
&:hover {
|
||||
.overview {
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.review {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background-color: #c92502;
|
||||
color: #fff;
|
||||
border-radius: 0 0 16px 0;
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
|
||||
0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
.overview {
|
||||
line-height: 1.5;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
background-color: rgba(201, 38, 2, 0.9);
|
||||
padding: 12px;
|
||||
color: #fff;
|
||||
transform: translateY(100%);
|
||||
transition: 0.3s ease-in-out all;
|
||||
}
|
||||
}
|
||||
.info {
|
||||
margin-top: auto;
|
||||
.title {
|
||||
margin-top: 8px;
|
||||
color: #fff;
|
||||
font-size: 20px;
|
||||
}
|
||||
.release {
|
||||
margin-top: 8px;
|
||||
color: #c9c9c9;
|
||||
}
|
||||
.button {
|
||||
margin-top: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,142 @@
|
||||
<template>
|
||||
<BaseLoader v-if="$fetchState.pending" />
|
||||
<div v-else class="container single-movie">
|
||||
<NuxtLink class="button" :to="{ name: 'index' }">Back</NuxtLink>
|
||||
<div class="movie-info">
|
||||
<div class="movie-img">
|
||||
<img
|
||||
:src="`https://image.tmdb.org/t/p/w500${movie.poster_path}`"
|
||||
alt=""
|
||||
/>
|
||||
</div>
|
||||
<div class="movie-content">
|
||||
<h1>Title: {{ movie.title }}</h1>
|
||||
<p class="movie-fact tagline">
|
||||
<span>Tagline:</span> "{{ movie.tagline }}"
|
||||
</p>
|
||||
<p class="movie-fact">
|
||||
<span>Released:</span>
|
||||
{{
|
||||
new Date(movie.release_date).toLocaleString('en-us', {
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
})
|
||||
}}
|
||||
</p>
|
||||
<p class="movie-fact">
|
||||
<span>Duration:</span> {{ movie.runtime }} minutes
|
||||
</p>
|
||||
<p class="movie-fact">
|
||||
<span>Revenue:</span>
|
||||
{{
|
||||
movie.revenue.toLocaleString('en-us', {
|
||||
style: 'currency',
|
||||
currency: 'USD',
|
||||
})
|
||||
}}
|
||||
</p>
|
||||
<p class="movie-fact"><span>Overview:</span> {{ movie.overview }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from 'axios'
|
||||
export default {
|
||||
name: 'SingleMovie',
|
||||
data() {
|
||||
return {
|
||||
movie: '',
|
||||
}
|
||||
},
|
||||
async fetch() {
|
||||
await this.getSingleMovie()
|
||||
},
|
||||
fetchDelay: 1000,
|
||||
head() {
|
||||
return {
|
||||
title: this.movie.title,
|
||||
meta: [
|
||||
{
|
||||
hid: 'description',
|
||||
name: 'description',
|
||||
content: 'Get all the latest streaming movies in theaters & online',
|
||||
},
|
||||
{
|
||||
hid: 'keywords',
|
||||
name: 'keywords',
|
||||
content: 'movie, stream, streaming',
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async getSingleMovie() {
|
||||
const data = axios.get(
|
||||
`https://api.themoviedb.org/3/movie/${this.$route.params.movieid}?api_key=${process.env.NUXT_ENV_MOVIE_DB_API}&language=en-US`
|
||||
)
|
||||
const result = await data
|
||||
this.movie = result.data
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.single-movie {
|
||||
color: #fff;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
padding: 32px 16px;
|
||||
.button {
|
||||
align-self: flex-start;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
.movie-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 32px;
|
||||
color: #fff;
|
||||
@media (min-width: 800px) {
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.movie-img {
|
||||
img {
|
||||
max-height: 500px;
|
||||
width: 100%;
|
||||
@media (min-width: 800px) {
|
||||
max-height: 700px;
|
||||
width: initial;
|
||||
}
|
||||
}
|
||||
}
|
||||
.movie-content {
|
||||
h1 {
|
||||
font-size: 56px;
|
||||
font-weight: 400;
|
||||
}
|
||||
.movie-fact {
|
||||
margin-top: 12px;
|
||||
font-size: 20px;
|
||||
line-height: 1.5;
|
||||
span {
|
||||
font-weight: 600;
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
.tagline {
|
||||
font-style: italic;
|
||||
span {
|
||||
font-style: normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user