mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: add assignment submission from the activity page
This commit is contained in:
parent
c13a7b4538
commit
e9caa2ceb4
7 changed files with 207 additions and 29 deletions
|
|
@ -0,0 +1,28 @@
|
|||
'use client'
|
||||
import React from 'react'
|
||||
import { useLHSession } from '../LHSessionContext'
|
||||
import { getAPIUrl } from '@services/config/config'
|
||||
import { swrFetcher } from '@services/utils/ts/requests'
|
||||
import useSWR from 'swr'
|
||||
|
||||
export const AssignmentSubmissionContext = React.createContext({})
|
||||
|
||||
function AssignmentSubmissionProvider({ children, assignment_uuid }: { children: React.ReactNode, assignment_uuid: string }) {
|
||||
const session = useLHSession() as any
|
||||
const accessToken = session?.data?.tokens?.access_token
|
||||
|
||||
const { data: assignmentSubmission, error: assignmentError } = useSWR(
|
||||
`${getAPIUrl()}assignments/${assignment_uuid}/submissions/me`,
|
||||
(url) => swrFetcher(url, accessToken)
|
||||
)
|
||||
|
||||
return (
|
||||
<AssignmentSubmissionContext.Provider value={assignmentSubmission} >{children}</AssignmentSubmissionContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useAssignmentSubmission() {
|
||||
return React.useContext(AssignmentSubmissionContext)
|
||||
}
|
||||
|
||||
export default AssignmentSubmissionProvider
|
||||
Loading…
Add table
Add a link
Reference in a new issue