Skip to content

Commit

Permalink
feat: add debug button for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Oct 11, 2024
1 parent f6cab49 commit 05ea7e5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { NextPage } from 'next';
import SuperTokensNode from 'supertokens-node';

import { logger } from '../../../../../../../../infrastructures/pino';
import { prisma } from '../../../../../../../../infrastructures/prisma';
Expand All @@ -13,6 +14,8 @@ type Props = {

const ProblemPage: NextPage<Props> = async (props) => {
const session = await getNonNullableSessionOnServer();
const superTokensUser = session && (await SuperTokensNode.getUser(session.superTokensUserId));
const isAdmin = superTokensUser?.emails[0]?.endsWith('@internet.ac.jp');

let incompleteProblemSession = await prisma.problemSession.findFirst({
where: {
Expand Down Expand Up @@ -42,6 +45,7 @@ const ProblemPage: NextPage<Props> = async (props) => {
return (
<ProblemPageOnClient
initialProblemSession={incompleteProblemSession}
isAdmin={isAdmin}
params={props.params}
userId={session.superTokensUserId}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ import { courseIdToLectureIds, courseIdToName, problemIdToName } from '../../../
import { ProblemBody } from './ProblmBody';

type Props = {
initialProblemSession: ProblemSession;
isAdmin: boolean | undefined;
params: { courseId: CourseId; lectureId: string; problemId: ProblemId };
userId: string;
initialProblemSession: ProblemSession;
};

export const ProblemPageOnClient: React.FC<Props> = (props) => {
Expand Down Expand Up @@ -106,23 +107,41 @@ export const ProblemPageOnClient: React.FC<Props> = (props) => {
</HStack>
<HStack justify="space-between" spacing={2}>
<Heading as="h1">{problemIdToName[props.params.problemId]}</Heading>
<Tooltip
label={
problemSession.problemType === 'executionResult' ? '減点になりますが、確実に問題を解けます。' : undefined
}
>
<Button
colorScheme="blue"
variant="outline"
onClick={() => {
void updateProblemSession('step', 1);
}}
<HStack spacing={2}>
<Tooltip
label={
problemSession.problemType === 'executionResult'
? '減点になりますが、確実に問題を解けます。'
: undefined
}
>
{problemSession.problemType === 'executionResult'
? '諦めてステップ実行モードに移る'
: 'ステップ実行モードで最初からやり直す'}
</Button>
</Tooltip>
<Button
colorScheme="blue"
variant="outline"
onClick={() => {
void updateProblemSession('step', 1);
}}
>
{problemSession.problemType === 'executionResult'
? '諦めてステップ実行モードに移る'
: 'ステップ実行モードで最初からやり直す'}
</Button>
</Tooltip>
{props.isAdmin && (
<Button
colorScheme="blue"
variant="outline"
onClick={() =>
updateProblemSession(
'step',
Math.min(problemSession.traceItemIndex + 1, problem.traceItems.length - 1)
)
}
>
次のステップに進む(管理者のみ)
</Button>
)}
</HStack>
</HStack>
</VStack>

Expand Down

0 comments on commit 05ea7e5

Please sign in to comment.