11import { useState , useEffect } from "react" ;
22import type { NextPage } from "next" ;
3- import { fetchIssues } from '../utils/fetchIssues' ;
4- import styles from '../styles/issues.module.css' ;
3+ import styles from '../styles/summariestable.module.css' ;
4+ import SubmitMissingSummary from '../components/SubmitMissingSummary' ;
5+ import { getWorkgroups } from '../utils/getWorkgroups' ;
6+ import { getMissingSummaries } from '../utils/getMissingSummaries' ;
57
6- interface Issue {
7- id : number ;
8- title : string ;
9- html_url : string ;
10- state : string ;
8+ interface SummaryData {
9+ meetingDate : string ;
10+ status : string ;
11+ workgroup : string ;
12+ workgroupId : string ;
1113}
1214
1315const StatusOfSummaries : NextPage = ( ) => {
1416 const [ loading , setLoading ] = useState < boolean > ( false ) ;
15- const [ openIssues , setOpenIssues ] = useState < Issue [ ] > ( [ ] ) ;
16- const [ closedIssues , setClosedIssues ] = useState < Issue [ ] > ( [ ] ) ;
17+ const [ data , setData ] = useState < SummaryData [ ] > ( [ ] ) ;
18+ const [ workgroups , setWorkgroups ] = useState < any [ ] > ( [ ] ) ;
19+ const [ allSummaries , setAllSummaries ] = useState < any [ ] > ( [ ] ) ;
1720
18- const newIssueUrl = `https://github.com/SingularityNET-Archive/archive-oracle/issues/new?assignees=Andre-Diamond&labels=tool-issue&projects=SingularityNET-Archive%2F3&template=testing_issue.yml&title=%2AEnter+title+here%2A+-+%5BDate%3A+${ getCurrentFormattedDate ( ) } %5D` ;
19-
20- async function getIssues ( ) {
21+ async function fetchCsvData ( ) {
2122 setLoading ( true ) ;
22- const issues = await fetchIssues ( ) ;
23- console . log ( issues )
24- const open = issues . filter ( ( issue : Issue ) => issue . state === 'open' ) ;
25- const closed = issues . filter ( ( issue : Issue ) => issue . state === 'closed' ) ;
26- setOpenIssues ( open ) ;
27- setClosedIssues ( closed ) ;
23+ try {
24+ const response = await fetch ( '/api/fetchCsv' ) ;
25+ const data = await response . json ( ) ;
26+ console . log ( 'Fetched CSV data:' , data ) ;
27+ setData ( data ) ;
28+ } catch ( error ) {
29+ console . error ( "Failed to fetch CSV data:" , error ) ;
30+ }
2831 setLoading ( false ) ;
2932 }
3033
3134 useEffect ( ( ) => {
32- getIssues ( )
33- } , [ ] ) ;
35+ //fetchCsvData();
36+ fetchWorkgroups ( ) ; // Add this line
37+ } , [ ] ) ;
38+
39+ async function fetchWorkgroups ( ) {
40+ try {
41+ const databaseWorkgroups = await getWorkgroups ( ) ;
42+ const allSummaries = await getMissingSummaries ( ) ;
43+ setAllSummaries ( allSummaries )
44+
45+ // Assuming databaseWorkgroups should be an array, check and handle accordingly
46+ if ( Array . isArray ( databaseWorkgroups ) ) {
47+ setWorkgroups ( databaseWorkgroups ) ;
48+ } else {
49+ console . error ( "Expected an array for workgroups, received:" , databaseWorkgroups ) ;
50+ // Handle the unexpected format, e.g., set to an empty array or a default value
51+ setWorkgroups ( [ ] ) ;
52+ }
53+ } catch ( error ) {
54+ console . error ( "Error fetching workgroups:" , error ) ;
55+ setWorkgroups ( [ ] ) ; // Handle error by setting workgroups to an empty array or another default state
56+ }
57+ }
3458
35- function getCurrentFormattedDate ( ) {
36- const today = new Date ( ) ;
37- const yyyy = today . getFullYear ( ) . toString ( ) ;
38- let mm = ( today . getMonth ( ) + 1 ) . toString ( ) ; // January is 0!
39- let dd = today . getDate ( ) . toString ( ) ;
40-
41- if ( dd . length < 2 ) dd = '0' + dd ;
42- if ( mm . length < 2 ) mm = '0' + mm ;
43-
44- return yyyy + '-' + mm + '-' + dd ;
45- }
46-
4759 return (
4860 < div className = { styles . container } >
49- < h1 > Issues </ h1 >
50- < a href = { newIssueUrl } target = "_blank" rel = "noopener noreferrer" >
51- < button className = { styles . createIssueButton } > Create New Issue </ button >
52- </ a >
61+ < SubmitMissingSummary workgroups = { workgroups } allSummaries = { allSummaries } / >
62+ < h1 > Status of Summaries </ h1 >
63+ { loading && < p > Loading... </ p > }
64+
5365 < div className = { styles . issuesTableContainer } >
54-
55- { /* Open Issues Table */ }
66+ { /* Missing Summaries Table */ }
67+ < h2 className = { styles . missingHeading } > Missing Summaries </ h2 >
5668 < table className = { styles . issuesTable } >
5769 < thead >
58- < tr >
59- < th colSpan = { 2 } > Open Issues</ th >
70+ < tr className = { styles . tableRow } >
71+ < th className = { styles . tableHeader } > Meeting Date</ th >
72+ < th className = { styles . tableHeader } > Workgroup</ th >
73+ < th className = { styles . tableHeader } > Status</ th >
6074 </ tr >
6175 </ thead >
6276 < tbody >
63- { openIssues . map ( issue => (
64- < tr key = { issue . id } className = { styles . openIssue } >
65- < td >
66- < a className = { styles . openIssueLink } href = { issue . html_url } target = "_blank" rel = "noopener noreferrer" >
67- { issue . title }
68- </ a >
69- </ td >
77+ { allSummaries . filter ( row => row . status === "Missing" ) . map ( ( row , index ) => (
78+ < tr key = { index } className = { styles . tableRow } >
79+ < td className = { styles . tableData } > { row . meetingDate } </ td >
80+ < td className = { styles . tableData } > { row . workgroup } </ td >
81+ < td className = { styles . tableData } > { row . status } </ td >
7082 </ tr >
7183 ) ) }
7284 </ tbody >
7385 </ table >
74-
75- { /* Closed Issues Table */ }
86+
87+ { /* Done Summaries Table */ }
88+ < h2 className = { styles . doneHeading } > Done Summaries</ h2 >
7689 < table className = { styles . issuesTable } >
7790 < thead >
78- < tr >
79- < th colSpan = { 2 } > Closed Issues</ th >
91+ < tr className = { styles . tableRow } >
92+ < th className = { styles . tableHeader } > Meeting Date</ th >
93+ < th className = { styles . tableHeader } > Workgroup</ th >
94+ < th className = { styles . tableHeader } > Status</ th >
8095 </ tr >
8196 </ thead >
8297 < tbody >
83- { closedIssues . map ( issue => (
84- < tr key = { issue . id } >
85- < td >
86- < a className = { styles . closedIssueLink } href = { issue . html_url } target = "_blank" rel = "noopener noreferrer" >
87- { issue . title }
88- </ a >
89- </ td >
98+ { allSummaries . filter ( row => row . status === "Done" ) . map ( ( row , index ) => (
99+ < tr key = { index } className = { styles . tableRow } >
100+ < td className = { styles . tableData } > { row . meetingDate } </ td >
101+ < td className = { styles . tableData } > { row . workgroup } </ td >
102+ < td className = { styles . tableData } > { row . status } </ td >
90103 </ tr >
91104 ) ) }
92105 </ tbody >
93106 </ table >
94-
95107 </ div >
96108 </ div >
97109 ) ;
98-
99110} ;
100111
101- export default StatusOfSummaries ;
112+ export default StatusOfSummaries ;
0 commit comments