Skip to content

Commit

Permalink
Filter by items in watch list in people view
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPerathoner committed Nov 5, 2024
1 parent 27218e8 commit 1585ed1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/routes/(app)/person/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import type { TMDBPersonCombinedCredits, TMDBPersonDetails } from "@/types";
import axios from "axios";
import { onMount } from "svelte";
import Checkbox from "@/lib/Checkbox.svelte";
export let data;
Expand All @@ -20,7 +21,9 @@
let person: TMDBPersonDetails | undefined;
let pageError: Error | undefined;
let sortOption = "Vote count";
let cachedCredits: TMDBPersonCombinedCredits | undefined;
let credits: TMDBPersonCombinedCredits | undefined;
let onMyListFilter = false;
onMount(() => {
const unsubscribe = page.subscribe((value) => {
Expand All @@ -37,6 +40,10 @@
fetchPersonData();
}
$: if (onMyListFilter !== undefined && credits) {
filterCredits(onMyListFilter);
}
$: if (sortOption && credits) {
sortCredits(sortOption);
}
Expand Down Expand Up @@ -65,6 +72,18 @@
credits = (await axios.get(`/content/person/${data.personId}/credits`))
.data as TMDBPersonCombinedCredits;
credits.cast = credits.cast.filter((v, i, a) => a.findIndex((t) => t.id === v.id) === i); // remove duplicate entries. If an actor has multiple roles in a single movie, it would otherwise show up multiple times
cachedCredits = JSON.parse(JSON.stringify(credits));
}
function filterCredits(onMyListFilter: boolean) {
if (!credits || !credits.cast || !cachedCredits) return;
if (!onMyListFilter) {
credits.cast = [...cachedCredits.cast];
} else {
credits.cast = [...cachedCredits.cast].filter((c) =>
wList.some((w) => w.content?.tmdbId === c.id)
);
}
}
function sortCredits(sortOption: string) {
Expand Down Expand Up @@ -170,6 +189,10 @@
</div>
</div>
<div class="filters">
<div class="listFilter">
<span>On my list</span>
<Checkbox name="On my list" bind:value={onMyListFilter} />
</div>
<DropDown
bind:active={sortOption}
placeholder="Vote count"
Expand Down Expand Up @@ -206,6 +229,16 @@
padding-left: 20px;
padding-right: 20px;
width: 100%;
.listFilter {
display: flex;
margin-right: 30px;
span {
margin-left: 5px;
margin-right: 5px;
margin-top: auto;
margin-bottom: auto;
}
}
/* Same as in PosterList */
max-width: 1200px;
}
Expand Down

0 comments on commit 1585ed1

Please sign in to comment.