refactor axios.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { getACRate } from "./../utils/functions"
|
||||
import { DIFFICULTY } from "./../utils/constants"
|
||||
import { Problem, LANGUAGE } from "./../utils/types"
|
||||
import { Problem, SubmitCodePayload } from "./../utils/types"
|
||||
import http from "./../utils/http"
|
||||
import { useAxios } from "@vueuse/integrations/useAxios"
|
||||
|
||||
@@ -65,11 +65,6 @@ export function getSubmission(id: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export function submitCode(data: {
|
||||
problem_id: number
|
||||
contest_id?: number
|
||||
language: LANGUAGE
|
||||
code: string
|
||||
}) {
|
||||
export function submitCode(data: SubmitCodePayload) {
|
||||
return http.post("submission", data)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from "../../../utils/constants"
|
||||
import { isMobile } from "../../../utils/breakpoints"
|
||||
import { submitCode } from "../../api"
|
||||
import { Problem } from "../../../utils/types"
|
||||
import { LANGUAGE, Problem, SubmitCodePayload } from "../../../utils/types"
|
||||
|
||||
const { problem, contestID = "" } = defineProps<{
|
||||
contestID?: string
|
||||
@@ -85,13 +85,12 @@ const submitDisabled = computed(() => {
|
||||
})
|
||||
|
||||
async function submit() {
|
||||
const data = {
|
||||
const data: SubmitCodePayload = {
|
||||
problem_id: problem.id,
|
||||
language: state.language,
|
||||
code: state.values[state.language],
|
||||
}
|
||||
if (contestID) {
|
||||
//@ts-ignore
|
||||
data.contest_id = parseInt(contestID)
|
||||
}
|
||||
const res = await submitCode(data)
|
||||
|
||||
@@ -12,7 +12,7 @@ export function logout() {
|
||||
}
|
||||
|
||||
export function getUserInfo(username: string) {
|
||||
return useAxios("profile", { method: "get", params: { username } }, http, {
|
||||
return useAxios("profile", { params: { username } }, http, {
|
||||
immediate: false,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -49,3 +49,10 @@ export interface Problem {
|
||||
contest: null
|
||||
my_status: number
|
||||
}
|
||||
|
||||
export interface SubmitCodePayload {
|
||||
problem_id: number
|
||||
language: LANGUAGE
|
||||
code: string
|
||||
contest_id?: number
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user