Skip to content

Commit

Permalink
[web] Update to nextra 3 #1364 (#1373)
Browse files Browse the repository at this point in the history
* web - update to nextra 3

* web - update to nextra 3

* web - fix unit tests

* web - fix format

* web - fix api docs
  • Loading branch information
janavlachova authored Dec 7, 2024
1 parent 95cd2ba commit 6c31811
Show file tree
Hide file tree
Showing 86 changed files with 2,917 additions and 4,471 deletions.
2 changes: 1 addition & 1 deletion agdb_web/components/pages/openapi/openapi.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const jsonMock = {
paths: {},
};

vi.mock("next/router", () => ({
vi.mock("nextra/hooks", () => ({
useRouter: () => ({
pathname: "/",
locale: "en-US",
Expand Down
10 changes: 5 additions & 5 deletions agdb_web/hooks/i18n.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ const { useRounterMock, messagesEnMock } = vi.hoisted(() => {
messagesEnMock: vi.fn(),
};
});
vi.mock("next/router", () => ({
vi.mock("nextra/hooks", () => ({
useRouter: useRounterMock,
}));

vi.mock("nextra/constants", () => ({
DEFAULT_LOCALE: "en-US",
}));

vi.mock("@/messages/cs-CZ.json", () => ({
test: "testCZ",
}));
Expand All @@ -40,6 +36,7 @@ describe("i18n", () => {
messagesEnMock.mockRejectedValue(new Error("error"));
useRounterMock.mockReturnValue({
locale: "",
defaultLocale: "en-US",
});
const { result } = renderHook(() => useI18n());
await waitFor(() => {
Expand All @@ -51,6 +48,7 @@ describe("i18n", () => {
messagesEnMock.mockResolvedValue(messagesEN);
useRounterMock.mockReturnValue({
locale: "",
defaultLocale: "en-US",
});
const { result } = renderHook(() => useI18n());
await waitFor(() => {
Expand All @@ -61,6 +59,7 @@ describe("i18n", () => {
it("should return the default locale", async () => {
useRounterMock.mockReturnValue({
locale: "cs-CZ",
defaultLocale: "en-US",
});

const { result } = renderHook(() => useI18n());
Expand All @@ -70,6 +69,7 @@ describe("i18n", () => {
it("should return a translation", async () => {
useRounterMock.mockReturnValue({
locale: "cs-CZ",
defaultLocale: "en-US",
});
const { result } = renderHook(() => useI18n());

Expand Down
11 changes: 2 additions & 9 deletions agdb_web/hooks/i18n.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useRouter } from "next/router";
import { useRouter } from "nextra/hooks";
import { useEffect, useState } from "react";
import { DEFAULT_LOCALE } from "nextra/constants";

type MessagesStructure = { [key: string]: string | MessagesStructure };

Expand All @@ -19,19 +18,13 @@ const iterateMessages = (
}
};

export const getDefaultLocale = (): string => {
return DEFAULT_LOCALE;
};

export const useI18n = () => {
const { locale } = useRouter();
const { locale, defaultLocale } = useRouter();
const [fallbackMessages, setFallbackMessages] = useState(
new Map<string, string>(),
);
const [messages, setMessages] = useState(new Map<string, string>());

const defaultLocale = getDefaultLocale();

const processFallbackMessages = (data: MessagesStructure): void => {
const messages = new Map<string, string>();
iterateMessages(null, data, messages);
Expand Down
6 changes: 5 additions & 1 deletion agdb_web/middleware.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { locales as middleware } from "nextra/locales";
export { middleware } from "nextra/locales";

export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico|images|manifest).*)"],
};
Loading

0 comments on commit 6c31811

Please sign in to comment.