Skip to content

Commit

Permalink
fix: Fix Jellyseerr Avatar Loading Issue (#2197)
Browse files Browse the repository at this point in the history
fix: Fix Jellyseerr Avatar Loading Issue
feat: Add Fallback Image.
  • Loading branch information
TyxTang authored Nov 27, 2024
1 parent 95c126f commit b59921b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/server/api/routers/media-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const mediaRequestsRouter = createTRPCRouter({
name: genericItem.name,
userName: item.requestedBy.displayName,
userProfilePicture: constructAvatarUrl(appUrl, item.requestedBy.avatar),
fallbackUserProfilePicture: constructAvatarUrl(appUrl, item.requestedBy.avatar,'avatarproxy'),
userLink: `${appUrl}/users/${item.requestedBy.id}`,
userRequestCount: item.requestedBy.requestCount,
airDate: genericItem.airDate,
Expand Down Expand Up @@ -119,6 +120,7 @@ export const mediaRequestsRouter = createTRPCRouter({
id: user.id,
userName: user.displayName,
userProfilePicture: constructAvatarUrl(appUrl, user.avatar),
fallbackUserProfilePicture: constructAvatarUrl(appUrl, user.avatar,'avatarproxy'),
userLink: `${appUrl}/users/${user.id}`,
userRequestCount: user.requestCount,
};
Expand All @@ -137,14 +139,14 @@ export const mediaRequestsRouter = createTRPCRouter({
}),
});

const constructAvatarUrl = (appUrl: string, avatar: string) => {
const constructAvatarUrl = (appUrl: string, avatar: string, path?: string) => {
const isAbsolute = avatar.startsWith('http://') || avatar.startsWith('https://');

if (isAbsolute) {
return avatar;
}

return `${appUrl}/${avatar}`;
return `${appUrl}/${path?.concat("/") ?? "" }${avatar}`;
};

const retrieveDetailsForItem = async (
Expand Down
14 changes: 9 additions & 5 deletions src/widgets/media-requests/MediaRequestListTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Stack,
Text,
Tooltip,
Avatar,
useMantineTheme,
} from '@mantine/core';
import { notifications } from '@mantine/notifications';
Expand Down Expand Up @@ -170,14 +171,17 @@ function MediaRequestListTile({ widget }: MediaRequestListWidgetProps) {
</Flex>
<Stack justify="center">
<Flex gap="xs">
<Image
<Avatar
src={item.userProfilePicture}
width={25}
height={25}
size={25}
alt="requester avatar"
radius="xl"
withPlaceholder
/>
>
<Image
src={item.fallbackUserProfilePicture}
alt="requester avatar"
/>
</Avatar>
<Anchor
href={item.userLink}
target={widget.properties.openInNewTab ? '_blank' : '_self'}
Expand Down
5 changes: 4 additions & 1 deletion src/widgets/media-requests/MediaRequestStatsTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Stack,
Text,
Tooltip,
Image,
useMantineTheme,
} from '@mantine/core';
import { useElementSize } from '@mantine/hooks';
Expand Down Expand Up @@ -163,7 +164,9 @@ function MediaRequestStatsTile({ widget }: MediaRequestStatsWidgetProps) {
/>
</Tooltip.Floating>
)}
<Avatar radius="xl" size={45} src={user.userProfilePicture} alt="user avatar" />
<Avatar radius="xl" size={45} src={user.userProfilePicture} alt="user avatar" >
<Image src={user.fallbackUserProfilePicture} alt="user avatar" />
</Avatar>
<Stack spacing={0} style={{ flex: 1 }}>
<Text>{user.userName}</Text>
<Text size="xs">
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/media-requests/media-request-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type MediaRequest = {
name: string;
userName: string;
userProfilePicture: string;
fallbackUserProfilePicture: string;
userLink: string;
userRequestCount: number;
airDate?: string;
Expand All @@ -22,6 +23,7 @@ export type Users = {
id: number;
userName: string;
userProfilePicture: string;
fallbackUserProfilePicture: string;
userLink: string;
userRequestCount: number;
};
Expand Down

0 comments on commit b59921b

Please sign in to comment.