Skip to content

Commit d627c86

Browse files
committed
refactor: replace the badge attribute by a useEffeect
1 parent b0dfb9f commit d627c86

5 files changed

Lines changed: 22 additions & 33 deletions

File tree

next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
import "./.next/types/routes.d.ts";
3+
import "./.next/dev/types/routes.d.ts";
44

55
// NOTE: This file should not be edited
66
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.

src/components/Common/Badge/index.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,11 @@ interface BadgeProps {
1212
| 'light';
1313
className?: string;
1414
href?: string;
15-
replace?: boolean;
1615
children: React.ReactNode;
1716
}
1817

1918
const Badge = (
20-
{
21-
badgeType = 'default',
22-
className,
23-
href,
24-
replace = false,
25-
children,
26-
}: BadgeProps,
19+
{ badgeType = 'default', className, href, children }: BadgeProps,
2720
ref?: React.Ref<HTMLElement>
2821
) => {
2922
const badgeStyle = [
@@ -100,7 +93,6 @@ const Badge = (
10093
return (
10194
<Link
10295
href={href}
103-
replace={replace}
10496
className={badgeStyle.join(' ')}
10597
ref={ref as React.Ref<HTMLAnchorElement>}
10698
>

src/components/MovieDetails/index.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ const MovieDetails = ({ movie }: MovieDetailsProps) => {
118118
const router = useRouter();
119119
const intl = useIntl();
120120
const { locale } = useLocale();
121-
const [showManager, setShowManager] = useState(
122-
router.query.manage == '1' ? true : false
123-
);
121+
const [showManager, setShowManager] = useState(false);
124122
const minStudios = 3;
125123
const [showMoreStudios, setShowMoreStudios] = useState(false);
126124
const [showIssueModal, setShowIssueModal] = useState(false);
@@ -158,8 +156,14 @@ const MovieDetails = ({ movie }: MovieDetailsProps) => {
158156
);
159157

160158
useEffect(() => {
161-
setShowManager(router.query.manage == '1' ? true : false);
162-
}, [router.query.manage]);
159+
if (router.query.manage === '1') {
160+
setShowManager(true);
161+
router.replace({
162+
pathname: router.pathname,
163+
query: { movieId: router.query.movieId },
164+
});
165+
}
166+
}, [router, router.query.manage]);
163167

164168
const closeBlocklistModal = useCallback(
165169
() => setShowBlocklistModal(false),

src/components/StatusBadge/index.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import defineMessages from '@app/utils/defineMessages';
99
import { MediaStatus } from '@server/constants/media';
1010
import { MediaServerType } from '@server/constants/server';
1111
import type { DownloadingItem } from '@server/lib/downloadtracker';
12-
import { useRouter } from 'next/router';
1312
import { useIntl } from 'react-intl';
1413

1514
const messages = defineMessages('components.StatusBadge', {
@@ -48,13 +47,11 @@ const StatusBadge = ({
4847
statusLabelOverride,
4948
}: StatusBadgeProps) => {
5049
const intl = useIntl();
51-
const router = useRouter();
5250
const { hasPermission } = useUser();
5351
const settings = useSettings();
5452

5553
let mediaLink: string | undefined;
5654
let mediaLinkDescription: string | undefined;
57-
let mediaLinkReplace = false;
5855

5956
const calculateDownloadProgress = (media: DownloadingItem) => {
6057
return Math.round(((media?.size - media?.sizeLeft) / media?.size) * 100);
@@ -98,8 +95,6 @@ const StatusBadge = ({
9895
} else if (hasPermission(Permission.MANAGE_REQUESTS)) {
9996
if (mediaType && tmdbId) {
10097
mediaLink = `/${mediaType}/${tmdbId}?manage=1`;
101-
mediaLinkReplace =
102-
router.asPath.split('?')[0] === `/${mediaType}/${tmdbId}`;
10398
mediaLinkDescription = intl.formatMessage(messages.managemedia, {
10499
mediaType: intl.formatMessage(
105100
mediaType === 'movie' ? globalMessages.movie : globalMessages.tvshow
@@ -174,7 +169,6 @@ const StatusBadge = ({
174169
<Badge
175170
badgeType="success"
176171
href={mediaLink}
177-
replace={mediaLinkReplace}
178172
className={`${
179173
inProgress && 'relative !bg-gray-700/80 !px-0 hover:!bg-gray-700'
180174
} overflow-hidden`}
@@ -240,7 +234,6 @@ const StatusBadge = ({
240234
<Badge
241235
badgeType="success"
242236
href={mediaLink}
243-
replace={mediaLinkReplace}
244237
className={`${
245238
inProgress && 'relative !bg-gray-700/80 !px-0 hover:!bg-gray-700'
246239
} overflow-hidden`}
@@ -306,7 +299,6 @@ const StatusBadge = ({
306299
<Badge
307300
badgeType="primary"
308301
href={mediaLink}
309-
replace={mediaLinkReplace}
310302
className={`${
311303
inProgress && 'relative !bg-gray-700/80 !px-0 hover:!bg-gray-700'
312304
} overflow-hidden`}
@@ -361,11 +353,7 @@ const StatusBadge = ({
361353
case MediaStatus.PENDING:
362354
return (
363355
<Tooltip content={mediaLinkDescription}>
364-
<Badge
365-
badgeType="warning"
366-
href={mediaLink}
367-
replace={mediaLinkReplace}
368-
>
356+
<Badge badgeType="warning" href={mediaLink}>
369357
{intl.formatMessage(is4k ? messages.status4k : messages.status, {
370358
status: intl.formatMessage(globalMessages.pending),
371359
})}
@@ -376,7 +364,7 @@ const StatusBadge = ({
376364
case MediaStatus.BLOCKLISTED:
377365
return (
378366
<Tooltip content={mediaLinkDescription}>
379-
<Badge badgeType="danger" href={mediaLink} replace={mediaLinkReplace}>
367+
<Badge badgeType="danger" href={mediaLink}>
380368
{intl.formatMessage(is4k ? messages.status4k : messages.status, {
381369
status:
382370
statusLabelOverride ??
@@ -400,7 +388,6 @@ const StatusBadge = ({
400388
<Badge
401389
badgeType="danger"
402390
href={mediaLink}
403-
replace={mediaLinkReplace}
404391
className={`${
405392
inProgress && 'relative !bg-gray-700/80 !px-0 hover:!bg-gray-700'
406393
} overflow-hidden`}

src/components/TvDetails/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const TvDetails = ({ tv }: TvDetailsProps) => {
118118
const intl = useIntl();
119119
const { locale } = useLocale();
120120
const [showRequestModal, setShowRequestModal] = useState(false);
121-
const [showManager, setShowManager] = useState(router.query.manage == '1');
121+
const [showManager, setShowManager] = useState(false);
122122
const [showIssueModal, setShowIssueModal] = useState(false);
123123
const [isUpdating, setIsUpdating] = useState<boolean>(false);
124124
const [toggleWatchlist, setToggleWatchlist] = useState<boolean>(
@@ -154,8 +154,14 @@ const TvDetails = ({ tv }: TvDetailsProps) => {
154154
);
155155

156156
useEffect(() => {
157-
setShowManager(router.query.manage == '1');
158-
}, [router.query.manage]);
157+
if (router.query.manage === '1') {
158+
setShowManager(true);
159+
router.replace({
160+
pathname: router.pathname,
161+
query: { movieId: router.query.movieId },
162+
});
163+
}
164+
}, [router, router.query.manage]);
159165

160166
const closeBlocklistModal = useCallback(
161167
() => setShowBlocklistModal(false),

0 commit comments

Comments
 (0)