-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from Alt-Org/leo/feature/103-update-main-page…
…-to-have-an-intro-component Leo/feature/103 update main page to have an intro component
- Loading branch information
Showing
24 changed files
with
203 additions
and
58 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
frontend-next-migration/src/app/[lng]/(home)/_intro/Intro.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
frontend-next-migration/src/app/[lng]/(home)/_intro/Intro.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
90 changes: 90 additions & 0 deletions
90
frontend-next-migration/src/app/[lng]/(home)/_useScrollHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
</> | ||
) | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.