fixed bugs with navigating between profile slate pages

This commit is contained in:
Martina 2021-11-30 14:03:36 -08:00
parent 538b931309
commit 49c94daa47
6 changed files with 24 additions and 16 deletions

View File

@ -345,22 +345,23 @@ export default class ApplicationPage extends React.Component {
state.activePage = page.id; state.activePage = page.id;
} }
let body = document.documentElement || document.body;
if (page.id === "NAV_SLATE" || page.id === "NAV_PROFILE") { if (page.id === "NAV_SLATE" || page.id === "NAV_PROFILE") {
state.loading = true; state.loading = true;
state.data = { id: details.id }; state.data = { id: details.id };
} }
this.setState(state, () => { if (page.id === "NAV_SLATE" || page.id === "NAV_PROFILE") {
if (!popstate) { this.updateDataAndPathname({ page, details, state, popstate });
body.scrollTo(0, 0); } else {
} this.setState(state, () => {
if (page.id === "NAV_SLATE" || page.id === "NAV_PROFILE") { let body = document.documentElement || document.body;
this.updateDataAndPathname({ page, details }); if (!popstate) {
} body.scrollTo(0, 0);
}); }
});
}
}; };
updateDataAndPathname = async ({ page, details }) => { updateDataAndPathname = async ({ page, details, state, popstate }) => {
let pathname = page.pathname.split("?")[0]; let pathname = page.pathname.split("?")[0];
let search = Strings.getQueryStringFromParams(page.params); let search = Strings.getQueryStringFromParams(page.params);
let data; let data;
@ -372,7 +373,7 @@ export default class ApplicationPage extends React.Component {
return; return;
} }
data = response.data; data = response.data;
pathname = `/${data.user.username}/${data.slatename}${search}`; pathname = `/${data.owner.username}/${data.slatename}${search}`;
} else if (page?.id === "NAV_PROFILE") { } else if (page?.id === "NAV_PROFILE") {
let response = await Actions.getSerializedProfile(details); let response = await Actions.getSerializedProfile(details);
if (!response || response.error) { if (!response || response.error) {
@ -384,7 +385,12 @@ export default class ApplicationPage extends React.Component {
pathname = `/${data.username}${search}`; pathname = `/${data.username}${search}`;
} }
this.setState({ data, loading: false }); this.setState({ ...state, data, loading: false }, () => {
if (!popstate) {
let body = document.documentElement || document.body;
body.scrollTo(0, 0);
}
});
window.history.replaceState(null, "Slate", pathname); window.history.replaceState(null, "Slate", pathname);
}; };

View File

@ -120,6 +120,7 @@ function Tags({ viewer, data, onAction, ...props }) {
} }
function Profile({ viewer, data, page, onAction, ...props }) { function Profile({ viewer, data, page, onAction, ...props }) {
console.log(data);
if (page.id === "NAV_SLATE") { if (page.id === "NAV_SLATE") {
data = data.owner; data = data.owner;
} }

View File

@ -58,7 +58,8 @@ const STYLES_SIDEBAR_FILTER_WRAPPER = (theme) => css`
export function Sidebar({ viewer, onAction, data, page, isMobile }) { export function Sidebar({ viewer, onAction, data, page, isMobile }) {
const [{ sidebarState }] = useFilterContext(); const [{ sidebarState }] = useFilterContext();
console.log(data);
console.log(page);
if (!sidebarState.isVisible || isMobile) return null; if (!sidebarState.isVisible || isMobile) return null;
if ( if (

View File

@ -42,7 +42,7 @@ export default async (req, res) => {
let slates = await Data.getSlatesByUserId({ let slates = await Data.getSlatesByUserId({
ownerId: user.id, ownerId: user.id,
// includeFiles: true, includeFiles: true,
publicOnly: true, publicOnly: true,
}); });

View File

@ -188,7 +188,7 @@ export default class SceneProfile extends React.Component {
{user.library?.length ? ( {user.library?.length ? (
<DataView <DataView
key="scene-files-folder" key="scene-files-folder"
isOwner={this.props.viewer.id === this.props.user.id} isOwner={isOwner}
items={user.library} items={user.library}
onAction={this.props.onAction} onAction={this.props.onAction}
viewer={this.props.viewer} viewer={this.props.viewer}

View File

@ -279,6 +279,7 @@ app.prepare().then(async () => {
let user = await Data.getUserByUsername({ let user = await Data.getUserByUsername({
username, username,
sanitize: true, sanitize: true,
includeFiles: true,
publicOnly: true, publicOnly: true,
}); });
@ -292,7 +293,6 @@ app.prepare().then(async () => {
const slates = await Data.getSlatesByUserId({ const slates = await Data.getSlatesByUserId({
ownerId: user.id, ownerId: user.id,
// includeFiles: true,
publicOnly: true, publicOnly: true,
}); });