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