Skip to content

Commit 531fb32

Browse files
authored
Merge pull request #20 from LoveYourself999/main
adding router
2 parents fd48239 + c0154b7 commit 531fb32

File tree

7 files changed

+171
-7
lines changed

7 files changed

+171
-7
lines changed

src/component/Layout.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Navbar from "./Navbar";
2+
import Sidebar from "./Sidebar";
3+
4+
const Layout = ({ children }) => {
5+
return(
6+
<div style={{ backgroundColor: '#F0F8FF' }}>
7+
<Sidebar />
8+
<main className="flex-grow ml-64 relative">
9+
<Navbar />
10+
{children}
11+
</main>
12+
</div>
13+
)
14+
}
15+
16+
export default Layout;

src/component/Navbar.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const Navbar = () => {
2+
return (
3+
<>
4+
<nav className="flex justify-between items-center px-4 py-2">
5+
<div className="flex-grow">
6+
<input
7+
type="text"
8+
className="w-3/4 bg-white text-black-200 px-4 py-2 rounded-md"
9+
placeholder="Search..."
10+
/>
11+
</div>
12+
<div className="flex items-center"></div>
13+
</nav>
14+
</>
15+
);
16+
};
17+
18+
export default Navbar;

src/component/Sidebar.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import React, { useState } from 'react';
2+
import Papa from 'papaparse';
3+
import { useRouter } from 'next/router';
4+
5+
const Sidebar = () => {
6+
const router = useRouter();
7+
// State to track the selected button, conference data, and dropdown visibility
8+
const [selectedButton, setSelectedButton] = useState(null);
9+
const [conferences, setConferences] = useState([]);
10+
const [dropdownVisible, setDropdownVisible] = useState(false);
11+
12+
// Function to handle button click and update selectedButton state
13+
const handleButtonClick = (buttonName) => {
14+
setSelectedButton(buttonName);
15+
router.push('/');
16+
if (buttonName === 'conference') {
17+
// Toggle dropdown visibility
18+
setDropdownVisible(!dropdownVisible);
19+
// If "Conference" button is clicked, fetch and set conference data
20+
if (!dropdownVisible) {
21+
fetchConferences();
22+
}
23+
} else {
24+
// Hide dropdown if another button is clicked
25+
setDropdownVisible(false);
26+
}
27+
};
28+
29+
// Function to fetch conference data from CSV file
30+
const fetchConferences = () => {
31+
fetch('https://raw.githubusercontent.com/cncf-tags/cloud-native-ai/main/cncf-youtube-channel-summarizer/data/sample_cncf_video_summary.csv')
32+
.then((response) => {
33+
if (!response.ok) {
34+
throw new Error('Network response was not ok');
35+
}
36+
return response.text();
37+
})
38+
.then((text) => {
39+
// Parse CSV data using PapaParse and extract 'conference_name' column
40+
Papa.parse(text, {
41+
header: true,
42+
skipEmptyLines: true,
43+
complete: (result) => {
44+
const uniqueConferences = new Set();
45+
const conferencesData = result.data.reduce((acc, row) => {
46+
const name = row['conference_name'].trim();
47+
if (!uniqueConferences.has(name)) {
48+
uniqueConferences.add(name);
49+
acc.push({ name });
50+
}
51+
return acc;
52+
}, []);
53+
setConferences(conferencesData);
54+
},
55+
});
56+
})
57+
.catch((error) => {
58+
console.error('Error fetching conference data:', error);
59+
});
60+
};
61+
62+
// Function to handle click on dropdown button
63+
const handleDropdownButtonClick = () => {
64+
// Navigate to the new page when dropdown button is clicked
65+
router.push('/conferences/NewPage');
66+
};
67+
68+
return (
69+
<>
70+
<aside className="fixed top-0 left-0 w-64 h-full" aria-label="Sidenav">
71+
<div className="overflow-y-auto py-5 px-3 h-full bg-white border-r border-gray-200 dark:bg-gray-800 dark:border-gray-700">
72+
<ul className="space-y-2">
73+
<li>
74+
<a href="#" className={`flex items-center p-2 text-base font-normal text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 ${selectedButton === 'dashboard' ? 'bg-blue-500 text-black' : ''}`} onClick={() => handleButtonClick('dashboard')}>
75+
<span className="ml-3">Dashboard</span>
76+
</a>
77+
</li>
78+
<li>
79+
<button type="button" className={`flex items-center p-2 w-full text-base font-normal text-gray-900 rounded-lg transition duration-75 group hover:bg-gray-100 dark:text-white dark:hover:bg-gray-700 ${selectedButton === 'conference' ? 'bg-blue-500 text-black' : ''}`} onClick={() => handleButtonClick('conference')}>
80+
<span className="flex-1 ml-3 text-left whitespace-nowrap">Conference</span>
81+
<svg aria-hidden="true" className="w-6 h-6" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fillRule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clipRule="evenodd"></path></svg>
82+
</button>
83+
{/* Render conference list if the "Conference" button is selected and dropdown is visible */}
84+
{selectedButton === 'conference' && dropdownVisible && (
85+
<ul className="pl-6 mt-2">
86+
{/* Render conference items */}
87+
{conferences.map((conference, index) => (
88+
<li key={index} className="py-1">
89+
<button type="button" className="text-left text-gray-900 dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 w-full p-1 rounded-lg transition" onClick={handleDropdownButtonClick}>
90+
{conference.name}
91+
</button>
92+
</li>
93+
))}
94+
</ul>
95+
)}
96+
</li>
97+
</ul>
98+
</div>
99+
</aside>
100+
</>
101+
);
102+
};
103+
104+
export default Sidebar;

src/pages/_app.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import "@/styles/globals.css";
2+
import Layout from '../component/Layout';
23

34
export default function App({ Component, pageProps }) {
4-
return <Component {...pageProps} />;
5-
}
5+
return (
6+
<Layout>
7+
<Component {...pageProps} />
8+
</Layout>
9+
)
10+
}

src/pages/conferences/[conference].js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
3+
const NewPage = () => {
4+
return (
5+
<div style={{ backgroundColor: '#F0F8FF' }}>
6+
<h1>This is the page for a conference</h1>
7+
{/* Add the content you want to display on the new page here */}
8+
</div>
9+
);
10+
};
11+
12+
export default NewPage;

src/pages/conferences/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
3+
const conferences = () => {
4+
5+
return (
6+
<div style={{ backgroundColor: '#F0F8FF' }}>
7+
<h1>This is the home page for all conferences</h1>
8+
{}
9+
</div>
10+
);
11+
};
12+
13+
export default conferences;

src/pages/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Sidebar from './Sidebar'
2-
import Navbar from './Navbar'
31
import { useEffect, useState } from 'react';
42
import ForceGraph from './force-graph';
53
const Home = () => {
@@ -12,10 +10,8 @@ const Home = () => {
1210
}, []);
1311

1412
return (
15-
<div style={{ backgroundColor: '#F0F8FF' }}> {/* Changed background color to light gray */}
16-
<Sidebar />
13+
<div style={{ backgroundColor: '#F0F8FF' }}>
1714
<main className="flex-grow ml-64 relative">
18-
<Navbar />
1915
{data && <ForceGraph data={data} src="/conference-dashboard"/>}
2016
</main>
2117
</div>

0 commit comments

Comments
 (0)