Skip to content

Commit 28d7a89

Browse files
author
osama bin junaid
committed
Initial commit
0 parents  commit 28d7a89

23 files changed

+2830
-0
lines changed

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
.pnpm-debug.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TODO:
2+
3+
- Deployment tutorial will go here

components/navbar.component.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Image from 'next/image'
2+
3+
type NavBarProps = {
4+
filterFunc: any
5+
}
6+
7+
export default function NavBar(props: NavBarProps) {
8+
return (
9+
<>
10+
<p className='text-right text-xs'>with 💗 from <a href="https://linkedin.com/in/ibnjunaid">@ibnjunaid</a></p>
11+
<div className="navbar bg-base-100 ">
12+
<div className="flex-1">
13+
<Image src="/GDSC.png" width={400} height={50}
14+
alt="Shoes" className="rounded-xl bg-green-200 p-2"
15+
/>
16+
</div>
17+
<div className="flex-1">
18+
<h1>GCCP Leader Board</h1>
19+
</div>
20+
<div className="flex-none gap-2">
21+
<div className="form-control">
22+
<input type="text" placeholder="Search" className="input input-bordered"
23+
onChange={props.filterFunc} />
24+
</div>
25+
</div>
26+
</div>
27+
</>
28+
)
29+
}

components/table.components.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as react from 'react'
2+
import { useState } from 'react';
3+
4+
type TableProp = {
5+
headers: string[];
6+
data: string[][]
7+
}
8+
9+
export default function Table(props: TableProp) {
10+
return (
11+
12+
<>
13+
<div className="overflow-x-auto">
14+
<table className="table w-full">
15+
{/* <!-- head --> */}
16+
<thead>
17+
<tr>
18+
<th>Serial</th>
19+
{
20+
props.headers.map((header, index) => <th key={index}>{header}</th>)
21+
}
22+
</tr>
23+
</thead>
24+
<tbody>
25+
{
26+
props.data.map((entry, i) => {
27+
return <tr key={i}>
28+
<th>{i}</th>
29+
{
30+
entry.map((val, j) => <th key={j}>{val}</th>)
31+
}
32+
</tr>
33+
})
34+
}
35+
</tbody>
36+
</table>
37+
</div>
38+
</>
39+
)
40+
}

next.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
reactStrictMode: true,
4+
swcMinify: true,
5+
}
6+
7+
module.exports = nextConfig

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "gccp",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"build": "next build",
8+
"start": "next start",
9+
"lint": "next lint"
10+
},
11+
"dependencies": {
12+
"@types/node": "18.11.9",
13+
"@types/react": "18.0.25",
14+
"@types/react-dom": "18.0.9",
15+
"colors": "^1.4.0",
16+
"daisyui": "^2.40.1",
17+
"eslint": "8.27.0",
18+
"eslint-config-next": "13.0.3",
19+
"google-auth-library": "^8.7.0",
20+
"googleapis": "^109.0.1",
21+
"next": "13.0.3",
22+
"react": "18.2.0",
23+
"react-dom": "18.2.0",
24+
"typescript": "4.8.4"
25+
},
26+
"devDependencies": {
27+
"autoprefixer": "^10.4.13",
28+
"postcss": "^8.4.19",
29+
"tailwindcss": "^3.2.4"
30+
}
31+
}

pages/_app.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import '../styles/globals.css'
2+
import type { AppProps } from 'next/app'
3+
4+
export default function App({ Component, pageProps }: AppProps) {
5+
return <Component {...pageProps} />
6+
}

pages/api/hello.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2+
import type { NextApiRequest, NextApiResponse } from 'next'
3+
import { getSheetId } from '../../utils/db';
4+
import { getDataFromSheet, getSheetTitles } from '../../utils/sheets'
5+
import { filterSensitiveData } from '../../utils/utils'
6+
7+
type Data = {
8+
headers: string[];
9+
data: any[][];
10+
}
11+
12+
export default async function handler( req: NextApiRequest, res: NextApiResponse<Data> ) {
13+
const sheetId = getSheetId()
14+
const sheetTitles = await getSheetTitles(sheetId)
15+
const latestTableTitle = sheetTitles.at(-1)
16+
if(latestTableTitle){
17+
const data = await getDataFromSheet(sheetId, latestTableTitle)
18+
const filteredData = filterSensitiveData(data);
19+
res.json(filteredData)
20+
}
21+
else {
22+
res.status(500).send({data:[], headers:[]})
23+
}
24+
}

pages/index.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { useState } from 'react'
2+
import NavBar from '../components/navbar.component'
3+
import Table from '../components/table.components'
4+
5+
export default function Home({participantsData}: any) {
6+
7+
const [data, setData] = useState(participantsData.data)
8+
9+
function handleFilter(event: React.ChangeEvent<HTMLInputElement>) {
10+
11+
if(event.target.value){
12+
const filtered_data = data.filter(
13+
(entry: any) => entry.some(
14+
(e:string) => e.toLowerCase().includes(event.target.value.toLowerCase())
15+
)
16+
)
17+
setData(filtered_data)
18+
} else {
19+
setData(participantsData.data)
20+
}
21+
}
22+
23+
return (
24+
<>
25+
<NavBar filterFunc = {handleFilter} />
26+
<Table headers={participantsData.headers} data={data}/>
27+
</>
28+
)
29+
}
30+
31+
32+
export async function getStaticProps(){
33+
// Fetch data from external API
34+
const res = await fetch(`https://gccp.vercel.app/api/hello`)
35+
const data = await res.json()
36+
return { props: { participantsData: data }, revalidate: 518400 }
37+
}

postcss.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
}

0 commit comments

Comments
 (0)