version 1.0

This commit is contained in:
Dmytro Barylo
2017-03-04 16:46:53 +02:00
commit ac6d57b46f
44 changed files with 2145 additions and 0 deletions

65
src/components/404.vue Normal file
View File

@@ -0,0 +1,65 @@
<template>
<section class="not-found">
<div class="not-found__content">
<h2 class="not-found__title">Page Not Found</h2>
</div>
</section>
</template>
<script>
import storage from '../storage.js'
export default {
created(){
document.title = 'Page Not Found' + storage.pageTitlePostfix;
}
}
</script>
<style lang="scss">
@import "./src/scss/variables";
@import "./src/scss/media-queries";
.not-found{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url('~assets/pulp-fiction.jpg') no-repeat 50% 50%;
background-size: cover;
display: flex;
align-items: center;
justify-content: center;
&:before{
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba($c-light, 0.7);
}
&__content{
width: 100%;
padding: 0 20px;
text-align: center;
@include tablet-min{
padding: 0 40px 40px 0;
}
}
&__title{
font-size: 24px;
font-weight: 500;
color: $c-dark;
position: relative;
margin: 0;
@include tablet-min{
font-size: 28px;
}
}
&__button{
position: relative;
margin-top: 20px;
}
}
</style>

127
src/components/Home.vue Normal file
View File

@@ -0,0 +1,127 @@
<template>
<section class="home">
<header class="home__header">
<div class="home__header-wrap">
<h1 class="home__header-title">The Movie DB App</h1>
<strong class="home__header-subtitle">Made with Vue.js</strong>
<a href="https://github.com/dmtrbrl/tmdb-app" target="_blank" class="home__header-link">
<svg class="home__header-link-icon">
<use xlink:href="#iconGithub"></use>
</svg>
<span>View Code</span>
</a>
</div>
</header>
<movies-list v-for="item in listTypes" v-if="item.isCategory" :type="'component'" :mode="'collection'" :category="item.query" :shortList="true"></movies-list>
</section>
</template>
<script>
import axios from 'axios'
import storage from '../storage.js'
import MoviesList from './MoviesList.vue'
export default {
components: { MoviesList },
data(){
return {
listTypes: storage.listTypes
}
},
created(){
document.title = 'TMDb';
storage.backTitle = document.title;
}
}
</script>
<style lang="scss">
@import "./src/scss/variables";
@import "./src/scss/media-queries";
.home{
&__header{
width: 100%;
height: 200px;
display: flex;
align-items: center;
justify-content: center;
background-size: cover;
background-repeat: no-repeat;
background-position: 50% 50%;
position: relative;
background-color: $c-dark;
background-image: url('~assets/pulp-fiction.jpg');
@include tablet-min{
height: 384px;
}
&:before{
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba($c-light, 0.7);
}
&-wrap{
text-align: center;
position: relative;
}
&-title{
font-weight: 500;
font-size: 22px;
text-transform: uppercase;
letter-spacing: 0.5px;
color: $c-dark;
margin: 0;
@include tablet-min{
font-size: 28px;
}
}
&-subtitle{
display: block;
font-size: 14px;
font-weight: 300;
color: $c-dark;
margin: 5px 0;
@include tablet-min{
font-size: 16px;
}
}
&-link{
text-decoration: none;
color: $c-dark;
font-size: 13px;
font-weight: 300;
opacity: 0.7;
transition: opacity 0.5s ease;
&:hover{
opacity: 1;
}
span{
display: inline-block;
vertical-align: middle;
}
&-icon{
display: inline-block;
vertical-align: middle;
margin-right: 2px;
width: 16px;
height: 15px;
fill: $c-dark;
}
}
}
.wrapper{
min-height: 0;
}
.movies__list{
.movies__item:last-child{
display: none;
@include desktop-min{
display: block;
}
}
}
}
</style>

364
src/components/Movie.vue Normal file
View File

