Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ const {

const nextConfig = {
output: "standalone",
i18n: {
locales: ["default", "en", "it"],
defaultLocale: "default",
localeDetection: false,
},
trailingSlash: false,
cacheHandler:
process.env.VERCEL_ENV === "preview"
Expand Down
35 changes: 3 additions & 32 deletions frontend/src/components/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ import { NavBar } from "@python-italia/pycon-styleguide";
import type { Action } from "@python-italia/pycon-styleguide/dist/navbar/types";
import React, { useEffect, useState } from "react";

import { useRouter } from "next/router";

import { useLoginState } from "~/components/profile/hooks";
import { getTranslatedMessage } from "~/helpers/use-translated-message";
import { useCurrentLanguage } from "~/locale/context";
import { useHeaderQuery } from "~/types";

import { createHref } from "../link";
import { Logo, MobileLogo } from "../logo";

export const Header = () => {
Expand All @@ -21,25 +18,14 @@ export const Header = () => {
code: process.env.conferenceCode!,
},
});
const { route, query } = useRouter();

useEffect(() => {
setIsReady(true);
}, []);

const {
conference: {
conferenceMenuEn,
programMenuEn,
conferenceMenuIt,
programMenuIt,
isRunning,
currentDay,
},
conference: { conferenceMenuEn, programMenuEn, isRunning },
} = data || { conference: {} };
// const hasSomethingLive = currentDay?.rooms?.some(
// (room) => !!room.streamingUrl,
// );

const actions: Action[] = [
isRunning
Expand All @@ -65,19 +51,8 @@ export const Header = () => {
},
];

const conferenceMenu =
language === "it" ? conferenceMenuIt : conferenceMenuEn;
const programMenu = language === "it" ? programMenuIt : programMenuEn;

const mainLinks = conferenceMenu?.links ?? [];
const secondaryLinks = programMenu?.links ?? [];

const languageSwitchHref = createHref({
path: route,
params: query,
locale: language === "it" ? "en" : "it",
external: false,
});
const mainLinks = conferenceMenuEn?.links ?? [];
const secondaryLinks = programMenuEn?.links ?? [];

return (
<header>
Expand All @@ -87,10 +62,6 @@ export const Header = () => {
actions={actions}
logo={Logo}
mobileLogo={MobileLogo}
bottomBarLink={{
text: getTranslatedMessage("header.switchLanguage", language),
link: languageSwitchHref,
}}
/>
</header>
);
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/components/link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import type { ParsedUrlQuery } from "querystring";
export const createHref = ({
path,
params,
locale,
external,
}: {
path: string;
params?: ParsedUrlQuery;
locale: string;
locale?: string;
external?: boolean;
}) => {
if (external) {
Expand Down Expand Up @@ -37,7 +36,5 @@ export const createHref = ({
.map(([key, value]) => `${key}=${value}`)
.join("&");

return `/${locale}${resolvedPath}${
queryParams.length > 0 ? `?${queryParams}` : ""
}`;
return `${resolvedPath}${queryParams.length > 0 ? `?${queryParams}` : ""}`;
};
14 changes: 5 additions & 9 deletions frontend/src/components/meta-tags/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ type Props = {
useDefaultSocialCard?: boolean;
};

const getSocialCardURL = (
asPath: string,
useDefaultSocialCard: boolean,
locale: string,
) => {
const getSocialCardURL = (asPath: string, useDefaultSocialCard: boolean) => {
if (useDefaultSocialCard) {
return `${process.env.NEXT_PUBLIC_SITE_URL}api/${locale}/social-card`;
return `${process.env.NEXT_PUBLIC_SITE_URL}api/social-card`;
}

return `${process.env.NEXT_PUBLIC_SITE_URL}api/${locale}/${asPath.substring(
return `${process.env.NEXT_PUBLIC_SITE_URL}api/${asPath.substring(
1,
)}/social-card`;
};
Expand All @@ -33,8 +29,8 @@ export const MetaTags = ({
children,
}: React.PropsWithChildren<Props>) => {
const language = useCurrentLanguage();
const { asPath, locale } = useRouter();
const socialCard = getSocialCardURL(asPath, useDefaultSocialCard, locale);
const { asPath } = useRouter();
const socialCard = getSocialCardURL(asPath, useDefaultSocialCard);

const titleTemplate = messages[language].titleTemplate;

Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/page-handler/page-static-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { GetStaticProps } from "next";
import { addApolloState, getApolloClient } from "~/apollo/client";
import { blocksDataFetching } from "~/components/blocks-renderer";
import { prefetchSharedQueries } from "~/helpers/prefetch";
import { DEFAULT_LOCALE } from "~/locale/languages";
import {
type PagePreviewQuery,
type PageQuery,
Expand Down
21 changes: 3 additions & 18 deletions frontend/src/locale/context.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
import React from "react";

import cookies from "next-cookies";
import { useRouter } from "next/router";

import type { Language } from "~/locale/languages";
import { DEFAULT_LOCALE, type Language } from "~/locale/languages";

export const LocaleProvider = ({
children,
}: React.PropsWithChildren<{ lang: string }>) => {
const language = useCurrentLanguage();

React.useEffect(() => {
const { pyconLocale } = cookies({
req: { headers: { cookie: document.cookie } },
});
if (language !== pyconLocale) {
document.cookie = `pyconLocale=${language}; path=/`;
}
}, [language]);

return <>{children}</>;
};

export const useCurrentLanguage = () => {
const { locale } = useRouter();
return locale as Language;
export const useCurrentLanguage = (): Language => {
return DEFAULT_LOCALE;
};
Loading
Loading