-
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 #14 from raipen/feat/main-page
Feat: main page
- Loading branch information
Showing
13 changed files
with
296 additions
and
66 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,22 @@ import { styled } from 'styled-components'; | |
|
||
const FooterContainer = styled.footer` | ||
background-color: #f8f9fa; | ||
padding: 20px; | ||
margin-top: auto; | ||
text-align: center; | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
height: 80px; | ||
`; | ||
|
||
function Footer() { | ||
return ( | ||
<FooterContainer> | ||
© 2024. <a href="https://github.com/raipen" target="_blank" style={{color:"#8e8bf9",fontWeight:"600"}}>Raipen</a> all rights reserved. | ||
<br/> | ||
<i>contact: [email protected]</i> | ||
<div> | ||
© 2024. <a href="https://github.com/raipen" target="_blank" style={{color:"#8e8bf9",fontWeight:"600"}}>Raipen</a> all rights reserved. | ||
<br/> | ||
<i>contact: [email protected]</i> | ||
</div> | ||
</FooterContainer> | ||
); | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useEffect, useState, useCallback, useMemo } from 'react'; | ||
|
||
function useMainPage<T>(pageList: Array<T>) { | ||
const [page, setPage] = useState(0); | ||
const [isScrolling, setIsScrolling] = useState(false); | ||
|
||
const pageUp = useCallback(() => { | ||
if (page < pageList.length - 1) setPage(page + 1); | ||
}, [page]); | ||
|
||
const pageDown = useCallback(() => { | ||
if (page > 0) setPage(page - 1); | ||
}, [page]); | ||
|
||
const pageControl = useCallback((type: 'up' | 'down') => { | ||
if (isScrolling) return; | ||
setIsScrolling(true); | ||
if (type === 'up') pageUp(); | ||
else pageDown(); | ||
setTimeout(() => { | ||
setIsScrolling(false); | ||
}, 1000); | ||
}, [isScrolling, pageUp, pageDown]); | ||
|
||
const wheelEvent = useCallback((e: WheelEvent) => { | ||
if(page === pageList.length - 1 && e.deltaY > 0 && !isScrolling) return; | ||
e.preventDefault(); | ||
if (e.deltaY > 0) return pageControl('up'); | ||
pageControl('down'); | ||
}, [pageControl]); | ||
|
||
const touchEvent = useCallback(() => { | ||
let startY = 0; | ||
const touchStart = (e: TouchEvent) => { | ||
startY = e.touches[0].clientY; | ||
} | ||
const touchEnd = (e: TouchEvent) => { | ||
const endY = e.changedTouches[0].clientY; | ||
if(startY === 0) return; | ||
if (startY - endY > 50) return pageControl('up'); | ||
if (startY - endY < -50) return pageControl('down'); | ||
} | ||
return { touchStart, touchEnd }; | ||
}, [pageControl]); | ||
|
||
const touchMove = useCallback((e: TouchEvent) => { | ||
if(page === pageList.length - 1 && !isScrolling) return; | ||
if(page === 0 && !isScrolling) return; | ||
e.preventDefault(); | ||
}, [isScrolling, page]); | ||
|
||
useEffect(() => { | ||
window.addEventListener('wheel', wheelEvent, { passive: false }); | ||
const { touchStart, touchEnd } = touchEvent(); | ||
window.addEventListener('touchstart', touchStart); | ||
window.addEventListener('touchend', touchEnd); | ||
window.addEventListener('touchmove', touchMove, { passive: false }); | ||
return () => { | ||
window.removeEventListener('wheel', wheelEvent); | ||
window.removeEventListener('touchstart', touchStart); | ||
window.removeEventListener('touchend', touchEnd); | ||
window.removeEventListener('touchmove', touchMove); | ||
}; | ||
}, [wheelEvent, touchEvent]); | ||
|
||
useEffect(()=> { | ||
scrollTo(0,0); | ||
}, [page]); | ||
|
||
return useMemo(()=>({page,info:pageList[page], pageUp}), [page, pageList, pageUp]); | ||
} | ||
|
||
export default useMainPage; |
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,54 @@ | ||
import { HomeContainer,NewPageLink, ScrollBottom,ImageContainer, ButtonContainingIcon } from '@components'; | ||
import useMainPage from '@hooks/useMainPage'; | ||
import { pageList, ContentsType } from '@utils/homeList'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
function Home() { | ||
const {page,info,pageUp} = useMainPage(pageList); | ||
|
||
const a = ( | ||
<> | ||
<h2>{info.title}</h2> | ||
{info.contents.map((content, index) => { | ||
switch(content.type) { | ||
case ContentsType.LINK: | ||
return ( | ||
<Link to={content.src!} key={index} target="_blank" style={{width:"fit-content"}}> | ||
<NewPageLink text={content.text}/> | ||
</Link> | ||
); | ||
case ContentsType.TEXT: | ||
return <p key={index} style={{whiteSpace:"pre-line"}}>{content.text}</p>; | ||
case ContentsType.IMAGE: | ||
return <ImageContainer key={index} src={content.src} alt="main" style={{maxWidth: "600px"}}/>; | ||
case ContentsType.BUTTON: | ||
return ( | ||
<Link to={content.link!} key={index} style={{width:"100%", maxWidth:"350px"}}> | ||
<ButtonContainingIcon style={{width:"100%", padding:"10px", fontSize:"1.5rem"}}> | ||
{content.text} | ||
</ButtonContainingIcon> | ||
</Link> | ||
); | ||
} | ||
})} | ||
{page!==pageList.length -1 && <ScrollBottom onClick={pageUp} className="material-icons-sharp"> | ||
keyboard_double_arrow_down | ||
</ScrollBottom>} | ||
</> | ||
) | ||
|
||
if(page%2 === 0) return ( | ||
<HomeContainer $background={info.background}> | ||
<input type="hidden" value="home"/> | ||
{a} | ||
</HomeContainer> | ||
); | ||
|
||
return ( | ||
<HomeContainer $background={info.background}> | ||
{a} | ||
</HomeContainer> | ||
); | ||
} | ||
|
||
export default Home; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.