-
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.
Fixed assignment "already submitted" label
- Fixed assignment "already submitted" label - Moved assignment and page api requests to separate functions - Added misc comments - Updated manifest description
- Loading branch information
Showing
3 changed files
with
77 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Todo } from "./types"; | ||
|
||
export async function getAssignment(courseId: number, assignmentId: number) { | ||
|
||
// Get assignment data | ||
const assignmentReq = await fetch(`/api/v1/courses/${courseId}/assignments/${assignmentId}`); | ||
// Get submission data | ||
const submissionReq = await fetch(`/api/v1/courses/${courseId}/students/submissions?assignment_ids[]=${assignmentId}`); | ||
|
||
// Parse json | ||
const assignmentData = await assignmentReq.json(); | ||
const submissionData = await submissionReq.json(); | ||
|
||
// Check if assignment is submitted | ||
const isSubmitted = submissionData[0].workflow_state !== 'unsubmitted'; | ||
|
||
// Create todo object | ||
const assignment: Todo = { | ||
type: 'assignment', | ||
courseId, | ||
id: assignmentId, | ||
name: assignmentData.name | ||
}; | ||
|
||
return { | ||
todo: assignment, | ||
isSubmitted | ||
}; | ||
} | ||
|
||
export async function getPage(courseId: number, pageId: number | string) { | ||
|
||
// Check if pageId is a number or a string | ||
const pageIdType = typeof pageId === 'number' ? 'pageId' : 'pageUrl'; | ||
|
||
// Get page data | ||
const pageReq = await fetch(`/api/v1/courses/${courseId}/pages/${pageId}`); | ||
const pageData = await pageReq.json(); | ||
|
||
// Create todo object | ||
const page: Todo = { | ||
type: 'page', | ||
courseId, | ||
id: pageIdType === 'pageId' ? pageId : pageData.id, | ||
name: pageData.title | ||
}; | ||
|
||
return { | ||
todo: page, | ||
isSubmitted: false | ||
} | ||
} |