Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigate to collection from movie page #9399

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 22 additions & 3 deletions frontend/src/Collection/Overview/CollectionOverviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class CollectionOverviews extends Component {
columnCount: 1,
posterWidth: 162,
posterHeight: 238,
rowHeight: calculateRowHeight(238, null, props.isSmallScreen, {})
rowHeight: calculateRowHeight(238, null, props.isSmallScreen, {}),
navigateToId: props.location.state ? props.location.state.navigateToId : 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
navigateToId: props.location.state ? props.location.state.navigateToId : 0
navigateToId: props.location.state?.navigateToId ?? 0

};

this._grid = null;
Expand All @@ -72,7 +73,8 @@ class CollectionOverviews extends Component {
const {
width,
rowHeight,
scrollRestored
scrollRestored,
navigateToId
} = this.state;

if (prevProps.sortKey !== sortKey ||
Expand Down Expand Up @@ -106,6 +108,10 @@ class CollectionOverviews extends Component {
});
}
}

if (navigateToId) {
this.scrollToItem(navigateToId);
}
}

//
Expand Down Expand Up @@ -186,6 +192,18 @@ class CollectionOverviews extends Component {
);
};

scrollToItem = (itemId) => {
const index = this.props.items.findIndex((item) => item.tmdbId === itemId);

if (index !== -1 && this._grid) {
this._grid.scrollToCell({
columnIndex: 0,
rowIndex: index,
align: 'start'
});
}
};

//
// Listeners

Expand Down Expand Up @@ -265,7 +283,8 @@ CollectionOverviews.propTypes = {
isSmallScreen: PropTypes.bool.isRequired,
timeFormat: PropTypes.string.isRequired,
selectedState: PropTypes.object.isRequired,
onSelectedChange: PropTypes.func.isRequired
onSelectedChange: PropTypes.func.isRequired,
location: PropTypes.object.isRequired
};

export default CollectionOverviews;
40 changes: 24 additions & 16 deletions frontend/src/Components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ import React, {
import { Link as RouterLink } from 'react-router-dom';
import styles from './Link.css';

interface ReactRouterLinkProps {
to?: string;
}

export interface LinkProps extends React.HTMLProps<HTMLAnchorElement> {
className?: string;
component?:
| string
| FunctionComponent<LinkProps>
| ComponentClass<LinkProps, unknown>;
to?: string;
to?: string | { pathname: string; state?: object };
target?: string;
isDisabled?: boolean;
noRouter?: boolean;
Expand Down Expand Up @@ -46,26 +42,38 @@ function Link(props: LinkProps) {
[isDisabled, onPress]
);

const linkProps: React.HTMLProps<HTMLAnchorElement> & ReactRouterLinkProps = {
const linkProps: React.HTMLProps<HTMLAnchorElement> & LinkProps = {
target,
};
let el = component;

if (to) {
if (/\w+?:\/\//.test(to)) {
el = 'a';
linkProps.href = to;
linkProps.target = target || '_blank';
linkProps.rel = 'noreferrer';
} else if (noRouter) {
el = 'a';
linkProps.href = to;
linkProps.target = target || '_self';
if (typeof to === 'string') {
if (/\w+?:\/\//.test(to)) {
el = 'a';
linkProps.href = to;
linkProps.target = target || '_blank';
linkProps.rel = 'noreferrer';
} else if (noRouter) {
el = 'a';
linkProps.href = to;
linkProps.target = target || '_self';
} else {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
el = RouterLink;
linkProps.to = `${window.Radarr.urlBase}/${to.replace(/^\//, '')}`;
linkProps.target = target;
}
} else {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
el = RouterLink;
linkProps.to = `${window.Radarr.urlBase}/${to.replace(/^\//, '')}`;
const url = `${window.Radarr.urlBase}/${to.pathname.replace(/^\//, '')}`;
linkProps.to = {
pathname: url,
...(to.state && { state: to.state }),
};
linkProps.target = target;
}
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/Movie/MovieCollectionLabel.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
color: var(--iconButtonHoverLightColor);
}
}

.titleLink {
color: inherit;
}
1 change: 1 addition & 0 deletions frontend/src/Movie/MovieCollectionLabel.css.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Please do not change this file!
interface CssExports {
'monitorToggleButton': string;
'titleLink': string;
}
export const cssExports: CssExports;
export default cssExports;
15 changes: 13 additions & 2 deletions frontend/src/Movie/MovieCollectionLabel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import Link from 'Components/Link/Link';
import MonitorToggleButton from 'Components/MonitorToggleButton';
import styles from './MovieCollectionLabel.css';

Expand All @@ -18,6 +19,7 @@ class MovieCollectionLabel extends Component {

render() {
const {
tmdbId,
title,
monitored,
onMonitorTogglePress
Expand All @@ -31,7 +33,15 @@ class MovieCollectionLabel extends Component {
size={15}
onPress={onMonitorTogglePress}
/>
{title}
<Link
to={{
pathname: '/collections',
state: { navigateToId: tmdbId }
}}
className={styles.titleLink}
>
{title}
</Link>
</div>
);
}
Expand All @@ -40,7 +50,8 @@ class MovieCollectionLabel extends Component {
MovieCollectionLabel.propTypes = {
title: PropTypes.string.isRequired,
monitored: PropTypes.bool.isRequired,
onMonitorTogglePress: PropTypes.func.isRequired
onMonitorTogglePress: PropTypes.func.isRequired,
tmdbId: PropTypes.string.isRequired
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tmdbId: PropTypes.string.isRequired
tmdbId: PropTypes.number.isRequired

};

export default MovieCollectionLabel;
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ function createUnoptimizedSelector(uiSection) {
const items = movies.items.map((s) => {
const {
id,
tmdbId,
sortTitle
} = s;

return {
id,
tmdbId,
sortTitle
};
});
Expand Down