Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leo/feature/103 update main page to have an intro component #138

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.intro{
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #111;
color: white;
text-align: center;
font-size: 24px;
//background: url('') no-repeat center center;
background-size: cover;
z-index: 1;
transition: opacity 0.5s ease, visibility 0.5s ease;

}
32 changes: 32 additions & 0 deletions frontend-next-migration/src/app/[lng]/(home)/_intro/Intro.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {forwardRef} from "react";
import {Button, ButtonTheme} from "@/shared/ui/Button";
import cls from "./Intro.module.scss";

type Props = {
scrollToContent: () => void;
};

const Intro = forwardRef<HTMLDivElement, Props>((props, ref) => {
const { scrollToContent } = props;
return (
<div ref={ref} className={cls.intro}>
<h1>
Welcome to our website!
</h1>
<p>
Scroll down to see more
</p>
<Button
onClick={scrollToContent}
theme={ButtonTheme.Graffiti}
withScalableLink
>
Scroll Down
</Button>
</div>
);
});

Intro.displayName = "IntroComponent";

export default Intro;
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { useEffect, useState } from 'react';

export const _useScrollHandler = (introRef: React.RefObject<HTMLDivElement>) => {
const [isScrollbarHidden, setIsScrollbarHidden] = useState(true);

const updateScrollbarVisibility = () => {
const isBelowIntro = window.scrollY > (introRef.current?.clientHeight || window.innerHeight);
setIsScrollbarHidden(!isBelowIntro);
};

const disableUserInteraction = () => {
document.body.style.pointerEvents = 'none';
document.body.style.userSelect = 'none';
document.body.style.overflow = 'hidden';
};

const enableUserInteraction = () => {
document.body.style.pointerEvents = '';
document.body.style.userSelect = '';
document.body.style.overflow = '';
};

const scrollToIntroOrContent = (lastScrollY: { value: number }) => {
const currentScrollY = window.scrollY;
const scrollDirection = currentScrollY > lastScrollY.value ? 'down' : 'up';
lastScrollY.value = currentScrollY;

if (introRef.current) {
const introBottom = introRef.current.clientHeight;

if (scrollDirection === 'up' && window.scrollY <= introBottom) {
disableUserInteraction();
setTimeout(() => {
window.scrollTo({
top: 0,
behavior: 'smooth',
});
setTimeout(() => {
enableUserInteraction();
}, 500);
}, 100);
}

if (scrollDirection === 'down' && window.scrollY < introBottom) {
disableUserInteraction();
setTimeout(() => {
window.scrollTo({
top: introBottom + 1,
behavior: 'smooth',
});
setTimeout(() => {
enableUserInteraction();
}, 500);
}, 100);
}
}
};

useEffect(() => {
window.scrollTo({
top: 0,
behavior: 'smooth',
});

let lastScrollY = { value: 0 };
const handleScroll = () => {
updateScrollbarVisibility();
scrollToIntroOrContent(lastScrollY);
};
window.addEventListener('scroll', handleScroll, { passive: true });
return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);

const scrollToContent = () => {
if (introRef.current) {
disableUserInteraction();
window.scrollTo({
top: introRef.current.clientHeight + 1,
behavior: 'smooth',
});
setTimeout(() => {
enableUserInteraction();
}, 500);
}
};

return { isScrollbarHidden, scrollToContent };
};
45 changes: 33 additions & 12 deletions frontend-next-migration/src/app/[lng]/(home)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
import {ReactNode} from "react";
import {Navbar} from "@/widgets/Navbar";
import {Footer} from "@/widgets/Footer";
import {ScrollTop} from "@/features/ScrollTop";
'use client'
import { ReactNode, useRef } from 'react';
import { Navbar } from '@/widgets/Navbar';
import { Footer } from '@/widgets/Footer';
import { ScrollTop } from '@/features/ScrollTop';
import Intro from './_intro/Intro';
import { _useScrollHandler } from './_useScrollHandler';


type Props = {
children: ReactNode;
}
};

