Skip to content

Commit

Permalink
feat(/user): add dropdown for narrowing results
Browse files Browse the repository at this point in the history
  • Loading branch information
Jabster28 committed Jul 12, 2020
1 parent e1c3f33 commit a821d03
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/pages/User.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@
<h2>{{ user.username }}</h2>

<h6 class="disabled">{{ user.user_id }}</h6>
<!-- <p class="text-justify">{{ anime.synopsis }}</p>
<h5>
<q-icon name="stars" /> {{ anime.score.toPrecision(3) }} / 10
</h5>
<h5><q-icon name="visibility" /> {{ norm(anime.members) }}</h5>
<h5><q-icon name="star" /> {{ norm(anime.favorites) }}</h5>
<h5 v-if="anime.rank"># {{ norm(anime.rank) }}</h5> -->
<q-select
v-model="filter"
:options="options"
label="Show"
class="q-my-md"
/>
</div>
<div class="col-10">
<q-table
Expand Down Expand Up @@ -83,6 +82,8 @@ export default Vue.extend({
name: 'PageUser',
data() {
return {
options: 'All Completed OnHold Watching Dropped PlanToWatch'.split(' '),
filter: 'All',
initialPagination: {
sortBy: 'watching_status',
descending: false,
Expand Down Expand Up @@ -156,7 +157,11 @@ export default Vue.extend({
},
watch: {
// call again the method if the route changes
$route: 'fetchData'
$route: 'fetchData',
filter() {
this.tableLoading = true;
this.again();
}
},
methods: {
// @ts-ignore
Expand All @@ -176,18 +181,21 @@ export default Vue.extend({
/* @ts-ignore */
cache.animelist &&
/* @ts-ignore */
cache.animelist[this.user.username.toLowerCase()]
cache.animelist[this.user.username.toLowerCase() + '/' + this.filter]
) {
/* @ts-ignore */
this.cached = true;
/* @ts-ignore */
this.animelist = cache.animelist[this.user.username.toLowerCase()];
this.animelist =
/* @ts-ignore */
cache.animelist[this.user.username.toLowerCase() + '/' + this.filter];
}
axios
.get(
`https://api.jikan.moe/v3/user/${this.$route.params.id}/animelist?page=${this.pageNum}`
`https://api.jikan.moe/v3/user/${this.$route.params.id}/animelist/${this.filter}?page=${this.pageNum}`
)
.then(data => {
if (this.pageNum == 1 && !this.cached) this.animelist = [];
if (data.data.anime && data.data.anime.length != 0) {
this.pageNum++;
// @ts-ignore
Expand All @@ -202,10 +210,12 @@ export default Vue.extend({
const x = this.again;
setTimeout(x, 2000);
} else {
this.pageNum = 1;
this.tableLoading = false;
if (this.cached) {
this.animelist = this.cachedAnimeList;
}
this.cached = false;
/* @ts-ignore */
let cache = this.$q.localStorage.getItem('cache');
/* @ts-ignore */
Expand All @@ -216,10 +226,15 @@ export default Vue.extend({
/* @ts-ignore */
if (!cache.animelist) cache.animelist = {};
/* @ts-ignore */
cache.animelist[this.user.username.toLowerCase()] = this.animelist;
cache.animelist[
this.user.username.toLowerCase() + '/' + this.filter
] = this.animelist;
/* @ts-ignore */
cache.animelist[this.user.username.toLowerCase()].date = new Date();
cache.animelist[
this.user.username.toLowerCase() + '/' + this.filter
].date = new Date();
this.$q.localStorage.set('cache', cache);
this.cachedAnimeList = [];
}
})
.catch(e => console.log(e));
Expand Down

1 comment on commit a821d03

@vercel
Copy link

@vercel vercel bot commented on a821d03 Jul 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.