Skip to content

Commit

Permalink
Merge pull request #448 from Eldemarkki/small-improvements
Browse files Browse the repository at this point in the history
Small improvements
  • Loading branch information
Eldemarkki authored Dec 23, 2023
2 parents 76ffe30 + 6ae7943 commit 13f1f3d
Show file tree
Hide file tree
Showing 59 changed files with 729 additions and 494 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
}
},
"root": true,
"plugins": ["@typescript-eslint"]
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/switch-exhaustiveness-check": "error"
}
}
22 changes: 10 additions & 12 deletions .storybook/withSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const InnerApp = ({ children }: PropsWithChildren) => {
return (
<MantineProvider
theme={{
fontFamily: "Ubuntu, sans-serif",
fontFamily: "var(--font-ubuntu), sans-serif",
white: "#eee",
black: "#121212",
colors: {
Expand Down Expand Up @@ -57,7 +57,7 @@ const InnerApp = ({ children }: PropsWithChildren) => {
],
},
headings: {
fontFamily: "Poppins, sans-serif",
fontFamily: "var(--font-poppins), sans-serif",
fontWeight: "800",
sizes: {
h1: { fontSize: "1.9rem" },
Expand All @@ -79,15 +79,13 @@ const InnerApp = ({ children }: PropsWithChildren) => {

export const withSetup: Decorator = (Story) => {
return (
<div id="root">
<I18nextProvider i18n={i18n}>
<InnerApp>
<ModalsProvider>
<Notifications />
<Story />
</ModalsProvider>
</InnerApp>
</I18nextProvider>
</div>
<I18nextProvider i18n={i18n}>
<InnerApp>
<ModalsProvider>
<Notifications />
<Story />
</ModalsProvider>
</InnerApp>
</I18nextProvider>
);
};
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@mantine/notifications": "^7.3.2",
"@radix-ui/react-icons": "^1.3.0",
"chart.js": "^4.4.1",
"date-fns": "^3.0.1",
"date-fns": "^3.0.6",
"formik": "^2.4.5",
"i18next": "^23.7.11",
"i18next-resources-to-backend": "^1.2.0",
Expand All @@ -22,7 +22,7 @@
"react-cookie": "^6.1.1",
"react-dom": "^18.2.0",
"react-feather": "^2.0.10",
"react-i18next": "^13.5.0",
"react-i18next": "^14.0.0",
"yup": "^1.3.3"
},
"scripts": {
Expand All @@ -49,7 +49,7 @@
"@typescript-eslint/parser": "^6.15.0",
"eslint-config-next": "^14.0.4",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.0",
"eslint-plugin-prettier": "^5.1.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-storybook": "^0.6.15",
"prettier": "^3.1.1",
Expand Down
Binary file removed public/fonts/poppins-v19-latin-800.woff
Binary file not shown.
Binary file removed public/fonts/poppins-v19-latin-800.woff2
Binary file not shown.
Binary file removed public/fonts/ubuntu-v19-latin-regular.woff
Binary file not shown.
Binary file removed public/fonts/ubuntu-v19-latin-regular.woff2
Binary file not shown.
11 changes: 11 additions & 0 deletions public/images/testausserveri.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
"title": "Editing {{projectName}}"
},
"error": "Error",
"errors": {
"unauthorized": "You are not logged in or your session has expired. Please log in and try again."
},
"extensions": {
"body": "Download the Testaustime extension for your favorite code editor!",
"intellij": "Download Testaustime for IntelliJ",
Expand Down
3 changes: 3 additions & 0 deletions public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
"title": "Muokataan {{projectName}}"
},
"error": "Virhe",
"errors": {
"unauthorized": "Et ole kirjautunut sisään tai sinun istuntosi on vanhentunut. Kirjaudu sisään, ja yritä uudelleen."
},
"extensions": {
"body": "Lataa Testaustime-laajennus suosikkieditorillesi!",
"intellij": "Lataa Testaustime IntelliJ:lle",
Expand Down
51 changes: 21 additions & 30 deletions src/api/leaderboardApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import {
Leaderboard,
LeaderboardData,
} from "../types";
import { revalidateTag } from "next/cache";
import { redirect } from "next/navigation";

export const getMyLeaderboards = async (username: string) => {
export const getMyLeaderboards = async () => {
const token = cookies().get("token")?.value;
if (!token) {
return GetLeaderboardsError.Unauthorized;
return { error: GetLeaderboardsError.Unauthorized };
}

try {
Expand All @@ -27,38 +25,35 @@ export const getMyLeaderboards = async (username: string) => {
"bypass-token": process.env.RATELIMIT_IP_FORWARD_SECRET ?? "",
},
cache: "no-cache",
next: {
tags: [`leaderboards-${username}`],
},
},
);

if (!response.ok) {
if (response.status === 401) {
return GetLeaderboardsError.Unauthorized;
return { error: GetLeaderboardsError.Unauthorized };
} else if (response.status === 429) {
return GetLeaderboardsError.TooManyRequests;
return { error: GetLeaderboardsError.RateLimited };
}

const errorText = await response.text();
console.log(errorText);
console.log("Unknown error when getting user's leaderboards:", errorText);

return GetLeaderboardsError.UnknownError;
return { error: GetLeaderboardsError.UnknownError };
}

const data = (await response.json()) as Leaderboard[];

return data;
} catch (e: unknown) {
console.error(e);
return GetLeaderboardsError.UnknownError;
console.error("Unknown error when getting user's leaderboards:", e);
return { error: GetLeaderboardsError.UnknownError };
}
};

export const getLeaderboard = async (leaderboardName: string) => {
const token = cookies().get("token")?.value;
if (!token) {
redirect("/login");
return { error: GetLeaderboardError.Unauthorized };
}

const response = await fetch(
Expand All @@ -78,26 +73,23 @@ export const getLeaderboard = async (leaderboardName: string) => {

if (!response.ok) {
if (response.status === 401) {
return GetLeaderboardError.Unauthorized;
return { error: GetLeaderboardError.Unauthorized };
} else if (response.status === 429) {
return GetLeaderboardError.TooManyRequests;
return { error: GetLeaderboardError.RateLimited };
}

const errorText = await response.text();
console.log(errorText);

return GetLeaderboardError.UnknownError;
return { error: GetLeaderboardError.UnknownError };
}

const data = (await response.json()) as LeaderboardData;

return data;
};

export const createLeaderboard = async (
leaderboardName: string,
username: string,
) => {
export const createLeaderboard = async (leaderboardName: string) => {
const token = cookies().get("token")?.value;
const response = await fetch(
process.env.NEXT_PUBLIC_API_URL + "/leaderboards/create",
Expand All @@ -114,19 +106,18 @@ export const createLeaderboard = async (
},
);

if (response.status === 409) {
return CreateLeaderboardError.AlreadyExists;
}

if (!response.ok) {
console.log(await response.text());
return CreateLeaderboardError.UnknownError;
if (response.status === 409) {
return { error: CreateLeaderboardError.AlreadyExists };
} else if (response.status === 429) {
return { error: CreateLeaderboardError.RateLimited };
}

console.error("Error while creating leaderboard:", await response.text());
return { error: CreateLeaderboardError.UnknownError };
}

const data = (await response.json()) as { invite_code: string };

// TODO: username is provided by user, we should not trust it
revalidateTag(`leaderboards-${username}`);

return data;
};
3 changes: 1 addition & 2 deletions src/api/usersApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { redirect } from "next/navigation";
import {
ActivityDataSummary,
ApiUsersUserActivityDataResponseItem,
Expand All @@ -11,7 +10,7 @@ import { CurrentActivity } from "../components/CurrentActivity/CurrentActivity";
export const getMe = async () => {
const token = cookies().get("token")?.value;
if (!token) {
redirect("/login");
return undefined;
}

const meResponse = await fetch(
Expand Down
7 changes: 7 additions & 0 deletions src/app/[locale]/Content.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.container {
display: flex;
justify-content: center;
flex-direction: row;
flex-wrap: wrap;
min-height: 100vh;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import { ModalsProvider } from "@mantine/modals";
import { Notifications } from "@mantine/notifications";
import { SettingsContext } from "../../../contexts/SettingsContext";
import { MantineColorScheme } from "@mantine/core";
import { useCreateSettings } from "../../../hooks/useSettings";
import { SettingsContext } from "../../contexts/SettingsContext";
import { MantineColorScheme, useMantineColorScheme } from "@mantine/core";
import { useCreateSettings } from "../../hooks/useSettings";
import { useHotkeys } from "@mantine/hooks";
import { CookiesProvider } from "react-cookie";
import styles from "./Content.module.css";

export const Content = ({
children,
Expand All @@ -15,6 +16,7 @@ export const Content = ({
children: React.ReactNode;
colorScheme: MantineColorScheme;
}) => {
const mantineColorScheme = useMantineColorScheme();
const settings = useCreateSettings({
initialColorScheme: colorScheme,
});
Expand All @@ -24,6 +26,7 @@ export const Content = ({
"mod+J",
() => {
settings.toggleColorScheme();
mantineColorScheme.toggleColorScheme();
},
],
]);
Expand All @@ -32,7 +35,7 @@ export const Content = ({
<>
<Notifications />
<ModalsProvider>
<div id="root">
<div className={styles.container}>
<CookiesProvider>
<SettingsContext.Provider value={settings}>
{children}
Expand Down
Loading

2 comments on commit 13f1f3d

@vercel
Copy link

@vercel vercel bot commented on 13f1f3d Dec 23, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 13f1f3d Dec 23, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

testaustime – ./

testaustime.vercel.app
testaustime-git-main-testaustime.vercel.app
testaustime-testaustime.vercel.app

Please sign in to comment.