Skip to content

Commit f941517

Browse files
committed
refactor(constants, types): moved to proper files
1 parent 58680fd commit f941517

File tree

6 files changed

+54
-64
lines changed

6 files changed

+54
-64
lines changed

frontend/src/components/ServerInfoPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import LoadingBanner from "@site/src/components/LoadingBanner";
2-
import { API_ADDRESS } from "@site/src/constants";
32
import { ServerAllData } from "@site/src/types";
43
import Layout from "@theme/Layout";
54
import Translate from "@docusaurus/Translate";
65
import { useEffect, useState } from "react";
76
import { useParams } from "react-router-dom";
7+
import { API_SERVERS } from "@site/src/constants.ts";
88

9-
const API_SERVER = (ip: string) => `${API_ADDRESS}/servers/${ip}`;
9+
const API_SERVER = (ip: string) => `${API_SERVERS}${ip}`;
1010

1111
const getServer = async (ip: string): Promise<ServerAllData | undefined> => {
1212
try {

frontend/src/constants.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
11
export const API_ADDRESS = "https://api.open.mp";
2+
export const API_SERVERS = `${API_ADDRESS}/servers/`;
3+
4+
export const socials = [
5+
{
6+
alt: "Discord icon",
7+
src: "/images/assets/discord-icon.svg",
8+
href: "https://discord.com/invite/samp",
9+
size: 45,
10+
},
11+
{
12+
alt: "Facebook icon",
13+
src: "/images/assets/facebook.svg",
14+
href: "https://www.facebook.com/openmultiplayer",
15+
size: 33,
16+
},
17+
{
18+
alt: "Instagram icon",
19+
src: "/images/assets/instagram.svg",
20+
href: "https://instagram.com/openmultiplayer/",
21+
size: 33,
22+
},
23+
{
24+
alt: "Twitch icon",
25+
src: "/images/assets/twitch.svg",
26+
href: "https://twitch.tv/openmultiplayer",
27+
size: 29,
28+
},
29+
{
30+
alt: "X (formerly Twitter) icon",
31+
src: "/images/assets/x.svg",
32+
href: "https://x.com/openmultiplayer",
33+
size: 29,
34+
},
35+
{
36+
alt: "YouTube icon",
37+
src: "/images/assets/youtube.svg",
38+
href: "https://youtube.com/openmultiplayer",
39+
size: 35,
40+
},
41+
];

frontend/src/pages/index.tsx

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,9 @@ import React, { useState } from "react";
88

99
import Admonition from "../components/Admonition";
1010
import styles from "./index.module.css";
11-
11+
import { socials } from "../constants.ts";
1212
import Translate from '@docusaurus/Translate';
1313

14-
const socials = [
15-
{
16-
alt: "Discord icon",
17-
src: "/images/assets/discord-icon.svg",
18-
href: "https://discord.com/invite/samp",
19-
size: 45,
20-
},
21-
{
22-
alt: "Facebook icon",
23-
src: "/images/assets/facebook.svg",
24-
href: "https://www.facebook.com/openmultiplayer",
25-
size: 33,
26-
},
27-
{
28-
alt: "Instagram icon",
29-
src: "/images/assets/instagram.svg",
30-
href: "https://instagram.com/openmultiplayer/",
31-
size: 33,
32-
},
33-
{
34-
alt: "Twitch icon",
35-
src: "/images/assets/twitch.svg",
36-
href: "https://twitch.tv/openmultiplayer",
37-
size: 29,
38-
},
39-
{
40-
alt: "X (formerly Twitter) icon",
41-
src: "/images/assets/x.svg",
42-
href: "https://x.com/openmultiplayer",
43-
size: 29,
44-
},
45-
{
46-
alt: "YouTube icon",
47-
src: "/images/assets/youtube.svg",
48-
href: "https://youtube.com/openmultiplayer",
49-
size: 35,
50-
},
51-
];
52-
5314
const SocialIcons = () => {
5415
return (
5516
<div className={styles.socialLinks}>

frontend/src/pages/partners.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import { FixedSizeList } from "react-window";
55
import LoadingBanner from "../components/LoadingBanner";
66
import ServerRow from "../components/ServerRow";
77
import { ToastContainer } from "../components/Toast";
8-
import { API_ADDRESS } from "../constants";
9-
import { CoreServerData } from "../types";
10-
11-
const API_SERVERS = `${API_ADDRESS}/servers/`;
8+
import { API_SERVERS } from "../constants";
9+
import { CoreServerData, Stats, SortBy } from "../types";
1210

1311
import { renderToStaticMarkup } from "react-dom/server";
1412

@@ -28,18 +26,11 @@ const getServers = async () => {
2826
}
2927
};
3028

31-
type Stats = {
32-
players: number;
33-
servers: number;
34-
};
35-
3629
const getStats = (servers: CoreServerData[]): Stats => ({
3730
players: servers.map((s) => s.pc).reduce((acc, pc) => acc + pc, 0),
3831
servers: servers.length,
3932
});
4033

41-
type SortBy = "relevance" | "pc";
42-
4334
type Query = {
4435
search?: string;
4536
sort: SortBy;

frontend/src/pages/servers/index.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ import { FixedSizeList } from "react-window";
1111
import LoadingBanner from "../../components/LoadingBanner";
1212
import ServerRow from "../../components/ServerRow";
1313
import { showToast, ToastContainer } from "../../components/Toast";
14-
import { API_ADDRESS } from "../../constants";
15-
import { CoreServerData, ServerAllData } from "../../types";
14+
import { API_SERVERS } from "../../constants";
15+
import { CoreServerData, ServerAllData, SortBy, Stats } from "../../types";
1616
import ServerInfoPage from "../../components/ServerInfoPage";
1717

18-
const API_SERVERS = `${API_ADDRESS}/servers/`;
19-
2018
const getServers = async () => {
2119
try {
2220
const r: Response = await fetch(API_SERVERS);
@@ -27,18 +25,11 @@ const getServers = async () => {
2725
}
2826
};
2927

30-
type Stats = {
31-
players: number;
32-
servers: number;
33-
};
34-
3528
const getStats = (servers: CoreServerData[]): Stats => ({
3629
players: servers.map((s) => s.pc).reduce((acc, pc) => acc + pc, 0),
3730
servers: servers.length,
3831
});
3932

40-
type SortBy = "relevance" | "pc";
41-
4233
type Query = {
4334
search?: string;
4435
showEmpty: boolean;

frontend/src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ export interface ServerAllData {
2323
lastUpdated: string;
2424
lastActive?: string;
2525
}
26+
27+
export type Stats = {
28+
players: number;
29+
servers: number;
30+
};
31+
32+
export type SortBy = "relevance" | "pc";

0 commit comments

Comments
 (0)