Guest User

Untitled

a guest
Feb 22nd, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypeScript 5.66 KB | Source Code | 0 0
  1. 'use client'
  2. import Image from 'next/image'
  3. import './globals.css'
  4. import Logo from '../images/logo.png'
  5. import Burger1 from '../images/burger-1.png'
  6. import React, { useEffect } from 'react'
  7. import axios from 'axios'
  8. import Product from '@/components/product'
  9.  
  10. function sleep(ms: number) {
  11.   return new Promise(resolve=> setTimeout(resolve, ms))
  12. }
  13.  
  14. export default function Home() {
  15.   const [position, setPosition] = React.useState({one: '',two: '', opacitye: '100'})
  16.   const [position2, setPosition2] = React.useState(0)
  17.   const [products, setProducts] = React.useState<{ id: string; title: string; price: number; description: string; imageUri: string; }[]>([])
  18.  
  19.   const getProducts = async () => {
  20.     const request = axios.get('http://localhost:8080/api/products/get').then((request) => {
  21.       const data = request.data
  22.       setProducts(data.products)
  23.     }).catch(console.error)
  24.   }
  25.   getProducts()
  26.   const handlePosition = async (percentage: number) => {
  27.     setPosition({one: `translate-x-[-100%]`, two: '', opacitye: '0'});
  28.     await sleep(2000);
  29.     (document.getElementById('shop_modal') as HTMLDialogElement)?.showModal()
  30.   }
  31.   const closeModal = () => {
  32.     setPosition({one: 'left-0', two: '', opacitye: '100'});
  33.     (document.getElementById('cart_modal') as HTMLDialogElement)?.close();
  34.     (document.getElementById('shop_modal') as HTMLDialogElement)?.close()
  35.   }
  36.   const openCart = async () => {
  37.     setPosition({one: position.one, two: 'translate-x-[100%]', opacitye: position.opacitye})
  38.     await sleep(2000);
  39.     (document.getElementById('cart_modal') as HTMLDialogElement)?.showModal()
  40.   }
  41.   return (
  42.     <div className="flex justify-center items-center h-screen w-screen font-roboto">
  43.       <div className={`flex justify-center lg:justify-end items-center lg:items-end min-h-screen m-0 w-screen flex-row`}>
  44.         <div className={`w-7/12 left-0 lg:absolute p-24 transition duration-[2000ms] flex justify-center items-start min-h-screen flex flex-col bg-primary text-white ${position.one}`}>
  45.           <h1 className="text-5xl font-roboto-black">Bringing deliciousity to your doorstep.</h1>
  46.           <p className='mt-2 text-lg'>Order a burger now for an exclusive <span className='roboto-bold'>25% OFF</span>. Offer ends this Friday! Experience the delight of having a Big Belly Burger!</p>
  47.           <button onClick={()=>handlePosition(position2)} className='mt-8 p-3 bg-white text-primary font-roboto-black transition duration-500 hover:scale-110 hover:bg-secondary'>Order a Big Belly Burger!</button>
  48.         </div>
  49.         <div className={`w-5/12 lg:r-0 hidden lg:flex transition duration-[2000ms] justify-center items-center h-full bg-secondary min-h-screen ${position.two}`}>
  50.           <Image width={400} height={400} src={Logo} alt={'Logo'} className='transition duration-300 hover:rotate-[-25deg] hover:scale-110'></Image>
  51.         </div>
  52.       </div>
  53.       <dialog onClose={()=>closeModal()} id="cart_modal" className="modal modal-bottom sm:modal-middle bg-primaryLight lg:w-5/12 lg:bg-primary lg:absolute lg:right-0 bg-white">
  54.         <div className={`p-8 rounded bg-primary text-white rounded-t-3xl lg:rounded-none lg:w-full h-[calc(100vh-6rem)] overflow-y-auto r-0 absolute`}>
  55.           <h3 className="font-roboto-bold text-3xl text-center">Order a Big Cart Burger!</h3>
  56.           <p className="py-4 font-roboto text-center">Check our amazing menu and order the delicious burger you deserve.</p>
  57.           <div className='flex justify-center items-center p-4 px-0 flex-row flex-wrap'>
  58.             {products.map((product) => (
  59.                 <Product id={product.id} text={product.title} price={`${product.price}`}desc={product.description} imageUri={product.imageUri}/>
  60.               ))
  61.             }
  62.           </div>
  63.           <div className="modal-action">
  64.             <form method="dialog">
  65.               <button className="btn bg-primary text-white border-none text-black transition duration-500 hover:bg-primary hover:scale-110 rounded-none" onClick={closeModal}>Close</button>
  66.             </form>
  67.               <button className="btn bg-white text-primary border-none text-black transition duration-500 hover:bg-secondary hover:text-black hover:scale-110 rounded-none ml-4" onClick={openCart}>Continue To Cart</button>
  68.           </div>
  69.         </div>
  70.       </dialog>
  71.       <dialog onClose={()=>closeModal()} id="shop_modal" className="modal modal-bottom sm:modal-middle bg-primaryLight  lg:w-7/12 lg:bg-primary">
  72.         <div className={`p-8 rounded bg-primary text-white rounded-t-3xl lg:rounded-none lg:w-full h-[calc(100vh-6rem)] overflow-y-auto`}>
  73.           <h3 className="font-roboto-bold text-3xl text-center">Order a Big Belly Burger!</h3>
  74.           <p className="py-4 font-roboto text-center">Check our amazing menu and order the delicious burger you deserve.</p>
  75.           <div className='flex justify-center items-center p-4 px-0 flex-row flex-wrap'>
  76.             {products.map((product) => (
  77.                 <Product id={product.id} text={product.title} price={`${product.price}`}desc={product.description} imageUri={product.imageUri}/>
  78.               ))
  79.             }
  80.           </div>
  81.           <div className="modal-action">
  82.             <form method="dialog">
  83.               <button className="btn bg-primary text-white border-none text-black transition duration-500 hover:bg-primary hover:scale-110 rounded-none" onClick={closeModal}>Close</button>
  84.             </form>
  85.               <button className="btn bg-white text-primary border-none text-black transition duration-500 hover:bg-secondary hover:text-black hover:scale-110 rounded-none ml-4" onClick={openCart}>Continue To Cart</button>
  86.           </div>
  87.         </div>
  88.       </dialog>
  89.     </div>
  90.   );
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment