Skip to content

Commit

Permalink
Fix loader in showcase and add it to screenshots (#2710)
Browse files Browse the repository at this point in the history
* Fix loader in showcase and add it to screenshots.

* Cast import to string
  • Loading branch information
sea-snake authored Nov 27, 2024
1 parent 69b89df commit c15d6d2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
5 changes: 0 additions & 5 deletions src/frontend/screenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ async function takeShowcaseScreenshots(browser: WebdriverIO.Browser) {

// Iterate the pages and screenshot them
for (const pageName of pageNames) {
// Skip the loader, because it's animated
if (pageName === "loader") {
continue;
}

await visit(browser, `http://localhost:5174/${pageName}`);

await browser.execute('document.body.style.caretColor = "transparent"');
Expand Down
22 changes: 16 additions & 6 deletions src/frontend/src/components/loader.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { ERROR_SUPPORT_URL } from "$src/config";
import { html, render } from "lit-html";
import loaderUrl from "./loader.svg";

// Use same import approach as in 'src/frontend/src/flows/dappsExplorer/dapps.ts'
// this makes the import the same format (url string) in both the build and showcase.
const loaderUrl = import.meta.glob("./loader.svg", {
eager: true,
query: "?url",
import: "default",
})["./loader.svg"] as string;

// Duration in milliseconds a user considers as taking forever
const TAKING_FOREVER = 10000;

const loader = (takingForever = false) =>
html` <div id="loader" class="c-loader">
<img class="c-loader__image" src=${loaderUrl} alt="loading" />
<img class="c-loader__image" src="${loaderUrl}" alt="loading" />
${takingForever &&
html`<a
href="${ERROR_SUPPORT_URL}"
Expand All @@ -18,9 +25,9 @@ const loader = (takingForever = false) =>
>`}
</div>`;

const startLoader = () => {
const startLoader = (showCheckOngoingIssues?: boolean) => {
const container = document.getElementById("loaderContainer") as HTMLElement;
render(loader(), container);
render(loader(showCheckOngoingIssues), container);

const takingForeverTimeout = setTimeout(
() => render(loader(true), container),
Expand All @@ -33,8 +40,11 @@ const startLoader = () => {
};
};

export const withLoader = async <A>(action: () => Promise<A>): Promise<A> => {
const endLoader = startLoader();
export const withLoader = async <A>(
action: () => Promise<A>,
showCheckOngoingIssues?: boolean
): Promise<A> => {
const endLoader = startLoader(showCheckOngoingIssues);
try {
return await action();
} finally {
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -3149,6 +3149,7 @@ input[type="checkbox"] {
animation-duration: 5s;
animation-iteration-count: infinite;
animation-timing-function: ease-in-out;
transform: translate(-50%, -50%);
}

.c-loader__link {
Expand Down
7 changes: 6 additions & 1 deletion src/showcase/src/pages/loader.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import Screen from "../layouts/Screen.astro";
import { withLoader } from "$src/components/loader";
import { showMessage } from "$src/components/message";

// TODO: Fix loader image not loading
withLoader(() => new Promise(() => showMessage({ message: "Loading..." })))
</script>
<style>
/* Disable loader animation */
.c-loader__image {
animation: none;
}
</style>
</Screen>
18 changes: 18 additions & 0 deletions src/showcase/src/pages/loaderTakingForever.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
import Screen from "../layouts/Screen.astro";
---

<Screen title="Loader" pageName="loader">
<script>
import { withLoader } from "$src/components/loader";
import { showMessage } from "$src/components/message";

withLoader(() => new Promise(() => showMessage({ message: "Loading..." })), true)
</script>
<style>
/* Disable loader animation */
.c-loader__image {
animation: none;
}
</style>
</Screen>

0 comments on commit c15d6d2

Please sign in to comment.