Skip to content

Commit

Permalink
Various fixes for issues that have popped up (#733)
Browse files Browse the repository at this point in the history
* fix: remove Plex photo libraries from selector

* fix: add key for Jellyfin list items

* fix: protect against undefined items in programming selector state

Related to #721 but I can't get a solid repro
  • Loading branch information
chrisbenincasa authored Aug 29, 2024
1 parent 60bf786 commit f799b44
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions types/src/plex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const PlexMediaTypeSchema = z.union([
z.literal('movie'),
z.literal('show'),
z.literal('artist'),
z.literal('photo'),
]);

export const PlexLibrarySectionSchema = z.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export function JellyfinProgrammingSelector() {
getItemKey={useCallback((item: JellyfinItem) => item.Id, [])}
renderGridItem={renderGridItem}
renderListItem={(item, index) => (
<JellyfinListItem item={item} index={index} />
<JellyfinListItem key={item.Id} item={item} index={index} />
)}
// renderFinalRow={renderFinalRowInlineModal}
infiniteQuery={jellyfinItemsQuery}
Expand Down
20 changes: 17 additions & 3 deletions web/src/hooks/plex/usePlex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useApiQuery } from '../useApiQuery.ts';
import { useTunarrApi } from '../useTunarrApi.ts';
import { plexQueryOptions } from './plexHookUtil.ts';
import { MediaSourceId } from '@tunarr/types/schemas';
import { identity, reject } from 'lodash-es';

export type PlexPathMappings = [
['/library/sections', PlexLibrarySections],
Expand All @@ -23,16 +24,20 @@ type PlexQueryArgs<T> = {

export const usePlex = <
T extends ExtractTypeKeys<PlexPathMappings>,
OutType = FindChild<T, PlexPathMappings>,
ResponseType = FindChild<T, PlexPathMappings>,
OutType = ResponseType,
>(
serverId: MediaSourceId,
path: string,
enabled: boolean = true,
select: (response: ResponseType) => OutType = identity,
) => {
return useApiQuery({
queryKey: ['plex', serverId, path],
queryFn: (apiClient) => fetchPlexPath<OutType>(apiClient, serverId, path)(),
queryFn: (apiClient) =>
fetchPlexPath<ResponseType>(apiClient, serverId, path)(),
enabled,
select,
});
};
export const usePlexTyped = <T>(
Expand Down Expand Up @@ -74,4 +79,13 @@ export const usePlexTyped2 = <T = unknown, U = unknown>(
export const usePlexLibraries = (
serverId: MediaSourceId,
enabled: boolean = true,
) => usePlex<'/library/sections'>(serverId, '/library/sections', enabled);
) =>
usePlex<'/library/sections'>(
serverId,
'/library/sections',
enabled,
(response) => ({
...response,
Directory: reject(response.Directory, { type: 'photo' }),
}),
);
11 changes: 10 additions & 1 deletion web/src/store/programmingSelector/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
isPlexDirectory,
} from '@tunarr/types/plex';
import { MediaSourceId } from '@tunarr/types/schemas';
import { has, isArray, map, reject, some, uniq } from 'lodash-es';
import { has, isArray, isUndefined, map, reject, some, uniq } from 'lodash-es';
import useStore from '..';
import {
buildPlexFilterKey,
Expand All @@ -27,13 +27,19 @@ export const setProgrammingListingServer = (
) =>
useStore.setState((state) => {
state.currentServer = server;
state.currentLibrary = undefined;
});

export const setProgrammingListLibrary = (library: SelectedLibrary) =>
useStore.setState((state) => {
state.currentLibrary = library;
});

export const clearProgrammingListLibrary = () =>
useStore.setState((state) => {
state.currentLibrary = undefined;
});

function uniqueId(item: PlexLibrarySection | PlexMedia): string {
if (isPlexDirectory(item)) {
return item.uuid;
Expand Down Expand Up @@ -63,6 +69,9 @@ export const addKnownMediaForServer = (
switch (media.type) {
case 'plex': {
for (const item of media.items) {
if (isUndefined(item)) {
continue;
}
byGuid[uniqueId(item)] = { type: media.type, item };
}
break;
Expand Down

0 comments on commit f799b44

Please sign in to comment.