generated from ngyngcphu/react-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(HomePage): limit the use of HTML in React
- Loading branch information
Showing
17 changed files
with
180 additions
and
166 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
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -1,61 +1,32 @@ | ||
import { useState } from 'react'; | ||
import { FC } from 'react'; | ||
import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/24/outline'; | ||
import { Carousel } from '@material-tailwind/react'; | ||
import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/react/24/outline'; | ||
|
||
interface Slide { | ||
src: string; | ||
alt: string; | ||
} | ||
interface SlidesProps { | ||
children: Slide[]; | ||
} | ||
export const Slides: FC<SlidesProps> = ({ children }) => { | ||
const [slide, setSlide] = useState(0); | ||
const slideLength = children.length; | ||
const handleleftArrow = () => { | ||
const previousSlide = slide === 0 ? slideLength - 1 : slide - 1; | ||
setSlide(previousSlide); | ||
}; | ||
const handleRightArrow = () => { | ||
const nextSlide = slide === slideLength - 1 ? 0 : slide + 1; | ||
setSlide(nextSlide); | ||
}; | ||
setTimeout(handleRightArrow, 3000); | ||
export const Slides: Component<{ slides: SlideData[] }> = ({ slides }) => { | ||
return ( | ||
<div className='relative mb-4 w-full lg:mb-12'> | ||
<div className='absolute top-[40%] left-[5%] p-[5px] rounded-[999px] bg-white opacity-40 cursor-pointer hover:opacity-100'> | ||
<ArrowLeftIcon className='w-4' onClick={handleleftArrow} /> | ||
</div> | ||
{children.map((child, index) => { | ||
return ( | ||
<img | ||
src={child.src} | ||
alt={child.alt} | ||
key={index} | ||
className={ | ||
slide === index ? 'rounded-lg h-[200px] object-cover w-full lg:h-[400px]' : 'hidden' | ||
} | ||
/> | ||
); | ||
})} | ||
<div className='absolute top-[40%] right-[5%] p-[5px] rounded-[999px] bg-white opacity-40 cursor-pointer hover:opacity-100'> | ||
<ArrowRightIcon className='w-4 ' onClick={handleRightArrow} /> | ||
</div> | ||
<span className='flex absolute bottom-[1rem] left-[40%] lg:left-[50%]'> | ||
{children.map((_, idx) => { | ||
return ( | ||
<button | ||
key={idx} | ||
onClick={() => setSlide(idx)} | ||
className={ | ||
slide === idx | ||
? 'bg-white h-[0.5rem] w-[0.5rem] rounded-full border-0 outline-0 my-0 mx-[0.2rem] cursor-pointer' | ||
: 'h-[0.5rem] w-[0.5rem] rounded-full border-0 outline-0 my-0 mx-[0.2rem] cursor-pointer bg-[#9CA3AF]' | ||
} | ||
></button> | ||
); | ||
})} | ||
</span> | ||
</div> | ||
<Carousel | ||
className='rounded-lg' | ||
prevArrow={({ handlePrev }) => ( | ||
<div className='absolute top-[40%] left-[5%] p-[5px] rounded-full bg-white opacity-40 cursor-pointer hover:opacity-100'> | ||
<ChevronLeftIcon strokeWidth={4} className='w-5 h-5' onClick={handlePrev} /> | ||
</div> | ||
)} | ||
nextArrow={({ handleNext }) => ( | ||
<div className='absolute top-[40%] right-[5%] p-[5px] rounded-full bg-white opacity-40 cursor-pointer hover:opacity-100'> | ||
<ChevronRightIcon strokeWidth={4} className='w-5 h-5' onClick={handleNext} /> | ||
</div> | ||
)} | ||
loop={true} | ||
autoplay={true} | ||
autoplayDelay={3000} | ||
> | ||
{slides.map((slide, index) => ( | ||
<img | ||
key={index} | ||
src={slide.src} | ||
alt={slide.alt} | ||
className='h-[200px] object-cover w-full lg:h-[400px]' | ||
/> | ||
))} | ||
</Carousel> | ||
); | ||
}; |
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,6 @@ | ||
export const ORDER_STATUS = { | ||
progressing: 'amber', | ||
ready: 'green', | ||
done: 'indigo', | ||
canceled: 'red' | ||
}; |
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 was deleted.
Oops, something went wrong.
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,57 +1,39 @@ | ||
import { useEffect } from 'react'; | ||
import { ArrowRightIcon, PrinterIcon } from '@heroicons/react/24/outline'; | ||
import { Orders, Slides } from '@components/home'; | ||
import printerPicture from '@assets/printer.jpg'; | ||
import { ArrowRightIcon } from '@heroicons/react/24/outline'; | ||
import axios from 'axios'; | ||
import { useEffect, useState } from 'react'; | ||
import { useOrderStore, useSlideStore } from '@states/home'; | ||
|
||
export function HomePage() { | ||
const [orders, setOrders] = useState([]); | ||
const { orderData, getOrderData } = useOrderStore(); | ||
const { slideData, getSlideData } = useSlideStore(); | ||
|
||
useEffect(() => { | ||
const getOrders = async () => { | ||
try { | ||
const result = await axios.get('http://localhost:3002/orders'); | ||
setOrders(result.data); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}; | ||
getOrders(); | ||
}, []); | ||
const slidePictures = [ | ||
{ | ||
src: 'https://e-learning.hcmut.edu.vn/theme/boost/images/slbktv.jpg?1695219022292', | ||
alt: 'slide1' | ||
}, | ||
{ | ||
src: 'https://e-learning.hcmut.edu.vn/theme/boost/images/slbk.jpg?1695219022805', | ||
alt: 'slide2' | ||
}, | ||
{ | ||
src: 'https://static.tuoitre.vn/tto/i/s626/2016/04/05/dai-hoc-bach-khoa-tp-hcm-cong-bo-phuong-an-tuyen-sinh-2015jpg-1459820200.jpg', | ||
alt: 'slide3' | ||
}, | ||
{ | ||
src: 'https://we25.vn/media2018/Img_News/2020/06/08/khuon-vien-dh-bach-khoa-tp-hcm-khien-dan-tinh-me-man-voi-nhung-hanh-cay-xanh-tham-toa-bong-mat-quanh-nam-14_20200608150159.jpg', | ||
alt: 'slide4' | ||
} | ||
]; | ||
getOrderData(); | ||
getSlideData(); | ||
}, [getOrderData, getSlideData]); | ||
|
||
return ( | ||
<div className='p-6 lg:py-5 lg:px-56'> | ||
<div className='mb-4 lg:mb-6'> | ||
<h4 className='text-[#1488D8] text-base lg:text-2xl'> | ||
<h4 className='font-normal text-blue/1 text-base lg:text-2xl'> | ||
Student Smart Printing Service (SSPS) | ||
</h4> | ||
<h3 className='text-[#030391] text-xl lg:text-4xl font-bold'>Welcome Username!</h3> | ||
<h3 className='font-bold text-blue/2 text-xl lg:text-4xl'>Welcome Username!</h3> | ||
</div> | ||
<div className='mb-4 lg:mb-12'> | ||
<Slides slides={slideData} /> | ||
</div> | ||
<Slides children={slidePictures} /> | ||
<div className='flex p-4 bg-[#1488D8] rounded-lg items-center mb-16 lg:mb-24 lg:h-[120px] lg:px-6 relative'> | ||
<div className='p-[10px] rounded-full bg-white mr-4'> | ||
<img src={printerPicture} /> | ||
<div className='flex items-center justify-between bg-blue/1 rounded-lg p-4 mb-16 lg:mb-24 lg:h-[120px] lg:px-6'> | ||
<div className='flex items-center gap-4'> | ||
<PrinterIcon | ||
strokeWidth={2} | ||
className='bg-white text-blue-500 rounded-full w-10 h-10 p-2 lg:w-12 lg:h-12 lg:p-3' | ||
/> | ||
<span className='text-white font-bold lg:text-2xl'>Order printing</span> | ||
</div> | ||
<span className='text-white font-bold lg:text-2xl'>Order printing</span> | ||
<ArrowRightIcon className='w-4 text-white absolute top-50 right-[24px] lg:w-6' /> | ||
<ArrowRightIcon strokeWidth={3} className='text-white w-4 h-4 lg:w-6 lg:h-6' /> | ||
</div> | ||
<Orders orders={orders} /> | ||
<Orders orders={orderData} /> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
*/ | ||
|
||
export * from './order'; | ||
export * from './slide'; |
Oops, something went wrong.