-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uses display name instead of uid (#328)
* uses display name instead of uid * re added authentication * fix failing test * changed APP var * removed console log * replaced path and merge conflicts * removed 404 for submissions * fixed page spamming backend with requests * type error --------- Co-authored-by: Aron Buzogany <[email protected]>
- Loading branch information
1 parent
2822c1b
commit 4bfa40f
Showing
7 changed files
with
142 additions
and
97 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Params } from "react-router-dom"; | ||
import { Me } from "../types/me"; | ||
import { Submission } from "../types/submission"; | ||
import { authenticatedFetch } from "../utils/authenticated-fetch"; | ||
|
||
const APIURL = import.meta.env.VITE_APP_API_HOST; | ||
|
||
const fetchDisplaynameByUid = async (uids: [string]) => { | ||
const uidParams = new URLSearchParams(); | ||
for (const uid of uids) { | ||
uidParams.append("uid", uid); | ||
} | ||
const uidUrl = `${APIURL}/users?` + uidParams; | ||
const response = await authenticatedFetch(uidUrl); | ||
const jsonData = await response.json(); | ||
|
||
return jsonData.data; | ||
}; | ||
|
||
/** | ||
* | ||
* @param param0 - projectId | ||
* @returns - projectData and submissionsWithUsers | ||
*/ | ||
export default async function loadSubmissionOverview({ | ||
params, | ||
}: { | ||
params: Params<string>; | ||
}) { | ||
const projectId = params.projectId; | ||
const projectResponse = await authenticatedFetch( | ||
`${APIURL}/projects/${projectId}` | ||
); | ||
const projectData = (await projectResponse.json())["data"]; | ||
|
||
const overviewResponse = await authenticatedFetch( | ||
`${APIURL}/projects/${projectId}/latest-per-user` | ||
); | ||
const jsonData = await overviewResponse.json(); | ||
const uids = jsonData.data.map((submission: Submission) => submission.uid); | ||
const users = await fetchDisplaynameByUid(uids); | ||
|
||
const submissionsWithUsers = jsonData.data.map((submission: Submission) => { | ||
// Find the corresponding user for this submission's UID | ||
const user = users.find((user: Me) => user.uid === submission.uid); | ||
// Add user information to the submission | ||
return { | ||
...submission, | ||
display_name: user.display_name, | ||
}; | ||
}); | ||
|
||
return { | ||
projectData, | ||
submissionsWithUsers, | ||
}; | ||
} |
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