2016-06-22 21:58:23 +02:00
|
|
|
import * as ActionTypes from '../../../constants';
|
2016-05-05 23:48:26 +02:00
|
|
|
|
2016-07-06 21:09:05 +02:00
|
|
|
const defaultSketch = `function setup() {
|
2016-06-24 00:29:55 +02:00
|
|
|
createCanvas(400, 400);
|
2016-05-10 00:28:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function draw() {
|
2016-06-24 00:29:55 +02:00
|
|
|
background(220);
|
2016-07-06 21:09:05 +02:00
|
|
|
}`;
|
|
|
|
|
|
|
|
const defaultHTML =
|
2016-07-12 03:54:08 +02:00
|
|
|
`<!DOCTYPE html>
|
2016-07-06 21:09:05 +02:00
|
|
|
<html>
|
|
|
|
<head>
|
2016-07-12 17:13:09 +02:00
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.2/p5.min.js"></script>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.2/addons/p5.dom.min.js"></script>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.2/addons/p5.sound.min.js"></script>
|
2016-07-12 03:54:08 +02:00
|
|
|
<link rel="stylesheet" type="text/css" href="style.css">
|
2016-07-06 21:09:05 +02:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script src="sketch.js"></script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`;
|
|
|
|
|
2016-07-12 03:54:08 +02:00
|
|
|
const defaultCSS =
|
|
|
|
`html, body {
|
|
|
|
overflow: hidden;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
`;
|
2016-07-08 20:57:22 +02:00
|
|
|
|
|
|
|
// if the project has never been saved,
|
2016-07-06 21:09:05 +02:00
|
|
|
const initialState = [
|
|
|
|
{
|
|
|
|
name: 'sketch.js',
|
2016-07-08 20:57:22 +02:00
|
|
|
content: defaultSketch,
|
|
|
|
id: '1'
|
2016-07-06 21:09:05 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'index.html',
|
2016-07-08 20:57:22 +02:00
|
|
|
content: defaultHTML,
|
|
|
|
id: '2'
|
2016-07-12 03:54:08 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'style.css',
|
|
|
|
content: defaultCSS,
|
|
|
|
id: '3'
|
2016-07-06 21:09:05 +02:00
|
|
|
}];
|
2016-05-05 23:48:26 +02:00
|
|
|
|
2016-07-06 21:09:05 +02:00
|
|
|
|
|
|
|
const files = (state = initialState, action) => {
|
2016-06-24 00:29:55 +02:00
|
|
|
switch (action.type) {
|
2016-07-07 19:50:52 +02:00
|
|
|
case ActionTypes.UPDATE_FILE_CONTENT:
|
2016-07-06 21:09:05 +02:00
|
|
|
return state.map(file => {
|
|
|
|
if (file.name !== action.name) {
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2016-07-07 19:50:52 +02:00
|
|
|
return Object.assign({}, file, { content: action.content });
|
2016-07-06 21:09:05 +02:00
|
|
|
});
|
2016-06-24 00:29:55 +02:00
|
|
|
case ActionTypes.NEW_PROJECT:
|
2016-07-06 23:29:07 +02:00
|
|
|
return [...action.files];
|
2016-06-29 18:52:16 +02:00
|
|
|
case ActionTypes.SET_PROJECT:
|
2016-07-06 23:29:07 +02:00
|
|
|
return [...action.files];
|
2016-06-24 00:29:55 +02:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
2016-05-05 23:48:26 +02:00
|
|
|
|
2016-07-08 20:57:22 +02:00
|
|
|
export const getFile = (state, id) => state.filter(file => file.id === id)[0];
|
2016-07-12 03:54:08 +02:00
|
|
|
export const getHTMLFile = (state) => state.filter(file => file.name.match(/.*\.html$/))[0];
|
|
|
|
export const getJSFiles = (state) => state.filter(file => file.name.match(/.*\.js$/));
|
|
|
|
export const getCSSFiles = (state) => state.filter(file => file.name.match(/.*\.css$/));
|
2016-07-08 20:57:22 +02:00
|
|
|
|
2016-07-06 21:09:05 +02:00
|
|
|
export default files;
|