@@ -0,0 +1,364 @@
<template>
<section class="movie">
<div class="movie__container" v-if="loaded">
<header class="movie__header" :class="{'movie__header--page': type=='page'}" :style="{ 'background-image': 'url(' + movieBackdropSrc + ')' }">
<div class="movie__wrap movie__wrap--header" :class="{'movie__wrap--page': type=='page'}">
<figure class="movie__poster">
<img v-if="moviePosterSrc" class="movie__img" src="~assets/placeholder.png" v-img="moviePosterSrc">
<img v-if="!moviePosterSrc" class="movies-item__img is-loaded" src="~assets/no-image.png">
</figure>
<div class="movie__title">
<h1 class="movie__title-text">
{{ movie.title }}
<span v-if="movie.tagline">{{ movie.tagline }}</span>
</h1>
</div>
</div>
</header>
<div class="movie__main">
<div class="movie__wrap movie__wrap--main" :class="{'movie__wrap--page': type=='page'}">
<div class="movie__actions" v-if="userLoggedIn && favoriteChecked">
<a href="#" class="movie__actions-link" :class="{'active' : favorite === true}" @click.prevent="toggleFavorite">
<svg class="movie__actions-icon" :class="{'waiting' : favorite === ''}">
<use xlink:href="#iconFavorite"></use>
</svg>
<span class="movie__actions-text" v-if="favorite === ''">Wait...</span>
<span class="movie__actions-text" v-else-if="favorite">Marked as Favorite</span>
<span class="movie__actions-text" v-else>Mark as Favorite?</span>
</a>
</div>
<div class="movie__info">
<div v-if="movie.overview" class="movie__description">
{{ movie.overview }}
</div>
<div class="movie__details">
<div v-if="movie.genres.length" class="movie__details-block">
<h2 class="movie__details-title">
Genres
</h2>
<div class="movie__details-text">
{{ nestedDataToString(movie.genres) }}
</div>
</div>
<div v-if="movie.release_date" class="movie__details-block">
<h2 class="movie__details-title">
Release Date
</h2>
<div class="movie__details-text" v-formatDate="movie.release_date"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</template>
<script>
import axios from 'axios'
import storage from '../storage.js'
import img from '../directives/v-image.js'
import formatDate from '../directives/v-formatDate.js'
export default {
props: ['id', 'type'],
directives: {
img: img,
formatDate: formatDate
},
data(){
return{
movie: {},
movieLoaded: false,
moviePosterSrc: '',
movieBackdropSrc: '',
userLoggedIn: storage.sessionId ? true : false,
favoriteChecked: false,
favorite: ''
}
},
computed: {
loaded(){
return this.movieLoaded ? true : false;
}
},
methods: {
fetchMovie(id){
axios.get(`https://api.themoviedb.org/3/movie/${id}?api_key=${storage.apiKey}&language=en-US`)
.then(function(resp){
let movie = resp.data;
this.movie = movie;
this.poster();
this.backdrop();
this.movieLoaded = true;
if(this.userLoggedIn){
this.checkIfInFavorites(movie.id);
}
// Push state
if(storage.createMoviePopup){
storage.moviePath = '/movie/' + id;
history.pushState({ popup: true }, null, storage.moviePath);
storage.createMoviePopup = false;
}
// Change Page title
document.title = this.movie.title + storage.pageTitlePostfix;
}.bind(this))
.catch(function(error) {
console.log('error');
this.$router.push({ name: '404' });
}.bind(this));
},
poster() {
if(this.movie.poster_path){
this.moviePosterSrc = 'https://image.tmdb.org/t/p/w600_and_h900_bestv2' + this.movie.poster_path;
}
},
backdrop(){
if(this.movie.backdrop_path){
this.movieBackdropSrc = 'https://image.tmdb.org/t/p/w500' + this.movie.backdrop_path;
}
},
nestedDataToString(data) {
let nestedArray = [], resultString;
data.forEach((item) => nestedArray.push(item.name));
resultString = nestedArray.join(', ');
return resultString;
},
checkIfInFavorites(id){
axios.get(`https://api.themoviedb.org/3/movie/${id}/account_states?api_key=${storage.apiKey}&session_id=${storage.sessionId}`)
.then(function(resp){
this.favorite = resp.data.favorite;
this.favoriteChecked = true;
}.bind(this))
},
toggleFavorite(){
let favoriteInvert = !this.favorite;
this.favorite = '';
axios.post(`https://api.themoviedb.org/3/account/${storage.userId}/favorite?api_key=${storage.apiKey}&session_id=${storage.sessionId}`, {
'media_type': 'movie',
'media_id': this.id,
'favorite': favoriteInvert
})
.then(function(resp){
this.favorite = favoriteInvert;
eventHub.$emit('updateFavorite');
}.bind(this));
}
},
watch: {
id: function(val){
this.fetchMovie(val);
}
},
created(){
this.fetchMovie(this.id);
}
}
</script>
<style lang="scss">
@import "./src/scss/variables";
@import "./src/scss/media-queries";
.movie{
&__wrap{
display: flex;
&--page{
max-width: 768px;
position: relative;
margin: 0 auto;
}
&--header{
align-items: center;
height: 100%;
}
&--main{
display: flex;
flex-wrap: wrap;
flex-direction: column;
@include tablet-min{
flex-direction: row;
}
}
}
&__header{
height: 250px;
position: relative;
background-size: cover;
background-repeat: no-repeat;
background-position: 50% 50%;
background-color: $c-dark;
@include tablet-min{
height: 350px;
&--page{
height: 384px;
}
}
&:before{
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
z-index: 0;
width: 100%;
height: 100%;
background: rgba($c-dark, 0.85);
}
}
&__poster{
display: none;
@include tablet-min{
background: $c-dark;
display: block;
position: absolute;
width: calc(45% - 40px);
top: 40px;
left: 40px;
}
}
&__img{
display: block;
width: 100%;
opacity: 0;
transform: scale(0.97) translateZ(0);
transition: opacity 0.5s ease, transform 0.5s ease;
&.is-loaded{
opacity: 1;
transform: scale(1);
}
}
&__title{
position: relative;
padding: 20px;
color: $c-green;
text-align: center;
width: 100%;
@include tablet-min{
width: 55%;
text-align: left;
margin-left: 45%;
padding: 30px 30px 30px 40px;
}
&-text{
font-weight: 500;
line-height: 1.4;
font-size: 24px;
@include tablet-min{
font-size: 30px;
}
span{
display: block;
font-size: 14px;
font-weight: 300;
color: rgba($c-white, 0.7);
margin-top: 10px;
}
}
}
&__main{
background: $c-light;
min-height: calc(100vh - 250px);
@include tablet-min{
min-height: 0;
}
}
&__actions{
text-align: center;
width: 100%;
order: 2;
padding: 20px;
border-top: 1px solid rgba($c-dark, 0.05);
@include tablet-min{
order: 1;
width: 45%;
padding: 185px 0 40px 40px;
border-top: 0;
}
&-link{
display: flex;
align-items: center;
text-decoration: none;
text-transform: uppercase;
color: rgba($c-dark, 0.5);
transition: color 0.5s ease;
font-size: 11px;
padding: 10px 0;
border-bottom: 1px solid rgba($c-dark, 0.05);
&:hover{
color: rgba($c-dark, 0.75);
}
&.active{
color: $c-dark;
}
}
&-icon{
width: 16px;
height: 16px;
margin: 0 10px 0 0;
fill: rgba($c-dark, 0.5);
transition: fill 0.5s ease, transform 0.5s ease;
&.waiting{
transform: scale(0.8, 0.8);
}
}
&-link:hover &-icon{
fill: rgba($c-dark, 0.75);
}
&-link.active &-icon{
fill: $c-green;
}
&-text{
display: block;
padding-top: 2px;
}
}
&__info{
width: 100%;
padding: 20px;
order: 1;
@include tablet-min{
order: 2;
padding: 40px;
width: 55%;
margin-left: 45%;
}
}
&__actions + &__info{
margin-left: 0;
}
&__description{
font-weight: 300;
font-size: 13px;
line-height: 1.8;
margin-bottom: 20px;
@include tablet-min{
margin-bottom: 30px;
font-size: 14px;
}
}
&__details{
&-block:not(:last-child){
margin-bottom: 20px;
@include tablet-min{
margin-bottom: 30px;
}
}
&-title{
margin: 0;
font-weight: 400;
text-transform: uppercase;
font-size: 14px;
color: $c-green;
@include tablet-min{
font-size: 16px;
}
}
&-text{
font-weight: 300;
font-size: 14px;
margin-top: 5px;
}
}
}
</style>

