-
-
Save DanyF-github/fd223caddb6bf9f6a5b025dc80e02321 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/HomeworkList.tsx | |
import React from 'react'; | |
import { useQuery } from '@apollo/client'; | |
import { Link } from 'react-router-dom'; | |
import { GET_HOMEWORKS } from '../../data/queries'; | |
import { Homework } from '../../models'; | |
const HomeworkList = () => { | |
// query the list of homeworks | |
const { data, loading, error } = useQuery(GET_HOMEWORKS); | |
// render the component with the retrieved homework | |
return ( | |
<> | |
{loading && <p>Loading...</p>} | |
{error && <p>Error!</p>} | |
{data && ( | |
<table> | |
<thead> | |
<tr> | |
<th>Identifier</th> | |
<th>Description</th> | |
<th>Actions</th> | |
</tr> | |
</thead> | |
<tbody> | |
{data.homeworks.map((homework: Homework) => { | |
return ( | |
<tr key={homework.uuid}> | |
<td> | |
<Link to={`/homeworks/${homework.uuid}/list`}> | |
{homework.uuid} | |
</Link> | |
</td> | |
<td>{homework.description}</td> | |
<td> | |
<Link to={`/homeworks/${homework.uuid}/upload`}> | |
Upload | |
</Link> | |
</td> | |
</tr> | |
) | |
})} | |
</tbody> | |
</table> | |
)} | |
</> | |
) | |
} | |
export default HomeworkList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment