Skip to content

Commit

Permalink
fix: no last submitted program on the problem view
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzcdev committed Jun 8, 2023
1 parent 910578f commit bbeaee3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/webview/ptaPreviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class PtaPreviewProvider extends PtaWebview {
</div>
` : ""}
${(data.lastSubmissionId !== "0" && data.lastProgram.trim().length) ?
${data.lastProgram.trim().length ?
markdownEngine.render([
`### Last Submission ${data.lastSubmittedLang.trim().length ? "(" + data.lastSubmittedLang + ")" : ""}`,
"```" + data.lastSubmittedLang,
Expand Down
32 changes: 10 additions & 22 deletions src/webview/views/ProblemView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,43 +52,31 @@ export class ProblemView {

this.acceptCount = problemInfo.acceptCount;
this.submitCount = problemInfo.submitCount;
this.lastSubmittedLang = this.getLastSubmittedLang();
this.lastProgram = this.getLastSubmittedProgram();
[this.lastSubmittedLang, this.lastProgram] = await this.getLastSubmittedProgram();
[this.problemNote, this.lastProgram] = this.parseProblemNote(this.lastProgram, "@pintia note=start", "@pintia note=end");
}

private getLastSubmittedLang(): string {
if (!this.lastSubmissionId || this.lastSubmissionId === "0") {
return "";
}
if (this.type === ProblemType.MULTIPLE_FILE) {
return "Verilog";
}
const lastSubmittedCompiler: string = (this.problem.lastSubmissionDetail?.programmingSubmissionDetail
?? this.problem.lastSubmissionDetail?.codeCompletionSubmissionDetail)?.compiler
?? this.problem.compiler;
const lang: string = compilerLangMapping.get(lastSubmittedCompiler)?.trim() ?? "";
private parseCompiler2Lang(compiler: string): string {
const lang: string = compilerLangMapping.get(compiler)?.trim() ?? "";
const pos: number = lang.indexOf("(");
if (pos !== -1) {
return lang.substring(0, pos - 1);
}
return lang;
}

private getLastSubmittedProgram(): string {
if (!this.lastSubmissionId || this.lastSubmissionId === "0") {
return "";
}
private async getLastSubmittedProgram(): Promise<string[]> {
if (this.type === ProblemType.MULTIPLE_FILE) {
const content = this.problem.lastSubmissionDetail?.multipleFileSubmissionDetail?.fileContents;
if (!content || Object.keys(content).length === 0) {
return "";
return ["Verilog", ""];
}
return content[Object.keys(content)[0]];
return ["Verilog", content[Object.keys(content)[0]]];
}
return (this.problem.lastSubmissionDetail?.programmingSubmissionDetail
?? this.problem.lastSubmissionDetail?.codeCompletionSubmissionDetail)?.program
?? "";
const lastSubmissionDetail = (await ptaApi.getLastSubmissions(this.problemSetId, this.id, ptaManager.getUserSession()?.cookie ?? ""))?.submissionDetails[0];
const lastSubmittedCompiler: string = (lastSubmissionDetail?.programmingSubmissionDetail ?? lastSubmissionDetail?.codeCompletionSubmissionDetail)?.compiler ?? this.problem.compiler;
const lastProgram = lastSubmissionDetail?.programmingSubmissionDetail?.program ?? lastSubmissionDetail?.codeCompletionSubmissionDetail?.program ?? "";
return [this.parseCompiler2Lang(lastSubmittedCompiler), lastProgram];
}

private parseProblemNote(data: string, start: string, end: string): [string, string] {
Expand Down

0 comments on commit bbeaee3

Please sign in to comment.