View File

@@ -0,0 +1,12 @@
<template>
<div class="container info">
<movie :id="$route.params.id" :type="'page'"></movie>
</div>
</template>
<script>
import Movie from './Movie.vue';
export default {
components: { Movie }
}
</script>

View File

@@ -0,0 +1,86 @@
<template>
<div class="movie-popup" @click="$emit('close')">
<div class="movie-popup__box" @click.stop>
<movie :id="id"></movie>
<button class="movie-popup__close" @click="$emit('close')"></button>
</div>
<i class="loader"></i>
</div>
</template>
<script>
import Movie from './Movie.vue';
export default {
props: ['id'],
components: { Movie },
created(){
window.addEventListener('keyup', function(e){
if (e.keyCode == 27) {
this.$emit('close');
}
}.bind(this));
}
}
</script>
<style lang="scss">
@import "./src/scss/variables";
@import "./src/scss/media-queries";
.movie-popup{
position: fixed;
top: 0;
left: 0;
z-index: 20;
width: 100%;
height: 100vh;
background: rgba($c-dark, 0.98);
-webkit-overflow-scrolling: touch;
overflow: auto;
&__box{
width: 100%;
max-width: 768px;
position: relative;
z-index: 5;
background: $c-dark;
padding-bottom: 50px;
@include tablet-min{
padding-bottom: 0;
margin: 40px auto;
}
}
&__close{
display: block;
position: absolute;
top: 0;
right: 0;
border: 0;
background: transparent;
width: 40px;
height: 40px;
transition: background 0.5s ease;
cursor: pointer;
&:before,
&:after{
content: "";
display: block;
position: absolute;
top: 19px;
left: 10px;
width: 20px;
height: 2px;
background: $c-white;
}
&:before{
transform: rotate(45deg);
}
&:after{
transform: rotate(-45deg);
}
&:hover{
background: $c-green;
}
}
}
</style>

