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 1 commit
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
22 changes: 20 additions & 2 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.id === itemId);

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

//
// Listeners

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/Components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Link as RouterLink } from 'react-router-dom';
import styles from './Link.css';

interface ReactRouterLinkProps {
to?: string;
to?: any;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs an undo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a bit of a rework on this component that I'll commit up soon. Turns out how we are using this intermittent Link makes the type of to somewhat challenging.

}

export interface LinkProps extends React.HTMLProps<HTMLAnchorElement> {
Expand All @@ -19,6 +19,7 @@ export interface LinkProps extends React.HTMLProps<HTMLAnchorElement> {
| FunctionComponent<LinkProps>
| ComponentClass<LinkProps, unknown>;
to?: string;
toState?: string;
target?: string;
isDisabled?: boolean;
noRouter?: boolean;
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/Movie/MovieCollectionLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import MonitorToggleButton from 'Components/MonitorToggleButton';
import styles from './MovieCollectionLabel.css';
import Link from '../Components/Link/Link';
mynameisbogdan marked this conversation as resolved.
Show resolved Hide resolved

class MovieCollectionLabel extends Component {

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

render() {
const {
id,
title,
monitored,
onMonitorTogglePress
Expand All @@ -31,7 +33,11 @@ class MovieCollectionLabel extends Component {
size={15}
onPress={onMonitorTogglePress}
/>
{title}
<Link
to={'/collections'}
toState={{ navigateToId: id}}>
{title}
</Link>
</div>
);
}
Expand Down