-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added expo page * Added page to view public project data
- Loading branch information
1 parent
d7e478a
commit 9b4e9a7
Showing
6 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { useEffect, useState } from 'react'; | ||
import Container from '../components/Container'; | ||
import { getRequest } from '../api'; | ||
import { errorAlert } from '../util'; | ||
|
||
const Expo = () => { | ||
const [rawProjects, setRawProjects] = useState<PublicProject[]>([]); | ||
const [projects, setProjects] = useState<PublicProject[]>([]); | ||
const [nameSort, setNameSort] = useState(false); | ||
|
||
// Fetch public project list from DB | ||
useEffect(() => { | ||
async function fetchProjects() { | ||
const res = await getRequest<PublicProject[]>('/project/list/public', ''); | ||
if (res.status !== 200) { | ||
errorAlert(res); | ||
return; | ||
} | ||
setRawProjects(res.data as PublicProject[]); | ||
} | ||
|
||
fetchProjects(); | ||
}, []); | ||
|
||
// On load or when sort changes, sort by name/table # | ||
useEffect(() => { | ||
if (!rawProjects) return; | ||
|
||
const sortedProjects = [...rawProjects]; | ||
if (nameSort) { | ||
sortedProjects.sort((a, b) => a.name.localeCompare(b.name)); | ||
} else { | ||
sortedProjects.sort((a, b) => a.location - b.location); | ||
} | ||
|
||
setProjects(sortedProjects); | ||
}, [rawProjects, nameSort]); | ||
|
||
return ( | ||
<Container noCenter> | ||
<h1 className="mt-4 text-4xl text-center font-bold">Project Expo</h1> | ||
<h2 className="text-2xl text-center font-bold text-primary"> | ||
{process.env.REACT_APP_JURY_NAME} | ||
</h2> | ||
<table className="mb-4"> | ||
<thead> | ||
<tr> | ||
<th | ||
onClick={() => setNameSort(true)} | ||
className={ | ||
'px-4 py-2 cursor-pointer text-left ' + (nameSort && 'underline') | ||
} | ||
> | ||
Name | ||
</th> | ||
<th | ||
onClick={() => setNameSort(false)} | ||
className={ | ||
'px-4 py-2 cursor-pointer text-left ' + (!nameSort && 'underline') | ||
} | ||
> | ||
Table | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{projects.map((project, idx) => ( | ||
<tr key={idx}> | ||
<td className="px-4 py-2"> | ||
<a href={project.url} target="_blank" rel="noopener noreferrer"> | ||
{project.name} | ||
</a> | ||
</td> | ||
<td className="px-4 py-2">{project.location}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Expo; |
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
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
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
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