-
-
Save DanyF-github/3e40a2ab14b07631319f0c03a91036a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// client/src/components/Homeworks/HomeworkFileList.tsx | |
import React from 'react'; | |
import { useQuery } from '@apollo/client'; | |
import { GET_HOMEWORK_FILES } from '../../data/queries'; | |
import { HomeworkFile } from '../../models'; | |
// the component get the uuid of the homework as property | |
const HomeworkFileList = ({ uuid }: { uuid: string }) => { | |
// retrieve the submitted files for the given homework | |
const { data, loading, error } = useQuery< | |
{ homeworkFiles: HomeworkFile[] }, | |
{ uuid: string } | |
>(GET_HOMEWORK_FILES, { | |
variables: { | |
uuid, | |
}, | |
}); | |
// render the html elements | |
return ( | |
<> | |
{loading && <p>Loading...</p>} | |
{error && <p>Error!</p>} | |
{data && ( | |
<> | |
<h1>Homework Files</h1> | |
<p>{data.homeworkFiles.length > 0 && data.homeworkFiles[0].homework.description}</p> | |
<table> | |
<thead> | |
<tr> | |
<th>Phone Number</th> | |
<th>Student Name</th> | |
<th>Link</th> | |
</tr> | |
</thead> | |
<tbody> | |
{data.homeworkFiles.map((homeworkFile) => { | |
return ( | |
<tr key={homeworkFile.student.phoneNumber}> | |
<td>{homeworkFile.student.phoneNumber}</td> | |
<td> | |
{homeworkFile.student.firstName} | |
{homeworkFile.student.lastName} | |
</td> | |
<td> | |
<a | |
target="_blank" | |
rel="noopener noreferrer" | |
href={homeworkFile.url} | |
> | |
{homeworkFile.url} | |
</a> | |
</td> | |
</tr> | |
); | |
})} | |
</tbody> | |
</table> | |
</> | |
)} | |
</> | |
); | |
}; | |
export default HomeworkFileList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment