Skip to content

Commit

Permalink
fix csv replay to increment arduino code
Browse files Browse the repository at this point in the history
  • Loading branch information
cmayeux05 committed May 15, 2024
1 parent 271653d commit ca599d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions client/src/views/Replay/Replay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import NavBar from '../../components/NavBar/NavBar';
import { Table } from 'antd';
import { getSave } from '../../Utils/requests';
import { CSVDownloader } from 'react-papaparse';
import { getArduino, getXml } from '../../components/DayPanels/Utils/helpers.js';
import { getArduino, getArduinoXML } from '../../components/DayPanels/Utils/helpers.js';
const TIME_LINE_SIZE = 25;

const timelineReducer = (timeline, action) => {
Expand Down Expand Up @@ -70,6 +70,7 @@ const timelineReducer = (timeline, action) => {
const Replay = () => {
const { saveID } = useParams();
const workspaceRef = useRef(null);
const workspaceRefdummy = useRef(null);
const [replay, setReplay] = useState([]);
const [isPlaying, setIsPlaying] = useState(false);
const [playbackRef, setPlaybackRef] = useState(null);
Expand Down Expand Up @@ -128,18 +129,21 @@ const Replay = () => {
value: save.data.replay ? save.data.replay.length : 0,
});
//set log
let data = save.data.replay.map((item, index) => {
let data = save.data.replay.map((item, index) =>
{
return {
key: index,
blockId: item.blockId,
blockType: item.blockType,
timestamp: item.timestamp,
action: item.action,
xml: item.xml,
};
});

setLogData(data);
setCsvData(data.slice(0).reverse());
//console.log('csvlogdata: ', csvData);
setCsvFilename(
`${save.data.student.name}_${save.data.created_at}_code_replay`
);
Expand All @@ -151,6 +155,16 @@ const Replay = () => {
getReplay();
}, []);

const findMyArduino = (xml) => {
workspaceRefdummy.current = window.Blockly.inject('root', {
toolbox: document.getElementById('toolbox'),
readOnly: true,
});
const my_arduino = getArduinoXML(xml, workspaceRefdummy.current);
workspaceRefdummy.current.dispose();
return my_arduino
};

const columns = [
{
title: 'No.',
Expand Down Expand Up @@ -400,7 +414,8 @@ const Replay = () => {
action: log.action,
'block type': log.blockType,
'block id': log.blockId,
'arduino code': getArduino(workspaceRef.current, false),
'xml': log.xml,
'arduino code': findMyArduino(log.xml),
};
});
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"x-generation-date": "05/12/2024 9:04:36 PM"
"x-generation-date": "05/15/2024 9:33:55 PM"
},
"x-strapi-config": {
"path": "/documentation",
Expand Down

0 comments on commit ca599d3

Please sign in to comment.