Skip to content
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
2 changes: 1 addition & 1 deletion frontend/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<load src="html/head.html" />

<body>
<LoaderBar />
<div id="mediaQueryDebug"></div>
<load src="html/warnings.html" />
<div id="fpsCounter" class="hidden"></div>
<div class="customBackground"></div>
<div id="backgroundLoader" class="hidden"></div>
<div id="bannerCenter" class="focus"></div>
<div id="notificationCenter">
<div class="clearAll button hidden">
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/styles/core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ body {
}

#backgroundLoader {
height: 3px;
top: 0;
height: 0.25rem;
position: fixed;
width: 100%;
background: var(--main-color);
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/ts/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Notifications from "./elements/notifications";
import Config, { applyConfig, saveFullConfigToLocalStorage } from "./config";
import * as Misc from "./utils/misc";
import * as DB from "./db";
import * as Loader from "./elements/loader";
import { showLoaderBar, hideLoaderBar } from "./signals/loader-bar";
import * as LoginPage from "./pages/login";
import * as RegisterCaptchaModal from "./modals/register-captcha";
import {
Expand Down Expand Up @@ -43,15 +43,15 @@ async function sendVerificationEmail(): Promise<void> {
return;
}

Loader.show();
showLoaderBar();
qs(".sendVerificationEmail")?.disable();
const response = await Ape.users.verificationEmail();
qs(".sendVerificationEmail")?.enable();
if (response.status !== 200) {
Loader.hide();
hideLoaderBar();
Notifications.add("Failed to request verification email", -1, { response });
} else {
Loader.hide();
hideLoaderBar();
Notifications.add("Verification email sent", 1);
}
}
Expand Down Expand Up @@ -296,16 +296,16 @@ async function addAuthProvider(
});
return;
}
Loader.show();
showLoaderBar();
const user = getAuthenticatedUser();
if (!user) return;
try {
await linkWithPopup(user, provider);
Loader.hide();
hideLoaderBar();
Notifications.add(`${providerName} authentication added`, 1);
AuthEvent.dispatch({ type: "authConfigUpdated" });
} catch (error) {
Loader.hide();
hideLoaderBar();
const message = Misc.createErrorMessage(
error,
`Failed to add ${providerName} authentication`,
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/ts/commandline/commandline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getCommandlineSubgroup,
setCommandlineSubgroup,
} from "../signals/core";
import * as Loader from "../elements/loader";
import { showLoaderBar, hideLoaderBar } from "../signals/loader-bar";
import { Command, CommandsSubgroup, CommandWithValidation } from "./types";
import { areSortedArraysEqual, areUnsortedArraysEqual } from "../utils/arrays";
import { parseIntOptional } from "../utils/numbers";
Expand Down Expand Up @@ -123,11 +123,11 @@ export function show(
if (typeof overrideStringOrGroup === "string") {
const exists = CommandlineLists.doesListExist(overrideStringOrGroup);
if (exists) {
Loader.show();
showLoaderBar();
subgroupOverride = await CommandlineLists.getList(
overrideStringOrGroup,
);
Loader.hide();
hideLoaderBar();
} else {
subgroupOverride = null;
usingSingleList = Config.singleListCommandLine === "on";
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/ts/commandline/lists/quote-favorites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import QuotesController, { Quote } from "../../controllers/quotes-controller";
import * as Notifications from "../../elements/notifications";
import { isAuthenticated } from "../../firebase";
import { createErrorMessage } from "../../utils/misc";
import * as Loader from "../../elements/loader";
import { showLoaderBar, hideLoaderBar } from "../../signals/loader-bar";
import * as TestWords from "../../test/test-words";
import { Command } from "../types";

Expand All @@ -23,15 +23,15 @@ const commands: Command[] = [
},
exec: async (): Promise<void> => {
try {
Loader.show();
showLoaderBar();
await QuotesController.setQuoteFavorite(
TestWords.currentQuote as Quote,
true,
);
Loader.hide();
hideLoaderBar();
Notifications.add("Quote added to favorites", 1);
} catch (e) {
Loader.hide();
hideLoaderBar();
const message = createErrorMessage(
e,
"Failed to add quote to favorites",
Expand All @@ -55,15 +55,15 @@ const commands: Command[] = [
},
exec: async (): Promise<void> => {
try {
Loader.show();
showLoaderBar();
await QuotesController.setQuoteFavorite(
TestWords.currentQuote as Quote,
false,
);
Loader.hide();
hideLoaderBar();
Notifications.add("Quote removed from favorites", 1);
} catch (e) {
Loader.hide();
hideLoaderBar();
const message = createErrorMessage(
e,
"Failed to remove quote from favorites",
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/ts/components/common/LoaderBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { JSX } from "solid-js";
import { useRefWithUtils } from "../../hooks/useRefWithUtils";
import { getLoaderBarSignal } from "../../signals/loader-bar";
import { useVisibilityAnimation } from "../../hooks/useVisibilityAnimation";
import { applyReducedMotion } from "../../utils/misc";

export function LoaderBar(): JSX.Element {
const [ref, loaderEl] = useRefWithUtils<HTMLDivElement>();

useVisibilityAnimation({
element: loaderEl,
isVisible: () => getLoaderBarSignal()?.visible === true,
showAnimationOptions: {
delay: applyReducedMotion(getLoaderBarSignal()?.instant ? 0 : 125),
},
});

return <div id="backgroundLoader" class="hidden" ref={ref}></div>;
}
3 changes: 2 additions & 1 deletion frontend/src/ts/components/mount.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { render } from "solid-js/web";
import { qsa } from "../utils/dom";

import { JSXElement } from "solid-js";
import { Footer } from "./layout/footer/Footer";
import { Modals } from "./modals/Modals";
import { AboutPage } from "./pages/AboutPage";
import { LoaderBar } from "./common/LoaderBar";

const components: Record<string, () => JSXElement> = {
Footer: () => <Footer />,
Modals: () => <Modals />,
AboutPage: () => <AboutPage />,
LoaderBar: () => <LoaderBar />,
};

function mountToMountpoint(name: string, component: () => JSXElement): void {
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/ts/controllers/challenge-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import * as Funbox from "../test/funbox/funbox";
import Config, { setConfig } from "../config";
import * as ConfigEvent from "../observables/config-event";
import * as TestState from "../test/test-state";
import * as Loader from "../elements/loader";

import { showLoaderBar, hideLoaderBar } from "../signals/loader-bar";
import { CustomTextLimitMode, CustomTextMode } from "@monkeytype/schemas/util";
import {
Config as ConfigType,
Expand Down Expand Up @@ -284,11 +285,11 @@ export async function setup(challengeName: string): Promise<boolean> {
nosave: true,
});
} else if (challenge.type === "script") {
Loader.show();
showLoaderBar();
const response = await fetch(
"/challenges/" + (challenge.parameters[0] as string),
);
Loader.hide();
hideLoaderBar();
if (response.status !== 200) {
throw new Error(`${response.status} ${response.statusText}`);
}
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/ts/controllers/theme-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import * as BackgroundFilter from "../elements/custom-background-filter";
import * as ConfigEvent from "../observables/config-event";
import * as DB from "../db";
import * as Notifications from "../elements/notifications";
import * as Loader from "../elements/loader";

import { showLoaderBar, hideLoaderBar } from "../signals/loader-bar";
import { debounce } from "throttle-debounce";
import { ThemeName } from "@monkeytype/schemas/configs";
import { themes, ThemesList } from "../constants/themes";
Expand Down Expand Up @@ -93,7 +94,7 @@ export async function loadStyle(name: string): Promise<void> {
console.debug("Theme controller loading style", name);
loadStyleLoaderTimeouts.push(
setTimeout(() => {
Loader.show();
showLoaderBar();
}, 100),
);
qs("#nextTheme")?.remove();
Expand All @@ -104,7 +105,7 @@ export async function loadStyle(name: string): Promise<void> {
link.id = "nextTheme";
link.onload = (): void => {
console.debug("Theme controller loaded style", name);
Loader.hide();
hideLoaderBar();
swapCurrentToNext();
loadStyleLoaderTimeouts.map((t) => clearTimeout(t));
loadStyleLoaderTimeouts = [];
Expand All @@ -114,7 +115,7 @@ export async function loadStyle(name: string): Promise<void> {
link.onerror = (e): void => {
console.debug("Theme controller failed to load style", name, e);
console.error(`Failed to load theme ${name}`, e);
Loader.hide();
hideLoaderBar();
Notifications.add("Failed to load theme", 0);
swapCurrentToNext();
loadStyleLoaderTimeouts.map((t) => clearTimeout(t));
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/ts/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
TestActivityCalendar,
ModifiableTestActivityCalendar,
} from "./elements/test-activity-calendar";
import * as Loader from "./elements/loader";

import { showLoaderBar, hideLoaderBar } from "./signals/loader-bar";
import { Badge, CustomTheme } from "@monkeytype/schemas/users";
import { Config, Difficulty } from "@monkeytype/schemas/configs";
import {
Expand Down Expand Up @@ -1110,11 +1109,11 @@ export async function getTestActivityCalendar(
return undefined;
}

Loader.show();
showLoaderBar();
const response = await Ape.users.getTestActivity();
if (response.status !== 200) {
Notifications.add("Error getting test activities", -1, { response });
Loader.hide();
hideLoaderBar();
return undefined;
}

Expand All @@ -1134,7 +1133,7 @@ export async function getTestActivityCalendar(
true,
);
}
Loader.hide();
hideLoaderBar();
}

return dbSnapshot.testActivityByYear[yearString];
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/ts/elements/account-settings/ape-key-table.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Loader from "../../elements/loader";
import { showLoaderBar, hideLoaderBar } from "../../signals/loader-bar";
import * as Notifications from "../../elements/notifications";
import Ape from "../../ape";
import { ApeKey, ApeKeys } from "@monkeytype/schemas/ape-keys";
Expand Down Expand Up @@ -257,12 +257,12 @@ function refreshList(): void {
async function toggleActiveKey(keyId: string): Promise<void> {
const key = apeKeys?.[keyId];
if (!key || apeKeys === undefined) return;
Loader.show();
showLoaderBar();
const response = await Ape.apeKeys.save({
params: { apeKeyId: keyId },
body: { enabled: !key.enabled },
});
Loader.hide();
hideLoaderBar();
if (response.status !== 200) {
Notifications.add("Failed to update key", -1, { response });
return;
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/ts/elements/account/result-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DB from "../../db";
import Config from "../../config";
import * as Notifications from "../notifications";
import Ape from "../../ape/index";
import * as Loader from "../loader";
import { showLoaderBar, hideLoaderBar } from "../../signals/loader-bar";
import SlimSelect from "slim-select";
import { QuoteLength } from "@monkeytype/schemas/configs";
import {
Expand Down Expand Up @@ -183,11 +183,11 @@ export async function createFilterPreset(
name: string,
): Promise<number | undefined> {
name = name.replace(/ /g, "_");
Loader.show();
showLoaderBar();
const result = await Ape.users.addResultFilterPreset({
body: { ...filters, name },
});
Loader.hide();
hideLoaderBar();
if (result.status === 200) {
addFilterPresetToSnapshot({ ...filters, name, _id: result.body.data });
void updateFilterPresets();
Expand All @@ -212,11 +212,11 @@ function removeFilterPresetFromSnapshot(id: string): void {

// deletes the currently selected filter preset
async function deleteFilterPreset(id: string): Promise<void> {
Loader.show();
showLoaderBar();
const result = await Ape.users.removeResultFilterPreset({
params: { presetId: id },
});
Loader.hide();
hideLoaderBar();
if (result.status === 200) {
removeFilterPresetFromSnapshot(id);
void updateFilterPresets();
Expand Down
32 changes: 0 additions & 32 deletions frontend/src/ts/elements/loader.ts

This file was deleted.

6 changes: 3 additions & 3 deletions frontend/src/ts/elements/settings/theme-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Colors from "../../utils/colors";
import * as Notifications from "../notifications";
import * as ThemeColors from "../theme-colors";
import * as ChartController from "../../controllers/chart-controller";
import * as Loader from "../loader";
import { showLoaderBar, hideLoaderBar } from "../../signals/loader-bar";
import * as DB from "../../db";
import * as ConfigEvent from "../../observables/config-event";
import { isAuthenticated } from "../../firebase";
Expand Down Expand Up @@ -479,9 +479,9 @@ $(".pageSettings #saveCustomThemeButton").on("click", async () => {
colors: Config.customThemeColors,
};

Loader.show();
showLoaderBar();
await DB.addCustomTheme(newCustomTheme);
Loader.hide();
hideLoaderBar();
}
void fillCustomButtons();
});
Expand Down
Loading
Loading