fix for carousel not opening if search for file that's on the page you're currently on

This commit is contained in:
Martina 2021-02-28 14:13:12 -08:00
parent 95dd5b9e71
commit 904aa20e5c
2 changed files with 16 additions and 4 deletions

View File

@ -136,6 +136,9 @@ export default class SceneFilesFolder extends React.Component {
this._filterFiles();
}
}
if (prevProps.page !== this.props.page) {
this.openCarouselToItem();
}
};
_handleFilterTooltip = () => {
@ -202,6 +205,10 @@ export default class SceneFilesFolder extends React.Component {
};
componentDidMount = () => {
this.openCarouselToItem();
};
openCarouselToItem = () => {
let index = -1;
let page = this.props.page;
if (page?.fileId || page?.cid || page?.index) {

View File

@ -68,11 +68,13 @@ export default class SceneSlate extends React.Component {
componentDidUpdate = async (prevProps) => {
if (this.props.data?.id && prevProps.data?.id && this.props.data.id !== prevProps.data.id) {
await this.fetchSlate();
} else if (this.props.page !== prevProps.page) {
this.openCarouselToItem();
}
};
fetchSlate = async () => {
const { user: username, slate: slatename, cid } = this.props.page;
const { user: username, slate: slatename } = this.props.page;
if (!this.props.data && (!username || !slatename)) {
this.setState({ notFound: true });
@ -137,18 +139,21 @@ export default class SceneSlate extends React.Component {
);
}
this.props.onUpdateData({ data: slate });
this.props.onUpdateData({ data: slate }, this.openCarouselToItem);
};
openCarouselToItem = () => {
let slate = this.props.data;
let index = -1;
let page = this.props.page;
if (page?.fileId || page?.cid || page?.index || !Strings.isEmpty(cid)) {
if (page?.fileId || page?.cid || page?.index || !Strings.isEmpty(page.cid)) {
if (page?.index) {
index = page.index;
} else {
for (let i = 0; i < slate.data.objects.length; i++) {
let obj = slate.data.objects[i];
if (
(obj.cid && (obj.cid === cid || obj.cid === page?.cid)) ||
(obj.cid && (obj.cid === page.cid || obj.cid === page?.cid)) ||
(obj.id && obj.id === page?.fileId)
) {
index = i;