2016-10-10 10:57:39 +02:00
|
|
|
<template>
|
|
|
|
<main>
|
|
|
|
<div class="wrap-content" v-if=" ! loading">
|
2016-10-18 09:57:47 +02:00
|
|
|
<Item v-for="(item, index) in floxItems"
|
|
|
|
:item="item"
|
|
|
|
:key="index"
|
|
|
|
:genre="true"
|
|
|
|
:date="true"
|
|
|
|
></Item>
|
|
|
|
<Item v-for="(item, index) in tmdbItems"
|
|
|
|
:item="item"
|
|
|
|
:key="index"
|
|
|
|
:genre="true"
|
|
|
|
:date="true"
|
|
|
|
></Item>
|
2016-10-10 10:57:39 +02:00
|
|
|
|
|
|
|
<span class="nothing-found" v-if=" ! floxItems.length && ! tmdbItems.length">Nothing Found</span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<span class="loader fullsize-loader" v-if="loading"><i></i></span>
|
|
|
|
</main>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Item from './Item.vue';
|
|
|
|
import Helper from '../../helper';
|
|
|
|
|
2016-10-13 11:11:10 +02:00
|
|
|
import { mapState, mapMutations } from 'vuex'
|
2016-10-10 10:57:39 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
mixins: [Helper],
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.initSearch();
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
floxItems: [],
|
|
|
|
tmdbItems: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
searchTitle: state => state.searchTitle,
|
|
|
|
loading: state => state.loading
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2016-10-13 11:11:10 +02:00
|
|
|
...mapMutations([ 'SET_SEARCH_TITLE', 'SET_LOADING' ]),
|
|
|
|
|
2016-10-10 10:57:39 +02:00
|
|
|
initSearch() {
|
2016-10-13 11:11:10 +02:00
|
|
|
this.SET_SEARCH_TITLE(this.$route.query.q);
|
|
|
|
this.SET_LOADING(true);
|
2016-10-10 10:57:39 +02:00
|
|
|
this.searchFlox();
|
|
|
|
this.searchTMDB().then(() => {
|
|
|
|
setTimeout(() => {
|
2016-10-13 11:11:10 +02:00
|
|
|
this.SET_LOADING(false);
|
2016-10-10 10:57:39 +02:00
|
|
|
}, 500);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
searchFlox() {
|
|
|
|
this.$http.get(`${config.api}/search-items?q=${this.searchTitle}`).then(value => {
|
|
|
|
this.floxItems = value.data;
|
2016-10-13 11:11:10 +02:00
|
|
|
}, error => {
|
|
|
|
console.log(error);
|
2016-10-10 10:57:39 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
async searchTMDB() {
|
|
|
|
if(config.auth) {
|
|
|
|
await this.$http.get(`${config.api}/search-tmdb?q=${this.searchTitle}`).then(value => {
|
|
|
|
const floxItems = this.floxItems.map(item => item.tmdb_id);
|
|
|
|
this.tmdbItems = value.data.filter(item => ! floxItems.includes(item.tmdb_id));
|
|
|
|
}).catch(error => {
|
|
|
|
alert('Error in searchTMDB(): ' + error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
|
|
|
Item
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
$route() {
|
|
|
|
this.scrollToTop();
|
|
|
|
this.initSearch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|