View File

@@ -0,0 +1,246 @@
<template>
<div class="wrapper" v-if="listLoaded">
<div class="movies" v-if="movies.length">
<header class="movies__header">
<h2 class="movies__title">{{ listTitle }}</h2>
<span class="movies__results" v-if="!shortList">{{ countResults }}</span>
<router-link v-if="shortList" class="movies__link" :to="{name: 'home-category', params: {category: category}}">
View All
</router-link>
</header>
<ul class="movies__list">
<movies-list-item class="movies__item" v-for="(movie, index) in movies" :movie="movie"></movies-list-item>
</ul>
<div class="movies__nav" v-if="!shortList" :class="{'is-hidden' : currentPage == pages}">
<button @click="loadMore" class="button">Load More</button>
</div>
</div>
<i v-if="!listLoaded" class="loader"></i>
<section v-if="!movies.length" class="not-found">
<div class="not-found__content">
<h2 class="not-found__title" v-if="mode == 'search'">Nothing Found</h2>
<h2 class="not-found__title" v-if="mode == 'favorite'">You haven't added any favorite movies</h2>
</div>
</section>
</div>
</template>
<script>
import axios from 'axios'
import numeral from 'numeral'
import storage from '../storage.js'
import MoviesListItem from './MoviesListItem.vue'
// Storage for removed favorite item
let removed;
export default {
props: ['type', 'mode', 'category', 'shortList'],
components: { MoviesListItem },
beforeRouteLeave (to, from, next) {
if(from.name == 'search'){
eventHub.$emit('setSearchQuery', true);
}
next();
},
data() {
return {
listTitle: '',
movies: [],
pages: '',
results: '',
currentPage: 1,
listLoaded: false
}
},
computed: {
pageTitle(){
return this.listTitle + storage.pageTitlePostfix;
},
query(){
return this.$route.params.query || '';
},
request(){
if(this.mode == 'search'){
return `https://api.themoviedb.org/3/search/movie?api_key=${storage.apiKey}&language=en-US&query=${this.query}&page=${this.currentPage}`;
} else if(this.mode == 'collection') {
let caregory = this.$route.params.category || this.category;
return `https://api.themoviedb.org/3/movie/${caregory}?api_key=${storage.apiKey}&language=en-US&page=${this.currentPage}`;
} else if(this.mode == 'favorite') {
return `https://api.themoviedb.org/3/account/${storage.userId}/favorite/movies?api_key=${storage.apiKey}&session_id=${storage.sessionId}&language=en-US&sort_by=created_at.desc&page=${this.currentPage}`;
}
},
countResults(){
if(this.results > 1){
return numeral(this.results).format('0,0') + ' results';
} else {
return numeral(this.results).format('0,0') + ' result';
}
}
},
methods: {
fetchCategory(){
axios.get(this.request)
.then(function(resp){
let data = resp.data;
if(this.shortList){
this.movies = data.results.slice(0, 5);
this.pages = 1;
this.results = 5;
} else {
this.movies = data.results;
this.pages = data.total_pages;
this.results = data.total_results;
}
this.listLoaded = true;
// Change Page title
if(this.type == 'page'){
document.title = this.pageTitle;
}
}.bind(this));
},
loadMore(){
this.currentPage++;
axios.get(this.request)
.then(function(resp){
let data = resp.data;
let newData = this.movies.concat(data.results);
this.movies = newData;
}.bind(this));
},
updateFavorite(){
if(this.mode == 'favorite'){
let promises = [], movies = [], pages, results;
for(let i = 1; i <= this.currentPage; i++){
promises.push(axios.get(`https://api.themoviedb.org/3/account/${storage.userId}/favorite/movies?api_key=${storage.apiKey}&session_id=${storage.sessionId}&language=en-US&sort_by=created_at.desc&page=${i}`))
}
axios.all(promises).then(function(results) {
results.forEach(function(resp) {
let data = resp.data;
movies = movies.concat(data.results);
pages = data.total_pages;
results = data.total_results;
});
this.movies = movies;
this.pages = pages;
if(this.currentPage > pages){
this.currentPage -= 1;
}
this.results = results;
}.bind(this));
}
}
},
watch: {
query(value){
this.fetchCategory(value);
}
},
created(){
// Set List Title
if(this.mode == 'search'){
this.listTitle = storage.categories['search'];
eventHub.$emit('setSearchQuery');
} else if(this.mode == 'collection') {
let caregory = this.$route.params.category || this.category;
this.listTitle = storage.categories[caregory];
} else if(this.mode == 'favorite') {
this.listTitle = storage.categories['favorite'];
}
this.fetchCategory();
eventHub.$on('updateFavorite', this.updateFavorite);
}
}
</script>
<style lang="scss">
@import "./src/scss/variables";
@import "./src/scss/media-queries";
.movies{
padding: 10px;
@include tablet-min{
padding: 15px;
}
@include tablet-landscape-min{
padding: 25px;
}
@include desktop-min{
padding: 30px;
}
&__header{
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 10px;
@include tablet-min{
padding: 23px 15px;
}
@include tablet-landscape-min{
padding: 16px 25px;
}
@include desktop-min{
padding: 8px 30px;
}
}
&__title{
margin: 0;
font-size: 16px;
line-height: 16px;
color: $c-dark;
font-weight: 300;
@include tablet-min{
font-size: 18px;
line-height: 18px;
}
}
&__results{
font-size: 12px;
font-weight: 300;
letter-spacing: 0.5px;
color: rgba($c-dark, 0.5);
}
&__link{
font-size: 12px;
font-weight: 300;
letter-spacing: 0.5px;
color: rgba($c-dark, 0.5);
text-decoration: none;
transition: color 0.5s ease;
&:after{
content: " →";
}
&:hover{
color: $c-dark;
}
}
&__list{
padding: 0;
margin: 0;
list-style: none;
display: flex;
flex-wrap: wrap;
}
&__item{
padding: 10px;
width: 50%;
@include tablet-min{
padding: 15px;
}
@include tablet-landscape-min{
padding: 20px;
width: 25%;
}
@include desktop-min{
padding: 30px;
width: 20%;
}
}
&__nav{
padding: 25px 0;
text-align: center;
&.is-hidden{
display: none;
}
}
}
</style>

