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

Place redirect smoothing #4732

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion server/templates/place.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ <h3 id="locale" data-lc="{{ locale }}"></h3>
<div id="place-summary" class="row-col place-summary-container">{{ place_summary }}</div>
<div id="main-pane" class="row"></div>
{# TRANSLATORS: A message shown on the page while the content is loading. #}
<div id="page-loading" className="mt-4">{% trans %}Loading...{% endtrans %}</div>
<div id="page-loading" className="mt-4">
{# SVG: Material Icon: Progress Activity, Source: https://fonts.google.com/icons #}
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#5f6368"><path d="M480-80q-82 0-155-31.5t-127.5-86Q143-252 111.5-325T80-480q0-83 31.5-155.5t86-127Q252-817 325-848.5T480-880q17 0 28.5 11.5T520-840q0 17-11.5 28.5T480-800q-133 0-226.5 93.5T160-480q0 133 93.5 226.5T480-160q133 0 226.5-93.5T800-480q0-17 11.5-28.5T840-520q17 0 28.5 11.5T880-480q0 82-31.5 155t-86 127.5q-54.5 54.5-127 86T480-80Z"/></svg>
<p>{% trans %}Loading{% endtrans %}</p>
</div>
</div>
</div>
</div>
Expand Down
21 changes: 21 additions & 0 deletions static/css/place/place.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,24 @@ h3 {
#main-pane .button-dc {
margin-top: -3px;
}

#page-loading {
display: flex;
align-items: center;
gap: 8px;
svg {
animation: rotating 2s linear infinite;
}
p {
margin: 3px 0 0 0;
}
}

@keyframes rotating {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
9 changes: 8 additions & 1 deletion static/css/place/place_page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,17 @@ $chart-border: 0.5px solid #dee2e6;
padding: 0.25rem;
}

#main-pane {
opacity: 0;
transition: opacity 0.7s ease-in-out;
}

#sidebar-outer {
border-top: $vertical-section-border;
margin-top: $vertical-section-margin;
padding-top: $vertical-section-margin;
opacity: 0;
transition: opacity 0.7s ease-in-out;

@include media-breakpoint-up(lg) {
border: none;
Expand All @@ -269,7 +276,7 @@ $chart-border: 0.5px solid #dee2e6;
#sidebar-region {
padding-top: 15px;
position: relative;
transition: transform 300ms linear;
transition: transform 300ms ease-in-out;
}

#sidebar-region.fixed {
Expand Down
8 changes: 6 additions & 2 deletions static/js/apps/explore/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,14 @@ export function App(props: { isDemo: boolean }): JSX.Element {
sessionId: "session" in fulfillData ? fulfillData["session"]["id"] : "",
svSource: fulfillData["svSource"],
};
let isPendingRedirect = false;
if (
pageMetadata &&
pageMetadata.pageConfig &&
pageMetadata.pageConfig.categories
) {
if (shouldSkipPlaceOverview(pageMetadata)) {
isPendingRedirect = shouldSkipPlaceOverview(pageMetadata);
if (isPendingRedirect) {
const placeDcid = pageMetadata.place.dcid;
const url = `/place/${placeDcid}`;
window.location.replace(url);
Expand Down Expand Up @@ -262,7 +264,9 @@ export function App(props: { isDemo: boolean }): JSX.Element {
pastSourceContext: fulfillData["pastSourceContext"],
sessionId: pageMetadata.sessionId,
});
setLoadingStatus(LoadingStatus.SUCCESS);
setLoadingStatus(
isPendingRedirect ? LoadingStatus.LOADING : LoadingStatus.SUCCESS
);
}

function handleHashChange(): void {
Expand Down
7 changes: 4 additions & 3 deletions static/js/place/place.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ function renderPage(): void {
return;
}
const loadingElem = document.getElementById("page-loading");
const sidebarElem = document.getElementById("sidebar-outer");
const mainPaneElem = document.getElementById("main-pane");
loadingElem.style.display = "none";
sidebarElem.style.opacity = "1";
mainPaneElem.style.opacity = "1";
const data: PageData = landingPageData;
const isUsaPlace = isPlaceInUsa(dcid, data.parentPlaces);

Expand All @@ -205,9 +209,6 @@ function renderPage(): void {
}),
document.getElementById("nl-search-bar")
);
} else {
// when NL search bar is hidden, need to adjust spacing
document.getElementById("nl-search-bar").style.height = "2rem";
}

ReactDOM.render(
Expand Down
Loading