|
|
@ -1,13 +1,13 @@ |
|
|
|
import axios from 'axios'; |
|
|
|
import axios from 'axios' |
|
|
|
import { toast } from 'react-toastify'; |
|
|
|
import {toast} from 'react-toastify' |
|
|
|
import groupBy from 'lodash/groupBy'; |
|
|
|
import groupBy from 'lodash/groupBy' |
|
|
|
import pick from 'lodash/pick'; |
|
|
|
import pick from 'lodash/pick' |
|
|
|
import { type ModelType } from '../store'; |
|
|
|
import {type ModelType} from '../store' |
|
|
|
import remixClient from '../../remix-client'; |
|
|
|
import remixClient from '../../remix-client' |
|
|
|
import { router } from '../../App'; |
|
|
|
import {router} from '../../App' |
|
|
|
|
|
|
|
|
|
|
|
// const apiUrl = 'http://localhost:3001';
|
|
|
|
// const apiUrl = 'http://localhost:3001';
|
|
|
|
const apiUrl = 'https://static.220.14.12.49.clients.your-server.de:3000'; |
|
|
|
const apiUrl = 'https://static.220.14.12.49.clients.your-server.de:3000' |
|
|
|
|
|
|
|
|
|
|
|
const Model: ModelType = { |
|
|
|
const Model: ModelType = { |
|
|
|
namespace: 'workshop', |
|
|
|
namespace: 'workshop', |
|
|
@ -17,20 +17,20 @@ const Model: ModelType = { |
|
|
|
selectedId: '', |
|
|
|
selectedId: '', |
|
|
|
}, |
|
|
|
}, |
|
|
|
reducers: { |
|
|
|
reducers: { |
|
|
|
save(state, { payload }) { |
|
|
|
save(state, {payload}) { |
|
|
|
return { ...state, ...payload }; |
|
|
|
return {...state, ...payload} |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
effects: { |
|
|
|
effects: { |
|
|
|
*init(_, { put }) { |
|
|
|
*init(_, {put}) { |
|
|
|
const cache = localStorage.getItem('workshop.state'); |
|
|
|
const cache = localStorage.getItem('workshop.state') |
|
|
|
|
|
|
|
|
|
|
|
if (cache) { |
|
|
|
if (cache) { |
|
|
|
const workshopState = JSON.parse(cache); |
|
|
|
const workshopState = JSON.parse(cache) |
|
|
|
yield put({ |
|
|
|
yield put({ |
|
|
|
type: 'workshop/save', |
|
|
|
type: 'workshop/save', |
|
|
|
payload: workshopState, |
|
|
|
payload: workshopState, |
|
|
|
}); |
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
yield put({ |
|
|
|
yield put({ |
|
|
|
type: 'workshop/loadRepo', |
|
|
|
type: 'workshop/loadRepo', |
|
|
@ -38,80 +38,67 @@ const Model: ModelType = { |
|
|
|
name: 'ethereum/remix-workshops', |
|
|
|
name: 'ethereum/remix-workshops', |
|
|
|
branch: 'master', |
|
|
|
branch: 'master', |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
*loadRepo({ payload }, { put, select }) { |
|
|
|
*loadRepo({payload}, {put, select}) { |
|
|
|
toast.info(`loading ${payload.name}/${payload.branch}`); |
|
|
|
toast.info(`loading ${payload.name}/${payload.branch}`) |
|
|
|
|
|
|
|
|
|
|
|
yield put({ |
|
|
|
yield put({ |
|
|
|
type: 'loading/save', |
|
|
|
type: 'loading/save', |
|
|
|
payload: { |
|
|
|
payload: { |
|
|
|
screen: true, |
|
|
|
screen: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const { list, detail } = yield select((state) => state.workshop); |
|
|
|
const {list, detail} = yield select((state) => state.workshop) |
|
|
|
|
|
|
|
|
|
|
|
const url = `${apiUrl}/clone/${encodeURIComponent(payload.name)}/${ |
|
|
|
const url = `${apiUrl}/clone/${encodeURIComponent(payload.name)}/${payload.branch}?${Math.random()}` |
|
|
|
payload.branch |
|
|
|
console.log('loading ', url) |
|
|
|
}?${Math.random()}`;
|
|
|
|
const {data} = yield axios.get(url) |
|
|
|
console.log('loading ', url); |
|
|
|
console.log(data) |
|
|
|
const { data } = yield axios.get(url); |
|
|
|
const repoId = `${payload.name}-${payload.branch}` |
|
|
|
console.log(data); |
|
|
|
|
|
|
|
const repoId = `${payload.name}-${payload.branch}`; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < data.ids.length; i++) { |
|
|
|
for (let i = 0; i < data.ids.length; i++) { |
|
|
|
const { |
|
|
|
const { |
|
|
|
steps, |
|
|
|
steps, |
|
|
|
metadata: { |
|
|
|
metadata: { |
|
|
|
data: { steps: metadataSteps }, |
|
|
|
data: {steps: metadataSteps}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} = data.entities[data.ids[i]]; |
|
|
|
} = data.entities[data.ids[i]] |
|
|
|
|
|
|
|
|
|
|
|
let newSteps = []; |
|
|
|
let newSteps = [] |
|
|
|
|
|
|
|
|
|
|
|
if (metadataSteps) { |
|
|
|
if (metadataSteps) { |
|
|
|
newSteps = metadataSteps.map((step: any) => { |
|
|
|
newSteps = metadataSteps.map((step: any) => { |
|
|
|
return { |
|
|
|
return { |
|
|
|
...steps.find((item: any) => item.name === step.path), |
|
|
|
...steps.find((item: any) => item.name === step.path), |
|
|
|
name: step.name, |
|
|
|
name: step.name, |
|
|
|
}; |
|
|
|
} |
|
|
|
}); |
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
newSteps = steps.map((step: any) => ({ |
|
|
|
newSteps = steps.map((step: any) => ({ |
|
|
|
...step, |
|
|
|
...step, |
|
|
|
name: step.name.replace('_', ' '), |
|
|
|
name: step.name.replace('_', ' '), |
|
|
|
})); |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const stepKeysWithFile = [ |
|
|
|
const stepKeysWithFile = ['markdown', 'solidity', 'test', 'answer', 'js', 'vy'] |
|
|
|
'markdown', |
|
|
|
|
|
|
|
'solidity', |
|
|
|
|
|
|
|
'test', |
|
|
|
|
|
|
|
'answer', |
|
|
|
|
|
|
|
'js', |
|
|
|
|
|
|
|
'vy', |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (let j = 0; j < newSteps.length; j++) { |
|
|
|
for (let j = 0; j < newSteps.length; j++) { |
|
|
|
const step = newSteps[j]; |
|
|
|
const step = newSteps[j] |
|
|
|
for (let k = 0; k < stepKeysWithFile.length; k++) { |
|
|
|
for (let k = 0; k < stepKeysWithFile.length; k++) { |
|
|
|
const key = stepKeysWithFile[k]; |
|
|
|
const key = stepKeysWithFile[k] |
|
|
|
if (step[key]) { |
|
|
|
if (step[key]) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
step[key].content = (yield remixClient.call( |
|
|
|
step[key].content = (yield remixClient.call('contentImport', 'resolve', step[key].file)).content |
|
|
|
'contentImport', |
|
|
|
|
|
|
|
'resolve', |
|
|
|
|
|
|
|
step[key].file, |
|
|
|
|
|
|
|
)).content; |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|
console.error(error); |
|
|
|
console.error(error) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
data.entities[data.ids[i]].steps = newSteps; |
|
|
|
data.entities[data.ids[i]].steps = newSteps |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const workshopState = { |
|
|
|
const workshopState = { |
|
|
@ -120,44 +107,42 @@ const Model: ModelType = { |
|
|
|
[repoId]: { |
|
|
|
[repoId]: { |
|
|
|
...data, |
|
|
|
...data, |
|
|
|
group: groupBy( |
|
|
|
group: groupBy( |
|
|
|
data.ids.map((id: string) => |
|
|
|
data.ids.map((id: string) => pick(data.entities[id], ['level', 'id'])), |
|
|
|
pick(data.entities[id], ['level', 'id']), |
|
|
|
(item: any) => item.level |
|
|
|
), |
|
|
|
|
|
|
|
(item: any) => item.level, |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
...payload, |
|
|
|
...payload, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
list: detail[repoId] ? list : [...list, payload], |
|
|
|
list: detail[repoId] ? list : [...list, payload], |
|
|
|
selectedId: repoId, |
|
|
|
selectedId: repoId, |
|
|
|
}; |
|
|
|
} |
|
|
|
yield put({ |
|
|
|
yield put({ |
|
|
|
type: 'workshop/save', |
|
|
|
type: 'workshop/save', |
|
|
|
payload: workshopState, |
|
|
|
payload: workshopState, |
|
|
|
}); |
|
|
|
}) |
|
|
|
localStorage.setItem('workshop.state', JSON.stringify(workshopState)); |
|
|
|
localStorage.setItem('workshop.state', JSON.stringify(workshopState)) |
|
|
|
|
|
|
|
|
|
|
|
toast.dismiss(); |
|
|
|
toast.dismiss() |
|
|
|
yield put({ |
|
|
|
yield put({ |
|
|
|
type: 'loading/save', |
|
|
|
type: 'loading/save', |
|
|
|
payload: { |
|
|
|
payload: { |
|
|
|
screen: false, |
|
|
|
screen: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
if (payload.id) { |
|
|
|
if (payload.id) { |
|
|
|
const { detail, selectedId } = workshopState; |
|
|
|
const {detail, selectedId} = workshopState |
|
|
|
const { ids, entities } = detail[selectedId]; |
|
|
|
const {ids, entities} = detail[selectedId] |
|
|
|
for (let i = 0; i < ids.length; i++) { |
|
|
|
for (let i = 0; i < ids.length; i++) { |
|
|
|
const entity = entities[ids[i]]; |
|
|
|
const entity = entities[ids[i]] |
|
|
|
if (entity.metadata.data.id === payload.id || i + 1 === payload.id) { |
|
|
|
if (entity.metadata.data.id === payload.id || i + 1 === payload.id) { |
|
|
|
yield router.navigate(`/list?id=${ids[i]}`); |
|
|
|
yield router.navigate(`/list?id=${ids[i]}`) |
|
|
|
break; |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
*resetAll(_, { put }) { |
|
|
|
*resetAll(_, {put}) { |
|
|
|
yield put({ |
|
|
|
yield put({ |
|
|
|
type: 'workshop/save', |
|
|
|
type: 'workshop/save', |
|
|
|
payload: { |
|
|
|
payload: { |
|
|
@ -165,15 +150,15 @@ const Model: ModelType = { |
|
|
|
detail: {}, |
|
|
|
detail: {}, |
|
|
|
selectedId: '', |
|
|
|
selectedId: '', |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
localStorage.removeItem('workshop.state'); |
|
|
|
localStorage.removeItem('workshop.state') |
|
|
|
|
|
|
|
|
|
|
|
yield put({ |
|
|
|
yield put({ |
|
|
|
type: 'workshop/init', |
|
|
|
type: 'workshop/init', |
|
|
|
}); |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default Model; |
|
|
|
export default Model |
|
|
|