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

Updated with changes from original code base, fully migrated to react-router-dom-v5-compat #358

Closed
wants to merge 8 commits into from
92 changes: 25 additions & 67 deletions packages/web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import { Layout } from "antd";
import "./App.css";
import { Switch } from "react-router-dom";
import routes from "./routes";
import { CommanderDetails } from "./pages/commanders/commanderDetails";
import { CommandersList } from "./pages/commanders/commandersList";
Expand All @@ -26,7 +25,7 @@ import UserProfile from "./pages/profile";
import RecentMatches from "./pages/recent-matches/recent-matches";
import Regions from "./pages/about/regions";
import PlayersPage from "./pages/players";
import { CompatRoute, CompatRouter } from "react-router-dom-v5-compat";
import { Routes, Route, CompatRouter } from "react-router-dom-v5-compat";

const { Content } = Layout;

Expand All @@ -38,71 +37,30 @@ const App: React.FC = () => {
<Content>
<ErrorBoundary>
<CompatRouter>
<Switch>
<CompatRoute path={"/"} exact={true}>
<MainHome />
</CompatRoute>
<CompatRoute path={routes.fullStatsOldDetails()}>
<OldStats />
</CompatRoute>
<CompatRoute path={routes.mapStats()}>
<MapStats />
</CompatRoute>
<CompatRoute path={routes.statsBase()}>
<CustomStats />
</CompatRoute>
<CompatRoute path={routes.playerCardWithId()}>
<PlayerCard />
</CompatRoute>
<CompatRoute path={routes.playerCardBase()}>
<PlayersPage />
</CompatRoute>
<CompatRoute path={routes.leaderboardsBase()}>
<Leaderboards />
</CompatRoute>
<CompatRoute path={routes.commanderByID()}>
<CommanderDetails />
</CompatRoute>
<CompatRoute path={routes.commanderList()}>
<CommandersList />
</CompatRoute>
<CompatRoute path={routes.commanderBase()}>
<RacePicker />
</CompatRoute>
<CompatRoute path={routes.desktopAppBase()}>
<DesktopApp />
</CompatRoute>
<CompatRoute path={routes.liveMatchesBase()}>
<LiveMatches />
</CompatRoute>
<CompatRoute path={routes.regionsBase()}>
<Regions />
</CompatRoute>
<CompatRoute path={routes.aboutBase()}>
<About />
</CompatRoute>
<CompatRoute path={routes.bulletinsBase()}>
<BulletinList />
</CompatRoute>
<CompatRoute path={routes.searchWithParam()}>
<CustomSearch />
</CompatRoute>
<CompatRoute path={routes.searchBase()}>
<CustomSearch />
</CompatRoute>
<CompatRoute path={routes.singleMatch()}>
<SingleMatch />
</CompatRoute>
<CompatRoute path={routes.recentMatchesBase()}>
<RecentMatches />
</CompatRoute>
<CompatRoute path="/userProfile">
<UserProfile />
</CompatRoute>
<CompatRoute path="*">
<NotFound />
</CompatRoute>
</Switch>
<Routes>
<Route path={"/"} element={<MainHome />} />
<Route path={routes.fullStatsOldDetails()} element={<OldStats />} />
<Route path={routes.mapStats()} element={<MapStats />} />
<Route path={routes.statsBase()} element={<CustomStats />} />
{/* <Route path={routes.playerCardWithIdAndName()} element={<PlayerCard />} /> */}
<Route path={routes.playerCardWithId()} element={<PlayerCard />} />
<Route path={routes.playerCardBase()} element={<PlayersPage />} />
<Route path={routes.leaderboardsBase()} element={<Leaderboards />} />
<Route path={routes.commanderByID()} element={<CommanderDetails />} />
<Route path={routes.commanderList()} element={<CommandersList />} />
<Route path={routes.commanderBase()} element={<RacePicker />} />
<Route path={routes.desktopAppBase()} element={<DesktopApp />} />
<Route path={routes.liveMatchesBase()} element={<LiveMatches />} />
<Route path={routes.regionsBase()} element={<Regions />} />
<Route path={routes.aboutBase()} element={<About />} />
<Route path={routes.bulletinsBase()} element={<BulletinList />} />
<Route path={routes.searchWithParam()} element={<CustomSearch />} />
<Route path={routes.searchBase()} element={<CustomSearch />} />
<Route path={routes.singleMatch()} element={<SingleMatch />} />
<Route path={routes.recentMatchesBase()} element={<RecentMatches />} />
<Route path="/userProfile" element={<UserProfile />} />
<Route path="*" element={<NotFound />} />
</Routes>
</CompatRouter>
</ErrorBoundary>
</Content>
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/main-footer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { Footer } from "antd/es/layout/layout";
import { Divider, Typography } from "antd";
import { Link as RouterLink } from "react-router-dom";
import { Link as RouterLink } from "react-router-dom-v5-compat";
import config from "../config";
import { RegionSelector } from "./region-selector";
import { Helper } from "./helper";
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/main-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
mostRecentGamesAppBase,
regionsBase,
} from "../titles";
import { Link } from "react-router-dom";
import { Link } from "react-router-dom-v5-compat"; //yet to convert to v5
import { doc, getFirestore, onSnapshot } from "firebase/firestore";
import { ItemType } from "antd/lib/menu/hooks/useItems";

Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/main-home.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";
import { Card, Col, Row, Space, Typography } from "antd";
import Meta from "antd/es/card/Meta";
import { Link } from "react-router-dom";
import { Link } from "react-router-dom-v5-compat";
import routes from "../routes";
import { commanderAndBulletinDate, lastPatchName } from "../config";
import { doc, getFirestore, getDoc } from "firebase/firestore";
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/bulletins/bulletinList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ColumnsType } from "antd/es/table";
import { ExportDate } from "../../components/export-date";
import firebaseAnalytics from "../../analytics";
import { Tip } from "../../components/tip";
import { Link } from "react-router-dom";
import { Link } from "react-router-dom-v5-compat";
import routes from "../../routes";
import { ChangeEvent } from "react";
import { useHistory } from "react-router";
Expand Down
10 changes: 6 additions & 4 deletions packages/web/src/pages/commanders/commandersList.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { useEffect } from "react";
import { Col, Row, List, Avatar, Typography } from "antd";
import { getCommanderByRaces, getCommanderIconPath } from "../../coh/commanders";
import { useParams } from "react-router";
// import { useParams } from "react-router";
import { useParams } from "react-router-dom-v5-compat";
import { RaceName } from "../../coh/types";
import routes from "../../routes";
import { ExportDate } from "../../components/export-date";
import { commanderBase } from "../../titles";
import { capitalize } from "../../utils/helpers";
import { Link } from "react-router-dom";
// import { capitalize } from "../../utils/helpers";
import { Link } from "react-router-dom-v5-compat";
import { Tip } from "../../components/tip";
import { CommanderAbilitiesComponent } from "../../components/commander-abillities-component";

