Skip to content

Commit

Permalink
fix(gatsby): header, nav, logo, layout page interne
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoirelacoste authored and JalilArfaoui committed Nov 11, 2021
1 parent c94f4ea commit 59e3ca5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/app/website/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ const Layout = ({
useChangeLanguage(path);
const [switchLanguage] = useSwitchLanguage();
const { footer, header } = useGetMenus(i18n.language as SupportedLanguage);
const eng = new RegExp(/\/en/);
const eng = new RegExp(/^\/en\/$|^\/en$/);
const isHome = path === '/' || eng.test(path);
return (
<ThemeProvider theme={theme}>
<Seo title={pageContext.title || 'DisMoi'} />
<Header
scrolled={scrolled || !isHome}
isHome={isHome}
scrolled={scrolled}
links={header}
switchLanguage={switchLanguage}
/>
Expand Down
4 changes: 4 additions & 0 deletions src/app/website/src/contents/en/about.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ label: "About us"
name: "about"
locale: "en"
---
import Page from "../../pages/{mdx.slug}";

<Page/>

[À TRADUIRE !!!]

Expand Down Expand Up @@ -119,3 +122,4 @@ Basée à Bordeaux, d’où sont originaires les deux frères co-fondateurs de D
## VII. Nous contacter

C'est [par là](https://www.dismoi.op/contact).

3 changes: 2 additions & 1 deletion src/app/website/src/hooks/useSwitchLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import i18n from '../../../../libs/i18n';

const useSwitchLanguage = (): [() => void] => {
const newLocale = i18n.language === 'fr' ? 'en' : 'fr';
const newSlug = newLocale === 'fr' ? '/' : '/en';
const newSlug = newLocale === 'fr' ? '/' : '/en/';
console.log(newLocale, newSlug, '---------');

const switchLanguage = () =>
i18n.changeLanguage(newLocale).then(() => navigate(newSlug));
Expand Down
32 changes: 23 additions & 9 deletions src/components/website/molecules/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,52 @@ export interface HeaderProps {
scrolled?: Scrolled;
links: Link[];
switchLanguage: () => void;
isHome: boolean;
}

const Header = styled(
({ className, scrolled, links, switchLanguage }: HeaderProps) => {
const [offset, setOffset] = useState(0);
({ className, scrolled, links, switchLanguage, isHome }: HeaderProps) => {
const [scrolledClass, setScolledClass] = useState('');
const [opacity, setOpacity] = useState(0);
const [modalOpen, setModalOpen] = React.useState<boolean>(false);

useEffect(() => {
window.onload = () => {
setOffset(window.pageYOffset);
setOpacity(100);
const setMoove = () => {
console.log(1);
if (scrolled || !isHome || window.pageYOffset > 0)
return setScolledClass('scrolled');
console.log(
2,
isHome,
window.pageYOffset <= 0,
isHome && window.pageYOffset <= 0
);
if (isHome && window.pageYOffset <= 0) return setScolledClass('');
console.log(3);
return setScolledClass('scrolled');
};
setMoove();
window.onscroll = () => {
setOffset(window.pageYOffset);
setMoove();
};
}, []);

const isScrolled = scrolled || offset > 0;
return (
<>
<header className={className + (isScrolled ? ' scrolled' : '')}>
<header className={className + ' ' + scrolledClass} style={{ opacity }}>
<a className="homeLink" href={'/'}>
<LogoDisMoi />
</a>
<NavDesktop>
<ListLinks links={links} />
{isScrolled && <HeaderCTAButton />}
{!!scrolledClass && <HeaderCTAButton />}
<NavDesktopItem onClick={switchLanguage}>
<span title="French">fr</span> | <span title="English">en</span>
</NavDesktopItem>
</NavDesktop>
<MobileButtonsWrapper>
{isScrolled && <HeaderCTAButton />}
{!!scrolledClass && <HeaderCTAButton />}
<ToggleMenu handleClick={() => setModalOpen(true)} />
</MobileButtonsWrapper>
</header>
Expand Down

0 comments on commit 59e3ca5

Please sign in to comment.