Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/admin/src/locales/en-US/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ export default {
'Create and manage exams, set time range and duration, and manage exam participants.',
'pages.exams.listTitle': 'Exam List',
'pages.exams.create': 'Create Exam',
'pages.exams.more': 'More',
'pages.exams.publish': 'Publish',
'pages.exams.fetchError': 'Failed to fetch exam list',
'pages.exams.columns.id': 'ID',
Expand Down
1 change: 1 addition & 0 deletions apps/admin/src/locales/zh-CN/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ export default {
'创建和管理考试,设置考试时间、时长和参与考生,支持线上监考。',
'pages.exams.listTitle': '考试列表',
'pages.exams.create': '创建考试',
'pages.exams.more': '更多',
'pages.exams.publish': '发布',
'pages.exams.fetchError': '获取考试列表失败',
'pages.exams.columns.id': 'ID',
Expand Down
60 changes: 3 additions & 57 deletions apps/admin/src/pages/Content/Library/Questions/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import {
import { restrictToVerticalAxis } from '@dnd-kit/modifiers';
import {
SortableContext,
useSortable,
verticalListSortingStrategy,
} from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
import type { AdminQuestion, QuestionType } from '@examora/types';
import {
DIFFICULTY_OPTIONS,
Expand All @@ -42,7 +40,6 @@ import {
Empty,
Form,
Input,
InputNumber,
Popconfirm,
Radio,
Row,
Expand All @@ -53,6 +50,9 @@ import {
import dayjs from 'dayjs';
import React, { useEffect, useMemo, useState } from 'react';
import { requestErrorMessage } from '@/utils/request';
import { SectionTitle } from './components/SectionTitle';
import { SortableItemWrapper } from './components/SortableItemWrapper';
import { UnitInputNumber } from './components/UnitInputNumber';
import './index.less';

interface QuestionOption {
Expand All @@ -62,17 +62,6 @@ interface QuestionOption {

const OPTION_KEYS = 'ABCDEFGH'.split('');

const UnitInputNumber: React.FC<
React.ComponentProps<typeof InputNumber> & { unit: string }
> = ({ unit, style, ...props }) => (
<Space.Compact style={{ width: '100%' }}>
<InputNumber {...props} style={{ ...style, width: '100%' }} />
<Button disabled tabIndex={-1}>
{unit}
</Button>
</Space.Compact>
);

const normalizeOptions = (options: QuestionOption[] | undefined) =>
(options || [])
.map((option, index) => ({
Expand Down Expand Up @@ -292,49 +281,6 @@ const DIFFICULTY_TAGS: Record<string, string> = {
Sub-components
============================================================ */

const SectionTitle: React.FC<{
children: React.ReactNode;
style?: React.CSSProperties;
}> = ({ children, style }) => (
<h3 className="qdetail-section-title" style={style}>
{children}
</h3>
);

interface SortableItemWrapperProps {
id: string;
children: (handlers: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
listeners: any;
setActivatorNodeRef: (node: HTMLElement | null) => void;
}) => React.ReactNode;
}

const SortableItemWrapper: React.FC<SortableItemWrapperProps> = ({
id,
children,
}) => {
const {
attributes,
listeners,
setNodeRef,
setActivatorNodeRef,
transform,
transition,
} = useSortable({ id });

const style: React.CSSProperties = {
transform: CSS.Translate.toString(transform),
transition,
};

return (
<div ref={setNodeRef} style={style} {...attributes}>
{children({ listeners, setActivatorNodeRef })}
</div>
);
};

const OptionAnswerControl: React.FC<{
type: 'SINGLE_CHOICE' | 'MULTIPLE_CHOICE';
optionIndex: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

export const SectionTitle: React.FC<{
children: React.ReactNode;
style?: React.CSSProperties;
}> = ({ children, style }) => (
<h3 className="qdetail-section-title" style={style}>
{children}
</h3>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useSortable } from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
import React from 'react';

interface SortableItemWrapperProps {
id: string;
children: (handlers: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
listeners: any;
setActivatorNodeRef: (node: HTMLElement | null) => void;
}) => React.ReactNode;
}

export const SortableItemWrapper: React.FC<SortableItemWrapperProps> = ({
id,
children,
}) => {
const {
attributes,
listeners,
setNodeRef,
setActivatorNodeRef,
transform,
transition,
} = useSortable({ id });

const style: React.CSSProperties = {
transform: CSS.Translate.toString(transform),
transition,
};

return (
<div ref={setNodeRef} style={style} {...attributes}>
{children({ listeners, setActivatorNodeRef })}
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Button, InputNumber, Space } from 'antd';
import React from 'react';

export const UnitInputNumber: React.FC<
React.ComponentProps<typeof InputNumber> & { unit: string }
> = ({ unit, style, ...props }) => (
<Space.Compact style={{ width: '100%' }}>
<InputNumber {...props} style={{ ...style, width: '100%' }} />
<Button disabled tabIndex={-1}>
{unit}
</Button>
</Space.Compact>
);
8 changes: 8 additions & 0 deletions apps/admin/src/pages/Content/Library/Questions/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ html.examora-dark .question-type-icon {
outline-offset: 2px;
}

.question-actions-cell {
display: inline-flex;
align-items: center;
justify-content: flex-start;
min-width: 64px;
text-align: left;
}

.question-actions-cell a {
color: var(--examora-text);
transition: color 150ms ease;
Expand Down
Loading
Loading