View File

@@ -0,0 +1,90 @@
<template>
<li class="movies-item">
<a class="movies-item__link" :class="{'no-image': noImage}" :href="'/movie/' + movie.id" @click.prevent="openMoviePopup(movie.id, true)">
<figure class="movies-item__poster">
<img v-if="!noImage" class="movies-item__img" src="~assets/placeholder.png" v-img="poster()" alt="">
<img v-if="noImage" class="movies-item__img is-loaded" src="~assets/no-image.png" alt="">
</figure>
<div class="movies-item__content">
<p class="movies-item__title">{{ movie.title }}</p>
</div>
</a>
</li>
</template>
<script>
import img from '../directives/v-image.js'
export default {
props: ['movie'],
directives: {
img: img
},
data(){
return{
noImage: false
}
},
methods: {
poster() {
if(this.movie.poster_path){
return 'https://image.tmdb.org/t/p/w370_and_h556_bestv1' + this.movie.poster_path;
} else {
this.noImage = true;
}
},
openMoviePopup(id, event){
eventHub.$emit('openMoviePopup', id, event);
}
}
}
</script>
<style lang="scss">
@import "./src/scss/variables";
@import "./src/scss/media-queries";
.movies-item{
&__link{
text-decoration: none;
color: rgba($c-dark, 0.5);
font-weight: 300;
}
&__content{
padding-top: 15px;
}
&__poster{
transition: transform 0.5s ease, box-shadow 0.5s ease;
transform: translateZ(0);
background: $c-white;
}
&__img{
width: 100%;
opacity: 0;
transform: scale(0.97) translateZ(0);
transition: opacity 0.5s ease, transform 0.5s ease;
&.is-loaded{
opacity: 1;
transform: scale(1);
}
}
&__link:not(.no-image):hover &__poster{
transform: scale(1.03);
box-shadow: 0 0 10px rgba($c-dark, 0.1);
}
&__title{
margin: 0;
font-size: 11px;
letter-spacing: 0.5px;
transition: color 0.5s ease;
@include mobile-ls-min{
font-size: 12px;
}
@include tablet-min{
font-size: 14px;
}
}
&__link:hover &__title{
color: $c-dark;
}
}
</style>

