-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3542 from serlo/exercise-group-intermediate-tasks
feat(plugin-exercise-group): add intermediate tasks as experiment
- Loading branch information
Showing
7 changed files
with
201 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/editor/src/plugins/exercise-group/editor/intermediate-task.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { EditorTooltip } from '@editor/editor-ui/editor-tooltip' | ||
import { | ||
faArrowCircleDown, | ||
faArrowCircleUp, | ||
faTrashAlt, | ||
} from '@fortawesome/free-solid-svg-icons' | ||
|
||
import { type ExerciseGroupProps } from '..' | ||
import { FaIcon } from '@/components/fa-icon' | ||
import { useEditorStrings } from '@/contexts/logged-in-data-context' | ||
|
||
interface IntermediateTaskProps { | ||
intermediateTasks: ExerciseGroupProps['state']['intermediateTasks'] | ||
exerciseIndex: number | ||
lastExerciseIndex: number | ||
} | ||
|
||
export function IntermediateTask({ | ||
intermediateTasks, | ||
exerciseIndex, | ||
lastExerciseIndex, | ||
}: IntermediateTaskProps) { | ||
const templateStrings = useEditorStrings().templatePlugins | ||
const exGroupStrings = templateStrings.textExerciseGroup | ||
|
||
if (!intermediateTasks.defined) return | ||
const taskIndex = intermediateTasks.findIndex( | ||
(task) => task.afterIndex.value === exerciseIndex | ||
) | ||
const task = intermediateTasks[taskIndex] | ||
if (!task) return null | ||
|
||
function canMoveTask(newIndex: number) { | ||
if (!intermediateTasks.defined) return false | ||
const indexOccupied = !!intermediateTasks.find( | ||
({ afterIndex }) => afterIndex.value === newIndex | ||
) | ||
return newIndex >= 0 && newIndex < lastExerciseIndex && !indexOccupied | ||
} | ||
|
||
return ( | ||
<> | ||
<nav className="flex justify-end"> | ||
<small className="mx-2 bg-editor-primary-50 p-1 font-bold text-gray-600"> | ||
{exGroupStrings.intermediateTask} | ||
</small> | ||
<div> | ||
{canMoveTask(exerciseIndex - 1) ? ( | ||
<button | ||
className="serlo-button-editor-secondary serlo-tooltip-trigger mr-2" | ||
onClick={() => { | ||
task.afterIndex.set(exerciseIndex - 1) | ||
}} | ||
> | ||
<EditorTooltip text={templateStrings.article.moveUpLabel} /> | ||
<FaIcon icon={faArrowCircleUp} /> | ||
</button> | ||
) : null} | ||
{canMoveTask(exerciseIndex + 1) ? ( | ||
<button | ||
className="serlo-button-editor-secondary serlo-tooltip-trigger mr-2" | ||
onClick={() => { | ||
task.afterIndex.set(exerciseIndex + 1) | ||
}} | ||
> | ||
<FaIcon icon={faArrowCircleDown} /> | ||
</button> | ||
) : null} | ||
<button | ||
className="serlo-button-editor-secondary serlo-tooltip-trigger mr-2" | ||
onClick={() => { | ||
intermediateTasks.set((currentTasks) => { | ||
return currentTasks.filter((_, index) => index !== taskIndex) | ||
}) | ||
}} | ||
> | ||
<EditorTooltip text={exGroupStrings.removeIntermediateTask} /> | ||
<FaIcon icon={faTrashAlt} /> | ||
</button> | ||
</div> | ||
</nav> | ||
<div className="rounded-lg bg-gray-50 p-0.25"> | ||
{task.content.render()} | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters