Simplified home, now send apiFunction to child to make the requests
This commit is contained in:
@@ -2,86 +2,46 @@
|
|||||||
<section>
|
<section>
|
||||||
<LandingBanner />
|
<LandingBanner />
|
||||||
|
|
||||||
<div v-for="list in lists">
|
<div v-for="list in lists" :key="list.name">
|
||||||
<list-header :title="list.title" :link="list.route" />
|
<ResultsSection
|
||||||
|
:apiFunction="list.apiFunction"
|
||||||
<results-list :results="list.data" :shortList="true" />
|
:title="list.title"
|
||||||
<loader v-if="!list.data.length" />
|
:shortList="true"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import LandingBanner from "@/components/LandingBanner";
|
import LandingBanner from "@/components/LandingBanner";
|
||||||
import ListHeader from "@/components/ListHeader";
|
import ResultsSection from "@/components/ResultsSection";
|
||||||
import ResultsList from "@/components/ResultsList";
|
import { getRequests, getTmdbMovieListByName } from "@/api";
|
||||||
import Loader from "@/components/ui/Loader";
|
|
||||||
|
|
||||||
import { getTmdbMovieListByName, getRequests } from "@/api";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "home",
|
name: "home",
|
||||||
components: { LandingBanner, ResultsList, ListHeader, Loader },
|
components: { LandingBanner, ResultsSection },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
imageFile: "/pulp-fiction.jpg",
|
imageFile: "/pulp-fiction.jpg",
|
||||||
requests: [],
|
lists: [
|
||||||
nowplaying: [],
|
|
||||||
upcoming: [],
|
|
||||||
popular: []
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
lists() {
|
|
||||||
return [
|
|
||||||
{
|
{
|
||||||
title: "Requests",
|
title: "Requests",
|
||||||
route: "/requests",
|
apiFunction: getRequests
|
||||||
data: this.requests
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Now playing",
|
title: "Now playing",
|
||||||
route: "/list/now_playing",
|
apiFunction: () => getTmdbMovieListByName("now_playing")
|
||||||
data: this.nowplaying
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Upcoming",
|
title: "Upcoming",
|
||||||
route: "/list/upcoming",
|
apiFunction: () => getTmdbMovieListByName("upcoming")
|
||||||
data: this.upcoming
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Popular",
|
title: "Popular",
|
||||||
route: "/list/popular",
|
apiFunction: () => getTmdbMovieListByName("popular")
|
||||||
data: this.popular
|
|
||||||
}
|
}
|
||||||
];
|
]
|
||||||
}
|
};
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
fetchRequests() {
|
|
||||||
getRequests().then(results => (this.requests = results.results));
|
|
||||||
},
|
|
||||||
fetchNowPlaying() {
|
|
||||||
getTmdbMovieListByName("now_playing").then(
|
|
||||||
results => (this.nowplaying = results.results)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
fetchUpcoming() {
|
|
||||||
getTmdbMovieListByName("upcoming").then(
|
|
||||||
results => (this.upcoming = results.results)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
fetchPopular() {
|
|
||||||
getTmdbMovieListByName("popular").then(
|
|
||||||
results => (this.popular = results.results)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
this.fetchRequests();
|
|
||||||
this.fetchNowPlaying();
|
|
||||||
this.fetchUpcoming();
|
|
||||||
this.fetchPopular();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<list-header :title="prettify(title)" :info="info" :sticky="true" />
|
<list-header v-bind="{ title, info, shortList }" :sticky="true" />
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="!loadedPages.includes(1) && loading == false"
|
v-if="!loadedPages.includes(1) && loading == false"
|
||||||
@@ -11,11 +11,10 @@
|
|||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<results-list :results="results" v-if="results" />
|
<results-list v-bind="{ results, shortList }" />
|
||||||
|
<loader v-if="loading" />
|
||||||
|
|
||||||
<loader v-if="!results.length" />
|
<div v-if="!shortList && page < totalPages" class="load-button">
|
||||||
|
|
||||||
<div v-if="page < totalPages" class="load-button">
|
|
||||||
<seasoned-button @click="loadMore" :fullWidth="true"
|
<seasoned-button @click="loadMore" :fullWidth="true"
|
||||||
>load more</seasoned-button
|
>load more</seasoned-button
|
||||||
>
|
>
|
||||||
@@ -27,8 +26,9 @@
|
|||||||
import ListHeader from "@/components/ListHeader";
|
import ListHeader from "@/components/ListHeader";
|
||||||
import ResultsList from "@/components/ResultsList";
|
import ResultsList from "@/components/ResultsList";
|
||||||
import SeasonedButton from "@/components/ui/SeasonedButton";
|
import SeasonedButton from "@/components/ui/SeasonedButton";
|
||||||
import Loader from "@/components/ui/Loader";
|
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
|
import { getTmdbMovieListByName } from "@/api";
|
||||||
|
import Loader from "@/components/ui/Loader";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
@@ -39,6 +39,11 @@ export default {
|
|||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
shortList: {
|
||||||
|
type: Boolean,
|
||||||
|
required: false,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: { ListHeader, ResultsList, SeasonedButton, Loader },
|
components: { ListHeader, ResultsList, SeasonedButton, Loader },
|
||||||
@@ -73,7 +78,7 @@ export default {
|
|||||||
loadMore() {
|
loadMore() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
let maxPage = [...this.loadedPages].slice(-1)[0];
|
let maxPage = [...this.loadedPages].slice(-1)[0];
|
||||||
console.log("maxPage:", maxPage);
|
|
||||||
if (maxPage == NaN) return;
|
if (maxPage == NaN) return;
|
||||||
this.page = maxPage + 1;
|
this.page = maxPage + 1;
|
||||||
this.getListResults();
|
this.getListResults();
|
||||||
@@ -104,14 +109,13 @@ export default {
|
|||||||
}`
|
}`
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getPageFromQueryParams() {
|
getPageFromUrl() {
|
||||||
return new URLSearchParams(window.location.search).get("page");
|
return new URLSearchParams(window.location.search).get("page");
|
||||||
},
|
},
|
||||||
getListResults(front = false) {
|
getListResults(front = false) {
|
||||||
this.apiFunction(this.page)
|
this.apiFunction(this.page)
|
||||||
.then(results => {
|
.then(results => {
|
||||||
if (front) this.results = results.results.concat(...this.results);
|
this.results = this.results.concat(...results.results);
|
||||||
else this.results = this.results.concat(...results.results);
|
|
||||||
this.page = results.page;
|
this.page = results.page;
|
||||||
this.loadedPages.push(this.page);
|
this.loadedPages.push(this.page);
|
||||||
this.loadedPages = this.loadedPages.sort();
|
this.loadedPages = this.loadedPages.sort();
|
||||||
@@ -123,7 +127,9 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.page = this.getPageFromQueryParams() || this.page;
|
this.page = this.getPageFromUrl() || this.page;
|
||||||
|
// this.listName = this.getListNameFromUrl();
|
||||||
|
|
||||||
if (this.results.length === 0) this.getListResults();
|
if (this.results.length === 0) this.getListResults();
|
||||||
|
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
|
|||||||
Reference in New Issue
Block a user