View File

@@ -0,0 +1,208 @@
<template>
<nav class="nav">
<router-link class="nav__logo" :to="{name: 'home'}" exact title="Vue.js — TMDb App">
<svg class="nav__logo-image">
<use xlink:href="#svgLogo"></use>
</svg>
</router-link>
<ul class="nav__list">
<li class="nav__item" v-for="item in listTypes" v-if="item.isCategory">
<router-link class="nav__link" :to="{name: 'home-category', params: {category: item.query}}">
<div class="nav__link-wrap">
<svg class="nav__link-icon">
<use :xlink:href="'#icon_' + item.query"></use>
</svg>
<span class="nav__link-title">{{ item.shortTitle }}</span>
</div>
</router-link>
</li>
<li class="nav__item nav__item--profile">
<div class="nav__link nav__link--profile" @click="requestToken" v-if="!userLoggedIn">
<div class="nav__link-wrap">
<svg class="nav__link-icon">
<use xlink:href="#iconLogin"></use>
</svg>
<span class="nav__link-title">Log In</span>
</div>
</div>
<router-link class="nav__link nav__link--profile" :to="{name: 'profile'}" v-if="userLoggedIn">
<div class="nav__link-wrap">
<svg class="nav__link-icon">
<use xlink:href="#iconLogin"></use>
</svg>
<span class="nav__link-title">Profile</span>
</div>
</router-link>
</li>
</ul>
</nav>
</template>
<script>
import storage from '../storage.js'
export default {
data(){
return {
listTypes: storage.listTypes,
userLoggedIn: storage.sessionId ? true : false
}
},
methods: {
setUserStatus(){
this.userLoggedIn = storage.sessionId ? true : false;
},
requestToken(){
eventHub.$emit('requestToken');
}
},
created(){
eventHub.$on('setUserStatus', this.setUserStatus);
}
}
</script>
<style lang="scss">
@import "./src/scss/variables";
@import "./src/scss/media-queries";
.nav{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 50px;
background: $c-white;
display: flex;
z-index: 10;
@include tablet-min{
display: block;
width: 95px;
height: 100vh;
}
&__logo{
display: block;
width: 55px;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
background: $c-dark;
@include tablet-min{
width: 95px;
height: 75px;
}
&-image{
width: 35px;
height: 31px;
fill: $c-green;
transition: transform 0.5s ease;
@include tablet-min{
width: 45px;
height: 40px;
}
}
&:hover &-image{
transform: scale(1.04);
}
}
&__list{
list-style: none;
padding: 0;
margin: 0;
text-align: center;
width: 100%;
display: flex;
position: fixed;
left: 0;
top: 50px;
background: $c-white;
border-top: 1px solid $c-light;
@include tablet-min{
background: transparent;
position: relative;
display: block;
width: 100%;
border-top: 0;
top: 0;
}
}
&__item{
width: 20%;
&:not(:first-child){
border-left: 1px solid $c-light;
}
@include tablet-min{
width: 100%;
border-left: 0;
border-bottom: 1px solid $c-light;
&--profile{
position: fixed;
right: 0;
top: 0;
width: 75px;
height: 75px;
border-bottom: 0;
}
}
}
&__link{
width: 100%;
height: 50px;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
font-size: 7px;
font-weight: 300;
text-decoration: none;
text-transform: uppercase;
letter-spacing: 0.5px;
color: rgba($c-dark, 0.7);
transition: color 0.5s ease, background 0.5s ease;
position: relative;
cursor: pointer;
@include mobile-ls-min{
font-size: 8px;
}
@include tablet-min{
width: 95px;
height: 95px;
font-size: 9px;
&--profile{
width: 75px;
height: 75px;
background: $c-white;
}
}
&-icon{
width: 15px;
height: 15px;
margin-bottom: 3px;
fill: rgba($c-dark, 0.7);
transition: fill 0.5s ease;
@include tablet-min{
width: 20px;
height: 20px;
margin-bottom: 5px;
}
}
&-title{
display: block;
width: 100%;
}
&:hover{
color: $c-dark;
}
&:hover &-icon{
fill: $c-dark;
}
&.is-active{
color: $c-dark;
background: $c-light;
}
&.is-active &-icon{
fill: $c-dark;
}
}
}
</style>