Expand All @@ -19,7 +20,8 @@ export const CommandersList = () => {
}>();

useEffect(() => {
document.title = `${commanderBase} - ${capitalize(race)}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had issues with the capitalize during the migration. If the original line is kept, I would face this error.
Screenshot 2024-10-19 at 4 45 50 PM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, you can fix this by passing there empty string like this ${capitalize(race || "")}

// document.title = `${commanderBase} - ${capitalize(race)}`;
document.title = `${commanderBase} - ${race}`;
}, [race]);

let myData = getCommanderByRaces(race as RaceName);
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/commanders/racePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { Col, Row } from "antd";

import routes from "../../routes";
import { Link } from "react-router-dom";
import { Link } from "react-router-dom-v5-compat";
import { Tip } from "../../components/tip";
import { getGeneralIconPath } from "../../coh/helpers";

Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/ladders/leaderboards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Typography,
Switch,
} from "antd";
import { Link } from "react-router-dom";
import { Link } from "react-router-dom-v5-compat";
import { useHistory } from "react-router";

import { LaddersDataArrayObject, LaddersDataObject } from "../../coh/types";
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/live-matches/live-matches-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
raceIds,
} from "../../utils/table-functions";
import { convertSteamNameToID, getGeneralIconPath } from "../../coh/helpers";
import { Link } from "react-router-dom";
import { Link } from "react-router-dom-v5-compat";
import routes from "../../routes";
import { ColumnsType } from "antd/es/table";
import { ConfigContext } from "../../config-context";
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/map-stats/map-stats-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect } from "react";
import { Row, Card, Radio, RadioChangeEvent, Space, Typography, Tooltip, Select } from "antd";
import { MapBarChart } from "../../components/charts/maps-bar";
import { mapStatsBase } from "../../titles";
import { useLocation } from "react-router-dom";
import { useLocation } from "react-router-dom-v5-compat";
import { FactionVsFactionCard } from "../../components/factions";
import { useMediaQuery } from "react-responsive";
import { MapsWinRateChart } from "../../components/charts/map-stats/maps-winrate-bar";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
import { Typography } from "antd";
import { Loading } from "../../components/loading";
import { StatsDataObject, validStatsTypes } from "../../coh/types";
import { useLocation } from "react-router-dom";
import { useLocation } from "react-router-dom-v5-compat";
import firebaseAnalytics from "../../analytics";
import MapStatsDetails from "./map-stats-details";
import { doc, getDoc, getFirestore } from "firebase/firestore";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { firebase } from "../../firebase";
import { Loading } from "../../components/loading";

import { validStatsTypes } from "../../coh/types";
import { useLocation } from "react-router-dom";
import { useLocation } from "react-router-dom-v5-compat";
import MapStatsDetails from "./map-stats-details";

const { Title } = Typography;
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/matches/all-matches-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
raceIds,
} from "../../utils/table-functions";
import { convertSteamNameToID, getGeneralIconPath } from "../../coh/helpers";
import { Link } from "react-router-dom";
import { Link } from "react-router-dom-v5-compat";
import routes from "../../routes";
import { useMediaQuery } from "react-responsive";
import { BulbOutlined, DatabaseOutlined, PlusCircleOutlined } from "@ant-design/icons";
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/matches/last-matches-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
getPlayerMapListFilter,
} from "../../utils/table-functions";
import "./tableStyle.css";
import { Link } from "react-router-dom";
import { Link } from "react-router-dom-v5-compat";
import routes from "../../routes";
import { convertSteamNameToID, getGeneralIconPath } from "../../coh/helpers";
import { BulbOutlined, DatabaseOutlined } from "@ant-design/icons";
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/matches/match-details-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import firebaseAnalytics from "../../analytics";
import { getBulletinData, getBulletinIconPath } from "../../coh/bulletins";
import { getCommanderData, getCommanderIconPath } from "../../coh/commanders";
import { CommanderAbility } from "../../coh/types";
import { Link as RouterLink } from "react-router-dom";
import { Link as RouterLink } from "react-router-dom-v5-compat";
import { BulbOutlined } from "@ant-design/icons";

const { Text } = Typography;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { LaddersDataArrayObject, PlayerCardDataArrayObject } from "../../../coh/
import { CountryFlag } from "../../../components/country-flag";
import { Switch, Table, Tooltip, Typography } from "antd";
import { convertSteamNameToID, levelToText } from "../../../coh/helpers";
import { Link } from "react-router-dom";
import { Link } from "react-router-dom-v5-compat";
import routes from "../../../routes";
import { convertTeamNames, formatTimeAgo, latestDate, percentageFormat } from "./helpers";
import { Helper } from "../../../components/helper";
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/players/stats/player-stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Row } from "antd/es";
import { Helper } from "../../../components/helper";
import { Loading } from "../../../components/loading";
import { AlertBox } from "../../../components/alert-box";
import { Link } from "react-router-dom";
import { Link } from "react-router-dom-v5-compat";
import routes from "../../../routes";
import firebaseAnalytics from "../../../analytics";

Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/recent-matches/recent-matches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
raceIds,
} from "../../utils/table-functions";
import { convertSteamNameToID, getGeneralIconPath } from "../../coh/helpers";
import { Link } from "react-router-dom";
import { Link } from "react-router-dom-v5-compat";
import routes from "../../routes";
import { getMapIconPath } from "../../coh/maps";
import { AlertBox } from "../../components/alert-box";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
import { Typography } from "antd";
import { Loading } from "../../components/loading";
import { StatsDataObject, statTypesInDbAsType, validStatsTypes } from "../../coh/types";
import { useLocation } from "react-router-dom";
import { useLocation } from "react-router-dom-v5-compat";
import CustomStatsDetails from "./custom-stats-details";
import firebaseAnalytics from "../../analytics";
import GeneralStats from "./general-stats";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TypeAnalysisObject,
validStatsTypes,
} from "../../coh/types";
import { useLocation } from "react-router-dom";
import { useLocation } from "react-router-dom-v5-compat";
import CustomStatsDetails from "./custom-stats-details";
import { StatsHeader } from "./stats-header";
import GeneralStats from "./general-stats";
Expand Down
13 changes: 6 additions & 7 deletions packages/web/src/pages/stats/old-stats.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { useEffect } from "react";
import { Redirect, Switch } from "react-router-dom";
import { useHistory, useParams } from "react-router";
import routes from "../../routes";
import { getPreviousWeekTimeStamp, useQuery } from "../../utils/helpers";
import { CompatRoute } from "react-router-dom-v5-compat";
import { Link, Routes, Route } from "react-router-dom-v5-compat";

/**
* This is old stats format, it's used for redirect from the old links
Expand Down Expand Up @@ -39,13 +38,13 @@ const OldStats: React.FC = () => {
}, []);

return (
<Switch>
<CompatRoute path={"/stats/"}>
<Redirect
<Routes>
<Route path={"/stats/"}>
<Link
to={routes.fullStatsOldDetails("week", getPreviousWeekTimeStamp(), "4v4", "wermacht")}
/>
</CompatRoute>
</Switch>
</Route>
</Routes>
);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLocation } from "react-router-dom";
import { useLocation } from "react-router-dom-v5-compat";
import { eachDayOfInterval, format } from "date-fns";

import TimeAgo from "javascript-time-ago";
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/utils/table-functions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import firebaseAnalytics from "../analytics";
import { MatchPlayerDetailsTable } from "../pages/matches/match-details-table";
import { SimplePieChart } from "../components/charts-match/simple-pie";
import MatchDetails from "../pages/matches/match-details";
import { Link } from "react-router-dom";
import { Link } from "react-router-dom-v5-compat";
import routes from "../routes";
import { DatabaseOutlined } from "@ant-design/icons";
import { RelicIcon } from "../components/relic-icon";
Expand Down