diff --git a/apps/learneth/src/pages/StepDetail/index.tsx b/apps/learneth/src/pages/StepDetail/index.tsx
index 8ce821cf67..f235b885eb 100644
--- a/apps/learneth/src/pages/StepDetail/index.tsx
+++ b/apps/learneth/src/pages/StepDetail/index.tsx
@@ -1,37 +1,57 @@
-import React, {useEffect} from 'react'
-import {useLocation, useNavigate} from 'react-router-dom'
+import React, { useEffect } from 'react'
+import { useLocation, useNavigate } from 'react-router-dom'
import Markdown from 'react-markdown'
import rehypeRaw from 'rehype-raw'
import BackButton from '../../components/BackButton'
-import {useAppSelector, useAppDispatch} from '../../redux/hooks'
+import { useAppSelector, useAppDispatch } from '../../redux/hooks'
import './index.scss'
+import remixClient from '../../remix-client'
function StepDetailPage() {
const navigate = useNavigate()
const location = useLocation()
const dispatch = useAppDispatch()
+ const [clonedStep, setClonedStep] = React.useState(null)
+
const queryParams = new URLSearchParams(location.search)
const id = queryParams.get('id') as string
const stepId = Number(queryParams.get('stepId'))
const {
- workshop: {detail, selectedId},
- remixide: {errorLoadingFile, errors, success},
+ workshop: { detail, selectedId },
+ remixide: { errorLoadingFile, errors, success },
} = useAppSelector((state: any) => state)
const entity = detail[selectedId].entities[id]
const steps = entity.steps
const step = steps[stepId]
- console.log(step)
useEffect(() => {
- dispatch({
- type: 'remixide/displayFile',
- payload: step,
- })
- dispatch({
- type: 'remixide/save',
- payload: {errors: [], success: false},
+ setClonedStep(null)
+ const clonedStep = JSON.parse(JSON.stringify(step))
+ const loadFiles = async () => {
+ async function loadFile(step, fileType) {
+ if (step[fileType] && step[fileType].file && !step[fileType].content) {
+ clonedStep[fileType].content = (await remixClient.call('contentImport', 'resolve', step[fileType].file)).content;
+ }
+ }
+
+ const fileTypes = ['markdown', 'solidity', 'test', 'answer', 'js', 'vy'];
+ for (const fileType of fileTypes) {
+ await loadFile(step, fileType);
+ }
+ }
+ loadFiles().then(() => {
+
+ setClonedStep(clonedStep)
+ dispatch({
+ type: 'remixide/displayFile',
+ payload: clonedStep,
+ })
+ dispatch({
+ type: 'remixide/save',
+ payload: { errors: [], success: false },
+ })
+ window.scrollTo(0, 0)
})
- window.scrollTo(0, 0)
}, [step])
useEffect(() => {
@@ -40,6 +60,18 @@ function StepDetailPage() {
}
}, [errors, success])
+ if (!clonedStep) {
+ return (
+ )
+ }
+
return (
@@ -51,13 +83,13 @@ function StepDetailPage() {
{errorLoadingFile ? (
<>
-
{step.name}
+
{clonedStep.name}
- {step.answer?.content && (
+ {clonedStep.answer?.content && (
- {step.answer?.content && (
+ {clonedStep.answer?.content && (