From 2d9b72099710ead97c39ac35c1753b30ea44a13d Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 17 Jul 2024 13:54:17 +0200 Subject: [PATCH] readd and fix learneth --- apps/learneth/src/pages/StepList/index.tsx | 6 +- apps/learneth/src/redux/models/workshop.ts | 155 +++++++++--------- .../home-tab/src/lib/remix-ui-home-tab.tsx | 2 +- 3 files changed, 83 insertions(+), 80 deletions(-) diff --git a/apps/learneth/src/pages/StepList/index.tsx b/apps/learneth/src/pages/StepList/index.tsx index 4aae0de39e4..26574d5c1be 100644 --- a/apps/learneth/src/pages/StepList/index.tsx +++ b/apps/learneth/src/pages/StepList/index.tsx @@ -21,13 +21,13 @@ function StepListPage(): JSX.Element {
-

{entity.name}

+

{entity && entity.name}

- {entity.text} + {entity && entity.text}
- {entity.steps.map((step: any, i: number) => ( + {entity && entity.steps.map((step: any, i: number) => ( (window as any)._paq.push(['trackEvent', 'learneth', 'step_slide_in', `${id}/${i}/${step.name}`])}> {step.name} ยป diff --git a/apps/learneth/src/redux/models/workshop.ts b/apps/learneth/src/redux/models/workshop.ts index 1ef8394a863..55a18739deb 100644 --- a/apps/learneth/src/redux/models/workshop.ts +++ b/apps/learneth/src/redux/models/workshop.ts @@ -44,103 +44,106 @@ const Model: ModelType = { *loadRepo({ payload }, { put, select }) { toast.info(`loading ${payload.name}/${payload.branch}`) - yield put({ - type: 'loading/save', - payload: { - screen: true, - }, - }) - - const { list, detail } = yield select((state) => state.workshop) - - const url = `${apiUrl}/clone/${encodeURIComponent(payload.name)}/${payload.branch}?${Math.random()}` - console.log('loading ', url) - const { data } = yield axios.get(url) const repoId = `${payload.name}-${payload.branch}` + const { list, detail } = yield select((state) => state.workshop) - for (let i = 0; i < data.ids.length; i++) { - const { - steps, - metadata: { - data: { steps: metadataSteps }, + if (!detail[repoId]) { + yield put({ + type: 'loading/save', + payload: { + screen: true, }, - } = data.entities[data.ids[i]] - - let newSteps = [] + }) - if (metadataSteps) { - newSteps = metadataSteps.map((step: any) => { - return { - ...steps.find((item: any) => item.name === step.path), - name: step.name, - } - }) - } else { - newSteps = steps.map((step: any) => ({ - ...step, - name: step.name.replace('_', ' '), - })) - } + const url = `${apiUrl}/clone/${encodeURIComponent(payload.name)}/${payload.branch}?${Math.random()}` + console.log('loading ', url) + const { data } = yield axios.get(url) + + for (let i = 0; i < data.ids.length; i++) { + const { + steps, + metadata: { + data: { steps: metadataSteps }, + }, + } = data.entities[data.ids[i]] + + let newSteps = [] + + if (metadataSteps) { + newSteps = metadataSteps.map((step: any) => { + return { + ...steps.find((item: any) => item.name === step.path), + name: step.name, + } + }) + } else { + newSteps = steps.map((step: any) => ({ + ...step, + name: step.name.replace('_', ' '), + })) + } - const stepKeysWithFile = ['markdown', 'solidity', 'test', 'answer', 'js', 'vy'] - - for (let j = 0; j < newSteps.length; j++) { - const step = newSteps[j] - for (let k = 0; k < stepKeysWithFile.length; k++) { - const key = stepKeysWithFile[k] - if (step[key]) { - try { - step[key].content = null // we load this later - } catch (error) { - console.error(error) + const stepKeysWithFile = ['markdown', 'solidity', 'test', 'answer', 'js', 'vy'] + + for (let j = 0; j < newSteps.length; j++) { + const step = newSteps[j] + for (let k = 0; k < stepKeysWithFile.length; k++) { + const key = stepKeysWithFile[k] + if (step[key]) { + try { + step[key].content = null // we load this later + } catch (error) { + console.error(error) + } } } } + data.entities[data.ids[i]].steps = newSteps } - data.entities[data.ids[i]].steps = newSteps - } - const workshopState = { - detail: { - ...detail, - [repoId]: { - ...data, - group: groupBy( - data.ids.map((id: string) => pick(data.entities[id], ['level', 'id'])), - (item: any) => item.level - ), - ...payload, + const workshopState = { + detail: { + ...detail, + [repoId]: { + ...data, + group: groupBy( + data.ids.map((id: string) => pick(data.entities[id], ['level', 'id'])), + (item: any) => item.level + ), + ...payload, + }, }, - }, - list: detail[repoId] ? list : [...list, payload], - selectedId: repoId, - } - yield put({ - type: 'workshop/save', - payload: workshopState, - }) - localStorage.setItem('workshop.state', JSON.stringify(workshopState)) + list: detail[repoId] ? list : [...list, payload], + selectedId: repoId, + } + yield put({ + type: 'workshop/save', + payload: workshopState, + }) + localStorage.setItem('workshop.state', JSON.stringify(workshopState)) - toast.dismiss() - yield put({ - type: 'loading/save', - payload: { - screen: false, - }, - }) + toast.dismiss() + yield put({ + type: 'loading/save', + payload: { + screen: false, + }, + }); + (window)._paq.push(['trackEvent', 'learneth', 'load_repo', payload.name]) + } if (payload.id) { - const { detail, selectedId } = workshopState - const { ids, entities } = detail[selectedId] + const { detail } = yield select((state) => state.workshop) + const { ids, entities } = detail[repoId] for (let i = 0; i < ids.length; i++) { const entity = entities[ids[i]] if (entity.metadata.data.id === payload.id || i + 1 === payload.id) { yield router.navigate(`/list?id=${ids[i]}`) break } - } + }; + (window)._paq.push(['trackEvent', 'learneth', 'start_tutorial', payload.name]) } - (window)._paq.push(['trackEvent', 'learneth', 'load_repo', payload.name]) }, *resetAll(_, { put }) { yield put({ diff --git a/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx b/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx index 3153b7ac799..260ea667858 100644 --- a/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx +++ b/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx @@ -82,7 +82,7 @@ export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => { {!(platform === appPlatformTypes.desktop) ? : } - {/* */} +