Skip to content

Commit

Permalink
feat(client,server): support chapter problem editorial (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar authored Sep 30, 2023
1 parent 06e9821 commit c420701
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package judgels.jerahmeel.api.chapter.problem.programming;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.Optional;
import java.util.Set;
import judgels.jerahmeel.api.problem.ProblemProgress;
import judgels.sandalphon.api.problem.ProblemEditorialInfo;
import judgels.sandalphon.api.problem.programming.ProblemSkeleton;
import judgels.sandalphon.api.problem.programming.ProblemWorksheet;
import org.immutables.value.Value;
Expand All @@ -13,6 +15,7 @@ public interface ChapterProblemWorksheet extends judgels.jerahmeel.api.chapter.p
ProblemWorksheet getWorksheet();
Set<ProblemSkeleton> getSkeletons();
ProblemProgress getProgress();
Optional<ProblemEditorialInfo> getEditorial();

class Builder extends ImmutableChapterProblemWorksheet.Builder{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import judgels.gabriel.api.Verdict;
import judgels.jerahmeel.api.chapter.problem.ChapterProblem;
import judgels.jerahmeel.api.chapter.problem.ChapterProblemData;
import judgels.jerahmeel.api.chapter.problem.ChapterProblemWorksheet;
Expand All @@ -35,6 +36,7 @@
import judgels.jerahmeel.role.RoleChecker;
import judgels.jerahmeel.stats.StatsStore;
import judgels.sandalphon.SandalphonClient;
import judgels.sandalphon.api.problem.ProblemEditorialInfo;
import judgels.sandalphon.api.problem.ProblemInfo;
import judgels.sandalphon.api.problem.ProblemType;
import judgels.service.actor.ActorChecker;
Expand Down Expand Up @@ -134,6 +136,13 @@ public ChapterProblemWorksheet getProblemWorksheet(
resourceStore.getPreviousAndNextResourcePathsForProblem(chapterJid, problemAlias);

if (problemInfo.getType() == ProblemType.PROGRAMMING) {
ProblemProgress progress = statsStore.getProblemProgressesMap(actorJid, Set.of(problemJid)).get(problemJid);

Optional<ProblemEditorialInfo> editorial = Optional.empty();
if (progress.getVerdict().equals(Verdict.ACCEPTED.getCode())) {
editorial = sandalphonClient.getProblemEditorial(problemJid, uriInfo.getBaseUri(), language);
}

return new judgels.jerahmeel.api.chapter.problem.programming.ChapterProblemWorksheet.Builder()
.defaultLanguage(problemInfo.getDefaultLanguage())
.languages(problemInfo.getTitlesByLanguage().keySet())
Expand All @@ -145,7 +154,8 @@ public ChapterProblemWorksheet getProblemWorksheet(
.reasonNotAllowedToSubmit(reasonNotAllowedToSubmit)
.build())
.skeletons(sandalphonClient.getProgrammingProblemSkeletons(problemJid))
.progress(statsStore.getProblemProgressesMap(actorJid, Set.of(problemJid)).get(problemJid))
.progress(progress)
.editorial(editorial)
.build();
} else {
return new judgels.jerahmeel.api.chapter.problem.bundle.ChapterProblemWorksheet.Builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ContentCard } from '../../../ContentCard/ContentCard';
import { KatexText } from '../../../KatexText/KatexText';

export function ProblemEditorialCard({ alias, statement: { title }, editorial: { text } }) {
return (
<ContentCard>
<h2 className="programming-problem-statement__name">
{alias ? `${alias}. ` : ''}
{title}
</h2>
<div className="programming-problem-statement__text">
<KatexText key={alias}>{text}</KatexText>
</div>
</ContentCard>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import StatementLanguageWidget from '../../../../../../../../../../components/La
import { selectCourse } from '../../../../../../../modules/courseSelectors';
import { selectCourseChapter } from '../../../../../modules/courseChapterSelectors';
import { ProblemWorksheetCard } from '../../../../../../../../../../components/ProblemWorksheetCard/Programming/ProblemWorksheetCard';
import { ProblemEditorialCard } from '../../../../../../../../../../components/ProblemWorksheetCard/Programming/ProblemEditorialCard/ProblemEditorialCard';

import './ChapterProblemStatementPage.scss';

Expand All @@ -26,15 +27,37 @@ export function ChapterProblemStatementPage({ worksheet }) {
);
};

const renderEditorial = () => {
const { problem, editorial } = worksheet;
if (!editorial) {
return null;
}
return (
<ProblemEditorialCard alias={problem.alias} statement={worksheet.worksheet.statement} editorial={editorial} />
);
};

const renderStatement = () => {
const { problem } = worksheet;
const { problem, editorial } = worksheet;

if (editorial) {
return (
<details>
<summary>
<small>Click to view original problem statement</small>
</summary>
<ProblemWorksheetCard alias={problem.alias} worksheet={worksheet.worksheet} />
</details>
);
}

return <ProblemWorksheetCard alias={problem.alias} worksheet={worksheet.worksheet} />;
};

return (
<ContentCard className="chapter-programming-problem-statement-page">
{renderStatementLanguageWidget()}
{renderEditorial()}
{renderStatement()}
</ContentCard>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
.chapter-programming-problem-statement-page {
flex: 1 1;
max-width: 865px;

details summary {
cursor: pointer;
margin-bottom: 10px;
}

details summary > * {
display: inline;
}
}

0 comments on commit c420701

Please sign in to comment.