Skip to content

Commit

Permalink
add pagination for internship page (fixes #164) (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
PSS2134 authored May 19, 2024
2 parents 3f2bc4c + a646277 commit f767cff
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 72 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.0.1",
"react-paginate": "^8.2.0",
"react-redux": "^9.1.0",
"react-responsive-carousel": "^3.2.23",
"react-router-dom": "^6.22.0",
Expand Down
80 changes: 31 additions & 49 deletions src/Componet/Documetation/Internship/InternPage.jsx
Original file line number Diff line number Diff line change
@@ -1,76 +1,58 @@
/** @format */

import './internpage.css';
import DataDB from '../../../DB/DataBase.json'
import { useRef } from 'react';
let InternPage = () => {
// Dispatch and Subscribe
const button=document.querySelectorAll('viewMore');
const ref=useRef(null);

//
// function handleClick(){

// // console.log(ref.current.className + ' ' +"MoreDetails");
// // console.log(ref.current)
// let see=ref.current.parentElement.classList.toggle('MoreDetails');
// // console.log(see)
// // btn.parentElement.classList.toggle
// // see.classList.toggle('MoreDetails');

import { useRef, useState } from 'react';
import PaginatedItems from '../../pagination';

// }
// for(let btn in button){
// btn.parentElement.classList.toggle('MoreDetails');
// }


let InternPage = () => {
// Dispatch and Subscribe
const button = document.querySelectorAll('viewMore');
const ref = useRef(null);




const [currentData, setCurrentData] = useState([])
const [pageSummary, setPageSummary] = useState("")
// console.log(currentData)

return (

<div style={{ background: 'black' }}>

<p className='page-summary'>{pageSummary}</p>


<div className='internBox'>

{currentData.map((item, index) => {
return (

<div style={{background:'black'}}>

<div className='internBox'>


{DataDB.map((item,index)=>{
return(

<div className="BoxContent">
<div className="BoxContent" key={index}>
<img className='ApiImg' key={index} src={item.image} alt="" />
<h2 className='InternTitle' ref={ref}>{item.internship_name}</h2>
<div className="time">
<div className="mode">{item.mode}</div>
<div className="duration">{item.duration}</div>
</div>
<p className='desc'>{item.description}</p>
{/* ----------write logic for this */}
{/* <div className="fullBox">
<h2 className='InternTitle' ref={ref}>{item.internship_name}</h2>
<div className="time">
<div className="mode">{item.mode}</div>
<div className="duration">{item.duration}</div>
</div>
<p className='desc'>{item.description}</p>
{/* ----------write logic for this */}
{/* <div className="fullBox">
<h5 className='company_name'>{item.company_name}</h5>
<h5 className='Stipend'>{item.award}</h5>
<h5 className='internship_type'>{item.internship_type}</h5>
<button className='ApplyButton'>Apply Now ✅</button>
</div> */}

<button className='viewMore' id='btn' style={{cursor:'pointer'}} ref={ref} onClick={()=>{window.open(item.link)}} >Apply Now</button>
<button className='viewMore' id='btn' style={{ cursor: 'pointer' }} ref={ref} onClick={() => { window.open(item.link) }} >Apply Now</button>

</div>
)

)
})}

</div>

</div>
</div>

<PaginatedItems setCurrentData={setCurrentData} setPageSummary={setPageSummary}/>

</div>
);
};

Expand Down
5 changes: 5 additions & 0 deletions src/Componet/Documetation/Internship/internpage.css
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ font-weight:500;
}
}

.page-summary {
color: blueviolet;
padding: 15px 10%;
}

/* @mediaQwery */


Expand Down
46 changes: 23 additions & 23 deletions src/Componet/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ function Home() {
<div>
<div className="page_0">
<div className="bx-1">
<h2>Elevate
<h2>Elevate
<br /> Your
<br/>
<br />
Future</h2>
<h4>
<i>Land your dream career.....</i> </h4>
<Button className='check-now'>
<Link to="/intern" className='link1'>

Check Now
Check Now
</Link>
</Button>
</Button>
</div>
<div className="bx-2">
<img className="home-img img-1" src={code} alt="img" />
Expand All @@ -70,18 +70,18 @@ function Home() {
</div>
<div className="wrapper-bx-2">
<div className="wrapper-bx-2-0 wrapper-bx-2-1 outline">
<i className='icon' style={{color:'blueviolet'}}>
<GiWorld />
<i className='icon' style={{ color: 'blueviolet' }}>
<GiWorld />
</i>
<div className="wrapper-subbx">
<h3>World's Biggest</h3>
<p>The World's biggest collection of internships.</p>
</div>
</div>
{/* </div> */}
{/* </div> */}
<div className="wrapper-bx-2-0 wrapper-bx-2-2 outline">
<i className='icon' style={{color:'blueviolet'}}>
<GiGlobe />
<i className='icon' style={{ color: 'blueviolet' }}>
<GiGlobe />
</i>
<div className="wrapper-subbx">
<h3>Around the Globe</h3>
Expand All @@ -92,7 +92,7 @@ function Home() {
</div>
</div>
<div className="wrapper-bx-2-0 wrapper-bx-2-3 outline">
<i className='icon' style={{color:'blueviolet'}}>
<i className='icon' style={{ color: 'blueviolet' }}>
<FaPeopleGroup />
</i>
<div className="wrapper-subbx">
Expand All @@ -101,7 +101,7 @@ function Home() {
</div>
</div>
<div className=" wrapper-bx-2-0 wrapper-bx-2-4 outline">
<i className='icon' style={{color:'blueviolet'}}>
<i className='icon' style={{ color: 'blueviolet' }}>
<FaIndianRupeeSign />
</i>
<div className="wrapper-subbx">
Expand All @@ -113,19 +113,19 @@ function Home() {
</div>
</div>
<section>
<div className="desktopImg">
<img className='img img1' src={img1} alt="is" />
<img className='img img2' src={img2} alt="is" />
<img className='img img3' src={img7} alt="is" />
<img className='img img4' src={img6} alt="is" />
<img className='img img5' src={img8} alt="is" />
<img className='img img6' src={img5} alt="is" />
<img className='img img7' src={img9} alt="is" />
<img className='img img8' src={img4} alt="is" />
</div>
<div className="desktopImg">
<img className='img img1' src={img1} alt="is" />
<img className='img img2' src={img2} alt="is" />
<img className='img img3' src={img7} alt="is" />
<img className='img img4' src={img6} alt="is" />
<img className='img img5' src={img8} alt="is" />
<img className='img img6' src={img5} alt="is" />
<img className='img img7' src={img9} alt="is" />
<img className='img img8' src={img4} alt="is" />
</div>


</section>
</section>
{/* <div className="page_2 footer">
<div className="footer-wrapper">
<div className="flex">
Expand Down Expand Up @@ -160,7 +160,7 @@ function Home() {
</button>
</div>
</div> */}
</div>
</div>
);
}

Expand Down
56 changes: 56 additions & 0 deletions src/Componet/pagination.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.pagination-wrapper {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
margin-top:35px;
}
.pagination-container {
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
gap: 10px;
box-shadow: 0 0 10px blueviolet;
border: 2px solid blueviolet;
padding: 10px 20px;
border-radius: 30px;
}
.page-btn {
list-style-type: none;
}
.page-btn-link {
padding: 10px;
display: inline-block;
height: 35px;
width: 35px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
transition: 0.5s;
color: blueviolet;
}
.page-btn-link:not(.active):hover {
background-color: rgb(222, 186, 255);
}
.active {
background-color: blueviolet;
color: white;
font-weight: 600;
border-radius: 50%;
}
.prev, .next {
width: max-content;
border-radius: 5px;
}
.disabled{
pointer-events: none;
opacity: 0.5;
}
.break {
color: blueviolet;
pointer-events: none;
border: none;
font-weight: 600;
}
60 changes: 60 additions & 0 deletions src/Componet/pagination.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { useEffect, useState } from 'react';
import ReactPaginate from 'react-paginate';
import './pagination.css'
import DataDB from '../DB/DataBase.json'

function PaginatedItems({ setCurrentData, setPageSummary }) {
const itemsPerPage = 12;

const pageCount = Math.ceil(DataDB.length / itemsPerPage);

const handlePageClick = (event) => {
const newOffset = (event.selected * itemsPerPage) % DataDB.length;
const endOffset = newOffset + itemsPerPage > DataDB.length ? DataDB.length : newOffset + itemsPerPage;

setCurrentData(DataDB.slice(newOffset, endOffset))
setPageSummary(`Showing ${newOffset+1} to ${endOffset} results out of ${DataDB.length}`)

window.scroll(0, 0);
};

useEffect(() => {
const pageBtns = document.querySelectorAll(".page-btn");
console.log(pageBtns[1])
handlePageClick({selected: 0})
pageBtns[1].classList.add("active");
}, [])

return (
<>
<div className="pagination-wrapper">
<ReactPaginate
breakLabel="..."
nextLabel="| Next"
onPageChange={handlePageClick}
pageRangeDisplayed={3}
marginPagesDisplayed={2}
pageCount={pageCount}
previousLabel="Prev |"
renderOnZeroPageCount={null}
activeClassName="page-btn"
activeLinkClassName='active'
containerClassName='pagination-container'
pageClassName='page-btn'
pageLinkClassName='page-btn-link'
previousClassName='page-btn'
previousLinkClassName='prev page-btn-link'
nextClassName='page-btn'
nextLinkClassName='next page-btn-link'
disabledClassName='page-btn'
disabledLinkClassName='disabled page-btn-link'
breakClassName='page-btn'
breakLinkClassName='break page-btn-link'
/>
</div>
</>
);
}


export default PaginatedItems;

0 comments on commit f767cff

Please sign in to comment.