Skip to content

Instantly share code, notes, and snippets.

@DanyF-github
Created January 8, 2021 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanyF-github/3e40a2ab14b07631319f0c03a91036a4 to your computer and use it in GitHub Desktop.
Save DanyF-github/3e40a2ab14b07631319f0c03a91036a4 to your computer and use it in GitHub Desktop.
// 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