136
src/components/Profile.vue Normal file
View File

@@ -0,0 +1,136 @@
<template>
<section class="profile">
<div class="profile__content" v-if="userLoggedIn === true">
<header class="profile__header">
<h2 class="profile__title">Hello {{ userName }}</h2>
<button class="button" @click="logOut">Log Out</button>
</header>
<movies-list :type="'component'" :mode="'favorite'"></movies-list>
<!-- <created-lists></created-lists> -->
</div>
<section class="not-found" v-if="userLoggedIn === false">
<div class="not-found__content">
<h2 class="not-found__title">Authentication Request Failed</h2>
<button class="not-found__button button" @click="requestToken">Log In</button>
</div>
</section>
</section>
</template>
<script>
import axios from 'axios'
import storage from '../storage.js'
import MoviesList from './MoviesList.vue'
// import CreatedLists from './CreatedLists.vue'
export default {
components: { MoviesList },
data(){
return{
userLoggedIn: '',
userName: ''
}
},
methods: {
requestPermission(){
let query = location.search.substring(1);
if(query.length){
let params = query.split('&');
let token = params[0].split('=')[1];
let status = params[1].split('=')[0];
if(status == 'approved'){
this.createSession(token);
} else {
this.userLoggedIn = false;
}
} else {
this.userLoggedIn = false;
}
},
createSession(token){
axios.get(`https://api.themoviedb.org/3/authentication/session/new?api_key=${storage.apiKey}&request_token=${token}`)
.then(function(resp){
let data = resp.data;
if(data.success){
let id = data.session_id;
localStorage.setItem('session_id', id);
eventHub.$emit('setUserStatus');
this.userLoggedIn = true;
this.getUserInfo();
}
}.bind(this));
},
getUserInfo(){
axios.get(`https://api.themoviedb.org/3/account?api_key=${storage.apiKey}&session_id=${storage.sessionId}`)
.then(function(resp){
let data = resp.data;
this.userName = data.username;
if (!localStorage.getItem('user_id')) localStorage.setItem('user_id', data.id);
}.bind(this))
.catch(function (error) {
this.logOut();
}.bind(this));
},
requestToken(){
eventHub.$emit('requestToken');
},
logOut(){
localStorage.clear();
eventHub.$emit('setUserStatus');
this.$router.push({ name: 'home' });
}
},
created(){
document.title = 'Profile' + storage.pageTitlePostfix;
storage.backTitle = document.title;
if(!storage.sessionId){
this.requestPermission();
} else {
this.userLoggedIn = true;
this.getUserInfo();
}
}
}
</script>
<style lang="scss">
@import "./src/scss/variables";
@import "./src/scss/media-queries";
.profile{
&__content{
.wrapper{
min-height: calc(100vh - 175px);
@include tablet-min{
min-height: calc(100vh - 171px);
}
}
}
&__header{
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px;
border-bottom: 1px solid rgba($c-dark, 0.05);
@include tablet-min{
padding: 29px 30px;
}
@include tablet-landscape-min{
padding: 29px 50px;
}
@include desktop-min{
padding: 29px 60px;
}
}
&__title{
margin: 0;
font-size: 16px;
line-height: 16px;
color: $c-dark;
font-weight: 300;
@include tablet-min{
font-size: 18px;
line-height: 18px;
}
}
}
</style>