Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(blanks): hide exercise task until child plugin is selected, focus child plugin after selection #4188

Merged
merged 1 commit into from
Oct 14, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import IconTable from '@editor/editor-ui/assets/plugin-icons/icon-table.svg'
import IconText from '@editor/editor-ui/assets/plugin-icons/icon-text.svg'
import { SelectionCard } from '@editor/editor-ui/selection-card'
import { useEditStrings } from '@editor/i18n/edit-strings-provider'
import { useAppDispatch, focus } from '@editor/store'
import { EditorPluginType } from '@editor/types/editor-plugin-type'

import type { BlanksExerciseProps } from '..'
Expand All @@ -16,15 +17,18 @@ export function ChildPluginSelection({
const pluginStrings = useEditStrings().plugins
const description = pluginStrings.blanksExercise.childPluginSelection

const dispatch = useAppDispatch()

function handleClick(plugin: EditorPluginType) {
setShowSelection(false)
childPlugin.replace(plugin)
dispatch(focus(childPlugin.id))
}

return (
<>
<div className="py-6 text-center text-gray-500">{description}</div>
<div className="flex justify-center gap-6 [&_svg]:min-w-20">
<div className="blanks-child-plugin-selection flex justify-center gap-6 [&_svg]:min-w-20">
<SelectionCard
onClick={() => handleClick(EditorPluginType.Text)}
icon={<IconText />}
Expand Down
14 changes: 9 additions & 5 deletions packages/editor/src/plugins/exercise/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,15 @@ export function ExerciseEditor(props: ExerciseProps) {
/>
</div>
<div className="h-10"></div>
{content.render({
config: {
textPluginPlaceholder: exStrings.placeholder,
},
})}
{/* Special case for the blanks exercise: Until the child plugin is selected we hide the task to avoid confusion */}
{/* Background: Users often add their blanks-text to the task */}
<div className="group-has-[.blanks-child-plugin-selection]/exercise:hidden">
{content.render({
config: {
textPluginPlaceholder: exStrings.placeholder,
},
})}
</div>
<div className="mx-side">
{interactive.defined ? (
<>
Expand Down