Skip to content

Commit

Permalink
fix(watchlist): discover local watchlist item display and profile loc…
Browse files Browse the repository at this point in the history
…al watchlist slider visibility

Previously when you expand the `Your Watchlist` slider from the discover page to see all your
watchlist items, you only see the first 20 items. This commit fixes that so you can see all your
local watchlist items when you expand that slider. In addition, this commit also fixes the visiblity
of profile watchlist slider for local watchlists
  • Loading branch information
fallenbagel committed Nov 7, 2023
1 parent f922318 commit 3cb9494
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 63 deletions.
3 changes: 1 addition & 2 deletions server/routes/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ discoverRoutes.get<Record<string, unknown>, WatchlistResponse>(
if (total) {
return res.json({
page: page,
totalPages: total / itemsPerPage,
totalPages: Math.ceil(total / itemsPerPage),
totalResults: total,
results: result,
});
Expand All @@ -865,7 +865,6 @@ discoverRoutes.get<Record<string, unknown>, WatchlistResponse>(
}

const plexTV = new PlexTvAPI(activeUser.plexToken);

const watchlist = await plexTV.getWatchlist({ offset });

return res.json({
Expand Down
38 changes: 20 additions & 18 deletions server/routes/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,29 +717,31 @@ router.get<{ id: string }, WatchlistResponse>(

const user = await getRepository(User).findOneOrFail({
where: { id: Number(req.params.id) },
select: { id: true, plexToken: true },
select: ['id', 'plexToken'],
});

if (!user?.plexToken) {
if (user) {
const [result, total] = await getRepository(Watchlist).findAndCount({
where: { requestedBy: { id: user?.id } },
relations: { requestedBy: true },
// loadRelationIds: true,
take: itemsPerPage,
skip: offset,
if (user) {
const [result, total] = await getRepository(Watchlist).findAndCount({
where: { requestedBy: { id: user?.id } },
relations: {
/*requestedBy: true,media:true*/
},
// loadRelationIds: true,
take: itemsPerPage,
skip: offset,
});
if (total) {
return res.json({
page: page,
totalPages: Math.ceil(total / itemsPerPage),
totalResults: total,
results: result,
});
if (total) {
return res.json({
page: page,
totalPages: total / itemsPerPage,
totalResults: total,
results: result,
});
}
}
}

// We will just return an empty array if the user has no Plex token
// We will just return an empty array if the user has no Plex token
if (!user.plexToken) {
return res.json({
page: 1,
totalPages: 1,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Discover/DiscoverWatchlist/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const DiscoverWatchlist = () => {
</Header>
</div>
<ListView
plexItems={titles}
plexItems={titles.filter((title) => title != null)}
isEmpty={isEmpty}
isLoading={
isLoadingInitialData || (isLoadingMore && (titles?.length ?? 0) > 0)
Expand Down
41 changes: 24 additions & 17 deletions src/components/UserProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const messages = defineMessages({
seriesrequest: 'Series Requests',
recentlywatched: 'Recently Watched',
plexwatchlist: 'Plex Watchlist',
localWatchlist: "{username}'s Watchlist",
emptywatchlist:
'Media added to your <PlexWatchlistSupportLink>Plex Watchlist</PlexWatchlistSupportLink> will appear here.',
});
Expand Down Expand Up @@ -78,17 +79,17 @@ const UserProfile = () => {
? `/api/v1/user/${user.id}/watch_data`
: null
);

const { data: watchlistItems, error: watchlistError } =
useSWR<WatchlistResponse>(
user?.userType === UserType.PLEX &&
(user.id === currentUser?.id ||
currentHasPermission(
[Permission.MANAGE_REQUESTS, Permission.WATCHLIST_VIEW],
{
type: 'or',
}
))
? `/api/v1/user/${user.id}/watchlist`
user?.id === currentUser?.id ||
currentHasPermission(
[Permission.MANAGE_REQUESTS, Permission.WATCHLIST_VIEW],
{
type: 'or',
}
)
? `/api/v1/user/${user?.id}/watchlist`
: null,
{
revalidateOnMount: true,
Expand Down Expand Up @@ -117,6 +118,13 @@ const UserProfile = () => {
return <Error statusCode={404} />;
}

const watchlistSliderTitle = intl.formatMessage(
user.userType === UserType.PLEX
? messages.plexwatchlist
: messages.localWatchlist,
{ username: user.displayName }
);

return (
<>
<PageTitle title={user.displayName} />
Expand Down Expand Up @@ -309,12 +317,11 @@ const UserProfile = () => {
/>
</>
)}
{user.userType === UserType.PLEX &&
(user.id === currentUser?.id ||
currentHasPermission(
[Permission.MANAGE_REQUESTS, Permission.WATCHLIST_VIEW],
{ type: 'or' }
)) &&
{(user.id === currentUser?.id ||
currentHasPermission(
[Permission.MANAGE_REQUESTS, Permission.WATCHLIST_VIEW],
{ type: 'or' }
)) &&
(!watchlistItems ||
!!watchlistItems.results.length ||
(user.id === currentUser?.id &&
Expand All @@ -327,11 +334,11 @@ const UserProfile = () => {
href={
user.id === currentUser?.id
? '/profile/watchlist'
: `/users/${user?.id}/watchlist`
: `/users/${user.id}/watchlist`
}
>
<a className="slider-title">
<span>{intl.formatMessage(messages.plexwatchlist)}</span>
<span>{watchlistSliderTitle}</span>
<ArrowRightCircleIcon />
</a>
</Link>
Expand Down
Loading

0 comments on commit 3cb9494

Please sign in to comment.