export default function HomeLayout({ children }: Props) {
const introRef = useRef<HTMLDivElement>(null);
const { isScrollbarHidden, scrollToContent} = _useScrollHandler(introRef);

export default function HomeLayout({children}: Props) {
return (
<>
<Navbar overlaid />
{children}
<Footer />
<ScrollTop />
<Intro scrollToContent={scrollToContent} ref={introRef}/>
<>
<Navbar />
{children}
<Footer />
<ScrollTop />
</>
<style jsx global>{`
html {
scrollbar-width: ${isScrollbarHidden ? 'none' : 'auto'};
}
body {
-ms-overflow-style: ${isScrollbarHidden ? 'none' : 'auto'};
}
body::-webkit-scrollbar {
display: ${isScrollbarHidden ? 'none' : 'block'};
}
`}</style>
</>
)
}
);
}
2 changes: 1 addition & 1 deletion frontend-next-migration/src/app/[lng]/about/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = {
export default function AboutLayout({children}: Props) {
return (
<>
<Navbar overlaid />
<Navbar/>
{children}
<Footer />
</>
Expand Down
2 changes: 1 addition & 1 deletion frontend-next-migration/src/app/[lng]/comics/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = {
export default function ComicsLayout({children}: Props) {
return (
<>
<Navbar overlaid />
<Navbar />
{children}
<Footer />
</>
Expand Down
2 changes: 1 addition & 1 deletion frontend-next-migration/src/app/[lng]/coming/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Props = {
export default function ComingLayout({ children }: Props) {
return (
<>
<Navbar overlaid />
<Navbar/>
{children}
<FeedbackSideButton />
<HorizontalLines />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = {
export default function Layout({children}: Props) {
return (
<>
<Navbar overlaid />
<Navbar/>
{children}
<Footer />
<ScrollTop />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Props = {
export default function HeroDevelopmentLayout({ children }: Props) {
return (
<>
<Navbar overlaid />
<Navbar />
{children}
<FeedbackSideButton />
<HorizontalLines />
Expand Down
2 changes: 1 addition & 1 deletion frontend-next-migration/src/app/[lng]/heroes/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Props {
export default function Layout({ children}: Props) {
return (
<>
<Navbar overlaid={true} />
<Navbar/>
{children}
<HorizontalLines />
<Footer />
Expand Down
2 changes: 1 addition & 1 deletion frontend-next-migration/src/app/[lng]/news/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Props = {
export default function NewsLayout({ children }: Props) {
return (
<>
<Navbar overlaid />
<Navbar/>
{children}
<HorizontalLines />
<Footer />
Expand Down
2 changes: 1 addition & 1 deletion frontend-next-migration/src/app/[lng]/peli/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = {
export default function GameLayout({children}: Props) {
return (
<>
<Navbar overlaid/>
<Navbar/>
<div style={{paddingTop: "20px"}}></div>
{children}
<Footer/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = {
export default function PictureGalleriasLayout({children}: Props) {
return (
<>
<Navbar overlaid />
<Navbar />
{children}
<Footer />
</>
Expand Down
2 changes: 1 addition & 1 deletion frontend-next-migration/src/app/[lng]/privacy/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = {
export default function PrivacyLayout({ children }: Props) {
return (
<>
<Navbar overlaid navBarType={'Privacy'} />
<Navbar navBarType={'Privacy'} />
{children}
<Footer />
</>
Expand Down
2 changes: 1 addition & 1 deletion frontend-next-migration/src/app/[lng]/profile/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = {
export default function Layout({children}: Props) {
return (
<>
<Navbar overlaid />
<Navbar />
{children}
<Footer />
</>
Expand Down
2 changes: 1 addition & 1 deletion frontend-next-migration/src/app/[lng]/team/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = {
export default function TeamLayout({children}: Props) {
return (
<>
<Navbar overlaid />
<Navbar />
{children}
<ScrollTop />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const CookiesPage = (props: Props) => {

return (
<div className={classNames(cls.pageContainer)}>
<Navbar overlaid={true} navBarType={'Cookies'} />
{/*//todo mow to layout*/}
<Navbar navBarType={'Cookies'} />

<WikiContentWithSidebar sections={sections} />
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const GameArtPackagePage = (props: Props) => {

return (
<div className={classNames(cls.pageContainer, combinedModCss)}>
<Navbar overlaid={true} navBarType={'GameArt'} />
{/*//todo mow to layout*/}
<Navbar navBarType={'GameArt'} />
<WikiContentWithSidebar sections={sections} />
<div>
<FeedbackSideButton />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
font-weight: 500;
top: 0;
font-size: max(calc(20 * calc(min(750px, 100vw) / 750)), 12px);
}

.overlayed {
position: absolute;
margin-top: 5px;
position: relative;
}

.fixed {
position: fixed;
position: sticky;
}

.siteNavContentList {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { defineNs } from "../../model/defineNs";


type NavbarProps = {
overlaid?: boolean;
marginTop?: number;
className?: string;
navbarBuild: NavbarBuild
Expand All @@ -28,7 +27,6 @@ const NavbarDesktopV2 = (props: NavbarProps) => {

const {
navbarBuild,
overlaid = false,
marginTop,
className = '',
navBarType = "Default"
Expand All @@ -52,7 +50,6 @@ const NavbarDesktopV2 = (props: NavbarProps) => {
: {};

const mods: Record<string, boolean> = {
[cls.overlayed]: overlaid && !isFixed,
[cls.fixed]: isFixed,
} as Record<string, boolean>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import { getNavbarBuildByTypeAndSize } from '../../model/getNavbarBuildByTypeAnd
import useSizes from '@/shared/lib/hooks/useSizes';

interface NavbarMainProps {
overlaid?: boolean;
marginTop?: number;
className?: string;
navBarType?: NavBarType;
}

export const NavbarMain = memo((props: NavbarMainProps) => {
const { overlaid, marginTop, className, navBarType = 'Default' } = props;
const {marginTop, className, navBarType = 'Default' } = props;
const { isMobileSize, isTabletSize } = useSizes();
/* The line `const size = isMobileSize || isTabletSize ? 'mobile' : 'desktop';` is determining the
size of the navbar based on the screen size. */
Expand All @@ -29,15 +28,13 @@ export const NavbarMain = memo((props: NavbarMainProps) => {
<FixedProvider>
{isMobileSize || isTabletSize ? (
<NavbarMobileV2
overlaid={overlaid}
marginTop={marginTop}
className={className}
navbarBuild={navbarBuild}
navBarType={navBarType}
/>
) : (
<NavbarDesktopV2
overlaid={overlaid}
marginTop={marginTop}
className={className}
navbarBuild={navbarBuild}
Expand Down
Loading
Loading