diff --git a/src/App.tsx b/src/App.tsx index 572f08c4..eaab0659 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -23,6 +23,7 @@ import { PilasBloquesApi } from './pbApi'; import { Ember } from './emberCommunication'; import { ChallengeView } from './components/challengeView/ChallengeView'; import { PBSession } from './pbSession'; +import { setXml, xmlBloqueEmpezarAEjecutar } from './components/blockly/blockly'; const AnalyticsComponent = () => { const location = useLocation(); diff --git a/src/components/blockly/PBBlocklyWorkspace.tsx b/src/components/blockly/PBBlocklyWorkspace.tsx index c6c42c54..fde65091 100644 --- a/src/components/blockly/PBBlocklyWorkspace.tsx +++ b/src/components/blockly/PBBlocklyWorkspace.tsx @@ -3,7 +3,7 @@ import { BlockType, getBlockFromId } from "./blocks"; import { Toolbox, categorizedToolbox, setupBlockly, setupBlocklyBlocks, setXml, uncategorizedToolbox } from "./blockly"; import { PBCard } from "../PBCard"; import { Box, PaperProps, Typography } from "@mui/material"; -import { useMemo, useState } from "react"; +import { useState } from "react"; import Blockly from "blockly/core" import { useThemeContext } from "../../theme/ThemeContext"; diff --git a/src/components/challengeView/ChallengeView.tsx b/src/components/challengeView/ChallengeView.tsx index a3c876c3..0e8f4580 100644 --- a/src/components/challengeView/ChallengeView.tsx +++ b/src/components/challengeView/ChallengeView.tsx @@ -1,19 +1,21 @@ import { useParams } from "react-router-dom" import { Challenge, PathToChallenge, currentIdFor, getPathToChallenge } from "../../staticData/challenges"; import { PaperProps, Stack } from "@mui/material"; -import { StatementDescription } from "./StatementDescription"; import { EditableBlocklyWorkspace } from "./EditableBlocklyWorkspace"; import { InfoButton, SceneButtons, SceneButtonsVertical } from "./SceneButtons/SceneButtons"; import { SceneView } from "./SceneView"; +import { StatementDescription } from "./StatementDescription"; import { ChallengeFooter, InfoDrawer } from "./Info/ChallengeFooter"; import { LocalStorage } from "../../localStorage" import { Header } from "../header/Header" import { Scene, SceneMap, SerializedChallenge } from "../serializedChallenge"; import { useTranslation } from "react-i18next"; import { useThemeContext } from "../../theme/ThemeContext"; -import { useMemo, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { StatementTextToShow } from "../creator/Editor/MarkDownEdition/MarkdownEditor"; import { ChallengeBreadcrumb } from "./ChallengeBreadcrumb"; +import Blockly from "blockly/core" +import { setXml, xmlBloqueEmpezarAEjecutar } from "../blockly/blockly"; export const serializedSceneToDescriptor = (scene: Scene) => { const mapToString = (map: SceneMap) => `"${JSON.stringify(map).replace(/"/g, '')}"` @@ -24,7 +26,7 @@ export const serializedSceneToDescriptor = (scene: Scene) => { type ChallengeViewProps = { path?: string, - height?: string + height?: string, } export const ChallengeView = ({path, height}: ChallengeViewProps) => { @@ -74,12 +76,23 @@ const ChallengeWorkspace = ({ statement, challenge, clue }: ChallengeWorkspacePr const { isSmallScreen } = useThemeContext() const [descriptionOrClue, setDescriptionOrClue] = useState(statement!) const setToShow = (show: StatementTextToShow) => setDescriptionOrClue(show === StatementTextToShow.CLUE ? clue! : statement!) + const [first, setFirst] = useState(true) + + useEffect(() => { + setFirst(false) + }, []) + const blocklyWorkspaceProps: EditableBlocklyWorkspaceProps = { blockIds: challenge.toolboxBlockIds, - categorized: challenge.toolboxStyle !== 'noCategories' + categorized: challenge.toolboxStyle !== 'noCategories', + initialXml: first ? xmlBloqueEmpezarAEjecutar : Blockly.utils.xml.domToText( Blockly.Xml.workspaceToDom( Blockly.getMainWorkspace())) } - const challengeWorkspace = isSmallScreen ? : + console.log(blocklyWorkspaceProps.initialXml) + + const InsideChallengeWorkspace = () => { + return isSmallScreen ? : + } return <> @@ -88,7 +101,7 @@ const ChallengeWorkspace = ({ statement, challenge, clue }: ChallengeWorkspacePr setShowStatement={setToShow} clueIsEnabled={clue !== ''} urlImage={challenge.imageURL()} /> - {challengeWorkspace} + {!isSmallScreen ? : <>} @@ -101,12 +114,13 @@ type ChallengeWorkspaceDistributionProps = { type EditableBlocklyWorkspaceProps = { blockIds: string[], - categorized: boolean + categorized: boolean, + initialXml: string } const HorizontalChallengeWorkspace = ({ challenge, blocklyWorkspaceProps }: ChallengeWorkspaceDistributionProps) => { const blocklyWorkspace = useMemo( () => { - return + return },[]) return @@ -123,7 +137,7 @@ const VerticalChallengeWorkspace = ({ challenge, blocklyWorkspaceProps }: Challe const [openDrawer, setOpenDrawer] = useState(false) const blocklyWorkspace = useMemo( () => { - return }, []) + return }, []) return {blocklyWorkspace} diff --git a/src/components/creator/Editor/CreatorViewMode.tsx b/src/components/creator/Editor/CreatorViewMode.tsx index 69c27b1c..68033290 100644 --- a/src/components/creator/Editor/CreatorViewMode.tsx +++ b/src/components/creator/Editor/CreatorViewMode.tsx @@ -17,7 +17,6 @@ export const CreatorViewMode = () => { const challengeBeingEdited: SerializedChallenge = LocalStorage.getCreatorChallenge()! //Ember.importChallenge(challengeBeingEdited) - const navigate = useNavigate() const challengeExists = LocalStorage.getCreatorChallenge() @@ -30,7 +29,7 @@ export const CreatorViewMode = () => { {challengeExists ? ( <>
} SubHeader={} />} /> - + ) : <>}