Skip to content

Commit 29f8924

Browse files
authored
refactor: add Page component (@fehmer) (#7987)
1 parent 45bb17f commit 29f8924

10 files changed

Lines changed: 396 additions & 371 deletions

File tree

frontend/src/ts/collections/presets.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const presetsCollection = createCollection(
3636
getKey: (it) => it._id,
3737
queryFn: async () => {
3838
if (!isAuthenticated()) return [];
39+
3940
const response = await Ape.presets.get();
4041

4142
if (response.status !== 200) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ParentProps, Show } from "solid-js";
2+
3+
import { PageName } from "../../pages/page";
4+
import { getActivePage, isAuthenticated } from "../../states/core";
5+
6+
export function Page(
7+
props: {
8+
id: PageName;
9+
needsAuthentication?: boolean;
10+
} & ParentProps,
11+
) {
12+
const isOpen = () => getActivePage() === props.id;
13+
const isAllowed = () => !props.needsAuthentication || isAuthenticated();
14+
15+
return <Show when={isOpen() && isAllowed()}>{props.children}</Show>;
16+
}

frontend/src/ts/components/mount.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import { LeaderboardPage } from "./pages/leaderboard/LeaderboardPage";
1818
import { LoginPage } from "./pages/login/LoginPage";
1919
import { ProfilePage } from "./pages/profile/ProfilePage";
2020
import { ProfileSearchPage } from "./pages/profile/ProfileSearchPage";
21-
import { Settings } from "./pages/settings/Settings";
21+
import { SettingsPage } from "./pages/settings/SettingsPage";
2222
import { TestConfig } from "./pages/test/TestConfig";
2323
import { Popups } from "./popups/Popups";
2424

2525
const components: Record<string, () => JSXElement> = {
2626
footer: () => <Footer />,
2727
aboutpage: () => <AboutPage />,
28-
settingspage: () => <Settings />,
28+
settingspage: () => <SettingsPage />,
2929
accountpage: () => <AccountPage />,
3030
loginpage: () => <LoginPage />,
3131
leaderboardpage: () => <LeaderboardPage />,
@@ -40,7 +40,6 @@ const components: Record<string, () => JSXElement> = {
4040
devtools: () => <DevTools />,
4141
testconfig: () => <TestConfig />,
4242
commandlinehotkey: () => <CommandlineHotkey />,
43-
solidSettings: () => <Settings />,
4443
};
4544

4645
function mountToMountpoint(name: string, component: () => JSXElement): void {

0 commit comments

Comments
 (0)