Skip to content

Commit 501b501

Browse files
authored
Merge pull request #24 from LoveYourself999/main
Adding video summaries for each conferences
2 parents b065164 + 1ee8bad commit 501b501

File tree

4 files changed

+150
-38
lines changed

4 files changed

+150
-38
lines changed

src/component/Sidebar.js

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import React, { useState } from 'react';
22
import Papa from 'papaparse';
33
import { useRouter } from 'next/router';
4+
import Link from 'next/link';
5+
46

57
const Sidebar = () => {
68
const router = useRouter();
79
// State to track the selected button, conference data, and dropdown visibility
810
const [selectedButton, setSelectedButton] = useState(null);
911
const [conferences, setConferences] = useState([]);
12+
const [selectedDropDownButton, setSelectedDropDownButton] = useState(null);
1013
const [dropdownVisible, setDropdownVisible] = useState(false);
1114

1215
// Function to handle button click and update selectedButton state
@@ -26,43 +29,43 @@ const Sidebar = () => {
2629
}
2730
};
2831

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);
32+
// Function to fetch conference data from CSV file
33+
const fetchConferences = () => {
34+
fetch('https://raw.githubusercontent.com/cncf-tags/cloud-native-ai/main/cncf-youtube-channel-summarizer/data/cncf_video_summary_29.csv')
35+
.then((response) => {
36+
if (!response.ok) {
37+
throw new Error('Network response was not ok');
38+
}
39+
return response.text();
40+
})
41+
.then((text) => {
42+
// Parse CSV data using PapaParse and extract 'video_id' and 'conference_name' columns
43+
Papa.parse(text, {
44+
header: true,
45+
skipEmptyLines: true,
46+
complete: (result) => {
47+
const uniqueConferences = new Set();
48+
const conferencesData = result.data.reduce((acc, row) => {
49+
const name = row['conference_name'].trim();
50+
const videoId = row['video_id'].trim();
51+
if (!uniqueConferences.has(name)) {
52+
uniqueConferences.add(name);
53+
acc.push({ video_id: videoId, conference_name: name });
54+
}
55+
return acc;
56+
}, []);
57+
setConferences(conferencesData);
58+
},
5959
});
60-
};
60+
})
61+
.catch((error) => {
62+
console.error('Error fetching conference data:', error);
63+
});
64+
};
6165

6266
// 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');
67+
const handleDropdownButtonClick = (name) => {
68+
setSelectedDropDownButton(name);
6669
};
6770

6871
return (
@@ -86,9 +89,11 @@ const Sidebar = () => {
8689
{/* Render conference items */}
8790
{conferences.map((conference, index) => (
8891
<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+
<Link href={'/conferences/'+ conference.video_id}>
93+
<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 ${selectedDropDownButton === conference.video_id ? 'bg-blue-500 text-black' : ''}`} onClick={() => handleDropdownButtonClick(conference.video_id)}>
94+
{conference.conference_name}
95+
</button>
96+
</Link>
9297
</li>
9398
))}
9499
</ul>

src/pages/conferences/[id].js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// pages/conferences/[conference_name].js
2+
3+
import { useRouter } from 'next/router';
4+
import Papa from 'papaparse';
5+
6+
export default function Conference({ conferences, allVideos }) {
7+
const router = useRouter();
8+
9+
if (router.isFallback) {
10+
return <div>Loading...</div>;
11+
}
12+
13+
const sameConferences = allVideos.filter((video) => video.conference_name === conferences[0].conference_name);
14+
15+
return (
16+
<div className="container">
17+
<h1>{conferences[0].conference_name}</h1>
18+
{sameConferences.map((conference, index) => (
19+
<div key={index} className="conference">
20+
<p><strong>Video ID:</strong> {conference.video_id}</p>
21+
<p><strong>Video Summary:</strong> {conference.summary}</p>
22+
<p>-------------------------</p>
23+
</div>
24+
))}
25+
</div>
26+
);
27+
}
28+
29+
export async function getStaticPaths() {
30+
try {
31+
const response = await fetch('https://raw.githubusercontent.com/cncf-tags/cloud-native-ai/main/cncf-youtube-channel-summarizer/data/cncf_video_summary_29.csv');
32+
if (!response.ok) {
33+
throw new Error('Failed to fetch CSV');
34+
}
35+
const csvText = await response.text();
36+
const { data: videos } = Papa.parse(csvText, { header: true });
37+
38+
const paths = videos.map((video) => ({
39+
params: { id: video.video_id },
40+
}));
41+
42+
return {
43+
paths,
44+
fallback: false, // or 'blocking' or true
45+
};
46+
} catch (error) {
47+
console.error('Error fetching or parsing CSV:', error);
48+
return {
49+
paths: [],
50+
fallback: false, // or 'blocking' or true
51+
};
52+
}
53+
}
54+
55+
export async function getStaticProps({ params }) {
56+
try {
57+
const response = await fetch('https://raw.githubusercontent.com/cncf-tags/cloud-native-ai/main/cncf-youtube-channel-summarizer/data/cncf_video_summary_29.csv');
58+
if (!response.ok) {
59+
throw new Error('Failed to fetch CSV');
60+
}
61+
const csvText = await response.text();
62+
const { data: videos } = Papa.parse(csvText, { header: true });
63+
const conferences = videos.filter((video) => video.video_id === params.id);
64+
if (conferences.length === 0) {
65+
return {
66+
notFound: true,
67+
};
68+
}
69+
70+
return {
71+
props: {
72+
conferences,
73+
allVideos: videos,
74+
},
75+
};
76+
} catch (error) {
77+
console.error('Error fetching or parsing CSV:', error);
78+
return {
79+
notFound: true,
80+
};
81+
}
82+
}

src/pages/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Home = () => {
44
const [data, setData] = useState('');
55
useEffect(() => {
66
// Fetch the CSV data from the server
7-
fetch('https://raw.githubusercontent.com/cncf-tags/cloud-native-ai/main/cncf-youtube-channel-summarizer/data/sample_cncf_video_summary.csv')
7+
fetch('https://raw.githubusercontent.com/cncf-tags/cloud-native-ai/main/cncf-youtube-channel-summarizer/data/cncf_video_summary_29.csv')
88
.then((response) => response.text())
99
.then((csvData) => setData(csvData));
1010
}, []);

src/styles/globals.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,31 @@ body {
2626
rgb(var(--background-start-rgb));
2727
}
2828

29+
.container {
30+
max-width: 800px;
31+
margin: 0 auto;
32+
padding: 20px;
33+
background-color: #ffffff;
34+
border-radius: 10px;
35+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
36+
}
37+
38+
h1 {
39+
color: #333;
40+
font-size: 2.5em;
41+
margin-bottom: 10px;
42+
}
43+
44+
p {
45+
color: #666;
46+
font-size: 1.2em;
47+
line-height: 1.6;
48+
}
49+
50+
p strong {
51+
color: #000;
52+
}
53+
2954
@layer utilities {
3055
.text-balance {
3156
text-wrap: balance;

0 commit comments

Comments
 (0)