Skip to content

Commit b38b299

Browse files
committed
Implement root route without redirect
1 parent 15b63f2 commit b38b299

18 files changed

Lines changed: 70 additions & 75 deletions

react-router.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default {
1010
prerender: {
1111
unstable_concurrency: 8,
1212
async paths({ getStaticPaths }) {
13-
const paths = [...getStaticPaths()];
13+
const paths = [...getStaticPaths(), "/"];
1414

1515
for (const game of GAME_LIST) {
1616
paths.push(`/${game.id}`);

src/components/layout/NavBar.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from "react";
22
import { styled } from "@linaria/react";
3-
import { useNavigate, useLocation, useParams, href } from "react-router";
3+
import { useNavigate, useLocation, useParams } from "react-router";
44
import { AppContext } from "../AppContext";
55
import { SearchBox } from "../search/SearchBox";
6+
import { schemaPath } from "../schema/DeclarationsContext";
67
import { GAME_LIST, GameId, getGameDef } from "../../games-list";
78
import { ICONS_URL } from "../kind-icon/KindIcon";
89

@@ -63,7 +64,7 @@ export function GameSwitcher({ currentGame }: { currentGame: GameId }) {
6364
if (gameId === currentGame) return;
6465

6566
navigate({
66-
pathname: href("/:game/:module?/:scope?", { game: gameId, module, scope }),
67+
pathname: schemaPath(gameId, module, scope),
6768
hash: location.hash,
6869
});
6970
}

src/components/layout/Sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NavLink } from "../Link";
33
import { styled } from "@linaria/react";
44
import { IconKind, KindIcon } from "../kind-icon/KindIcon";
55
import { Declaration } from "../../data/types";
6-
import { DeclarationsContext, declarationPath } from "../schema/DeclarationsContext";
6+
import { DeclarationsContext, schemaPath } from "../schema/DeclarationsContext";
77

88
// @ts-expect-error Linaria styled() doesn't support ForwardRefExoticComponent
99
const SidebarLink = styled(NavLink)`
@@ -64,7 +64,7 @@ export const DeclarationSidebarElement: React.FC<{
6464
const { game } = useContext(DeclarationsContext);
6565
return (
6666
<SidebarElement
67-
to={declarationPath(game, declaration.module, declaration.name)}
67+
to={schemaPath(game, declaration.module, declaration.name)}
6868
icon={declaration.kind}
6969
text={declaration.name}
7070
title={`${declaration.kind} in ${declaration.module}`}

src/components/schema/Breadcrumb.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React, { useContext } from "react";
2-
import { href } from "react-router";
32
import { Link } from "../Link";
43
import { styled } from "@linaria/react";
5-
import { DeclarationsContext, declarationPath } from "./DeclarationsContext";
4+
import { DeclarationsContext, schemaPath } from "./DeclarationsContext";
65
import { getGameDef, SITE_ORIGIN } from "../../games-list";
76

87
const BreadcrumbNav = styled.nav`
@@ -51,20 +50,20 @@ export const DeclarationBreadcrumb: React.FC<{
5150
const gameData = getGameDef(game);
5251
if (!gameData) return null;
5352

54-
const nameUrl = declarationPath(game, module, name);
53+
const nameUrl = schemaPath(game, module, name);
5554
let position = 1;
5655

5756
return (
5857
<BreadcrumbNav aria-label="Breadcrumb">
5958
<BreadcrumbList itemScope itemType="https://schema.org/BreadcrumbList">
6059
<BreadcrumbItem itemProp="itemListElement" itemScope itemType="https://schema.org/ListItem">
61-
<BreadcrumbLink to={href("/:game/:module?/:scope?", { game })} itemProp="item">
60+
<BreadcrumbLink to={schemaPath(game)} itemProp="item">
6261
<span itemProp="name">{gameData.name}</span>
6362
</BreadcrumbLink>
6463
<meta itemProp="position" content={String(position++)} />
6564
</BreadcrumbItem>
6665
<BreadcrumbItem itemProp="itemListElement" itemScope itemType="https://schema.org/ListItem">
67-
<BreadcrumbLink to={href("/:game/:module?/:scope?", { game, module })} itemProp="item">
66+
<BreadcrumbLink to={schemaPath(game, module)} itemProp="item">
6867
<span itemProp="name">{module}</span>
6968
</BreadcrumbLink>
7069
<meta itemProp="position" content={String(position++)} />
@@ -75,7 +74,7 @@ export const DeclarationBreadcrumb: React.FC<{
7574
itemScope
7675
itemType="https://schema.org/ListItem"
7776
>
78-
<BreadcrumbLink to={declarationPath(game, parent.module, parent.name)} itemProp="item">
77+
<BreadcrumbLink to={schemaPath(game, parent.module, parent.name)} itemProp="item">
7978
<span itemProp="name">{parent.name}</span>
8079
</BreadcrumbLink>
8180
<meta itemProp="position" content={String(position++)} />

src/components/schema/ClassTree.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useContext, useMemo } from "react";
22
import { Link } from "../Link";
33
import { styled } from "@linaria/react";
44
import { SchemaClass } from "../../data/types";
5-
import { DeclarationsContext, declarationKey, declarationPath } from "./DeclarationsContext";
5+
import { DeclarationsContext, declarationKey, schemaPath } from "./DeclarationsContext";
66

77
interface TreeNode {
88
cls: SchemaClass;
@@ -95,7 +95,7 @@ function TreeNodeView({ node, game }: { node: TreeNode; game: string }) {
9595
return (
9696
<li>
9797
<ClassLink
98-
to={declarationPath(game, node.cls.module, node.cls.name)}
98+
to={schemaPath(game, node.cls.module, node.cls.name)}
9999
title={`class in ${node.cls.module}`}
100100
>
101101
{node.cls.name}

src/components/schema/ContentList.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useContext, useMemo } from "react";
2-
import { href, useParams } from "react-router";
2+
import { useParams } from "react-router";
33
import { Link } from "../Link";
44
import { styled } from "@linaria/react";
55
import { ContentWrapper, ListItem, TextMessage } from "../layout/Content";
@@ -14,6 +14,7 @@ import {
1414
DeclarationsContext,
1515
DeclarationsContextType,
1616
declarationKey,
17+
schemaPath,
1718
} from "./DeclarationsContext";
1819
import { GAME_LIST, GameId, getGameDef, compareModuleNames } from "../../games-list";
1920
import { SEARCH_TAGS } from "../search/SearchBox";
@@ -74,7 +75,7 @@ function GameList() {
7475
{GAME_LIST.map((g, i) => (
7576
<React.Fragment key={g.id}>
7677
{i > 0 && " "}
77-
<GameChip to={href("/:game/:module?/:scope?", { game: g.id })}>
78+
<GameChip to={schemaPath(g.id)}>
7879
<svg width="24" height="24">
7980
<use href={`${ICONS_URL}#game-${g.id}`} />
8081
</svg>{" "}
@@ -204,7 +205,7 @@ function ModuleList() {
204205
return (
205206
<ModuleChipsBlock>
206207
{modules.map(([mod, count]) => (
207-
<SectionLink key={mod} to={href("/:game/:module?/:scope?", { game, module: mod })}>
208+
<SectionLink key={mod} to={schemaPath(game, mod)}>
208209
{mod} ({count})
209210
</SectionLink>
210211
))}

src/components/schema/CrossGameRefs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
SchemaFieldType,
88
SchemaMetadataEntry,
99
} from "../../data/types";
10-
import { DeclarationsContext, declarationPath } from "./DeclarationsContext";
10+
import { DeclarationsContext, schemaPath } from "./DeclarationsContext";
1111
import { getGameDef, GameId } from "../../games-list";
1212
import { ICONS_URL } from "../kind-icon/KindIcon";
1313
import { SectionWrapper, SectionTitle, SectionList, SectionLink } from "./styles";
@@ -138,7 +138,7 @@ export function CrossGameRefs({ declaration }: { declaration: Declaration }) {
138138
{matches.map(({ gameId, gameName, status, module: otherModule }) => (
139139
<GameLink
140140
key={gameId}
141-
to={declarationPath(gameId, otherModule, declaration.name)}
141+
to={schemaPath(gameId, otherModule, declaration.name)}
142142
data-status={status === "identical" ? undefined : status}
143143
title={
144144
status === "identical"

src/components/schema/DeclarationsContext.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { createContext } from "react";
22
import { href } from "react-router";
33
import { Declaration, SchemaClass } from "../../data/types";
44
import { SchemaMetadata } from "../../data/schemas";
5-
import { GameId } from "../../games-list";
5+
import { DEFAULT_GAME, GameId } from "../../games-list";
66
import type { ReferenceEntry } from "../../data/derived";
77
export { declarationKey, type ReferenceEntry } from "../../data/derived";
88

9-
export function declarationPath(game: string, module: string, name: string): string {
10-
return href("/:game/:module?/:scope?", { game, module, scope: name });
9+
export function schemaPath(game: string, module?: string, scope?: string): string {
10+
return href("/:game?/:module?/:scope?", { game, module, scope });
1111
}
1212

1313
export type DeclarationsContextType = {
@@ -21,7 +21,7 @@ export type DeclarationsContextType = {
2121
};
2222

2323
export const DeclarationsContext = createContext<DeclarationsContextType>({
24-
game: "cs2",
24+
game: DEFAULT_GAME,
2525
declarations: [],
2626
classesByKey: new Map(),
2727
metadata: { revision: 0, versionDate: "", versionTime: "" },

src/components/schema/ReferencedBy.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useContext, useEffect, useState } from "react";
22
import { styled } from "@linaria/react";
3-
import { DeclarationsContext, declarationKey, declarationPath } from "./DeclarationsContext";
3+
import { DeclarationsContext, declarationKey, schemaPath } from "./DeclarationsContext";
44
import { KindIcon } from "../kind-icon/KindIcon";
55
import { SectionWrapper, SectionTitle, SectionList, SectionLink, SectionToggle } from "./styles";
66

@@ -32,7 +32,7 @@ export function ReferencedBy({ name, module }: { name: string; module: string })
3232
{visible.map((ref, i) => (
3333
<SectionLink
3434
key={`${ref.declarationModule}/${ref.declarationName}-${ref.fieldName ?? ""}-${i}`}
35-
to={declarationPath(game, ref.declarationModule, ref.declarationName)}
35+
to={schemaPath(game, ref.declarationModule, ref.declarationName)}
3636
title={`${ref.relation} in ${ref.declarationModule}`}
3737
>
3838
<KindIcon kind={ref.relation} size={18} />

src/components/schema/SchemaClass.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import React, { useContext, useMemo, useState } from "react";
2-
import { href } from "react-router";
32
import { Link } from "../Link";
43
import { styled } from "@linaria/react";
54
import * as api from "../../data/types";
65
import { SchemaTypeView, MetadataTags } from "./SchemaType";
76
import { ReferencedBy } from "./ReferencedBy";
87
import { CrossGameRefs } from "./CrossGameRefs";
98
import { KindIcon, ICONS_URL } from "../kind-icon/KindIcon";
10-
import { DeclarationsContext, declarationKey, declarationPath } from "./DeclarationsContext";
9+
import { DeclarationsContext, declarationKey, schemaPath } from "./DeclarationsContext";
1110
import { getGameDef } from "../../games-list";
1211
import { searchLink, useFieldParam } from "../../utils/filtering";
1312
import { formatHexOffset } from "../../utils/format";
@@ -70,7 +69,7 @@ const FieldOffset = styled(Link)`
7069
export const ModuleBadge: React.FC<{ module: string }> = ({ module }) => {
7170
const { game } = useContext(DeclarationsContext);
7271
return (
73-
<SectionLink to={href("/:game/:module?/:scope?", { game, module })}>
72+
<SectionLink to={schemaPath(game, module)}>
7473
<svg width="16" height="16" aria-hidden="true">
7574
<use href={`${ICONS_URL}#ki-module`} />
7675
</svg>
@@ -140,7 +139,7 @@ export const SchemaClassView: React.FC<{
140139
}, [declaration.parents, classesByKey, isSearchResult]);
141140

142141
const bitfieldInfo = useMemo(() => computeBitfieldInfo(declaration.fields), [declaration.fields]);
143-
const declPath = declarationPath(game, declaration.module, declaration.name);
142+
const declPath = schemaPath(game, declaration.module, declaration.name);
144143

145144
return (
146145
<CommonGroupWrapper>
@@ -197,7 +196,7 @@ function InheritedSection({
197196
{groups.toReversed().map((group) => (
198197
<SectionLink
199198
key={`inherited-${group.parent.module}/${group.parent.name}`}
200-
to={declarationPath(game, group.parent.module, group.parent.name)}
199+
to={schemaPath(game, group.parent.module, group.parent.name)}
201200
title={`class in ${group.parent.module}`}
202201
>
203202
<KindIcon kind="inherited-class" size="small" />

0 commit comments

Comments
 (0)