1
1
import React , { useState } from 'react' ;
2
2
import Papa from 'papaparse' ;
3
3
import { useRouter } from 'next/router' ;
4
+ import Link from 'next/link' ;
5
+
4
6
5
7
const Sidebar = ( ) => {
6
8
const router = useRouter ( ) ;
7
9
// State to track the selected button, conference data, and dropdown visibility
8
10
const [ selectedButton , setSelectedButton ] = useState ( null ) ;
9
11
const [ conferences , setConferences ] = useState ( [ ] ) ;
12
+ const [ selectedDropDownButton , setSelectedDropDownButton ] = useState ( null ) ;
10
13
const [ dropdownVisible , setDropdownVisible ] = useState ( false ) ;
11
14
12
15
// Function to handle button click and update selectedButton state
@@ -26,43 +29,43 @@ const Sidebar = () => {
26
29
}
27
30
} ;
28
31
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
+ } ,
59
59
} ) ;
60
- } ;
60
+ } )
61
+ . catch ( ( error ) => {
62
+ console . error ( 'Error fetching conference data:' , error ) ;
63
+ } ) ;
64
+ } ;
61
65
62
66
// 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 ) ;
66
69
} ;
67
70
68
71
return (
@@ -86,9 +89,11 @@ const Sidebar = () => {
86
89
{ /* Render conference items */ }
87
90
{ conferences . map ( ( conference , index ) => (
88
91
< 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 >
92
97
</ li >
93
98
) ) }
94
99
</ ul >
0 commit comments