Skip to content

Commit 1c05241

Browse files
authored
Merge pull request #2211 from lindapaiste/refactor/default-sketch
Cleanup: Single source of default project contents
2 parents 9cdbb8b + 2559f9e commit 1c05241

File tree

6 files changed

+15
-181
lines changed

6 files changed

+15
-181
lines changed

client/modules/IDE/reducers/files.js

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,12 @@
11
import objectID from 'bson-objectid';
22
import * as ActionTypes from '../../../constants';
3+
import {
4+
defaultSketch,
5+
defaultCSS,
6+
defaultHTML
7+
} from '../../../../server/domain-objects/createDefaultFiles';
38

4-
const defaultSketch = `function setup() {
5-
createCanvas(400, 400);
6-
}
7-
8-
function draw() {
9-
background(220);
10-
}`;
11-
12-
const defaultHTML = `<!DOCTYPE html>
13-
<html lang="en">
14-
<head>
15-
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.js"></script>
16-
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/addons/p5.sound.min.js"></script>
17-
<link rel="stylesheet" type="text/css" href="style.css">
18-
<meta charset="utf-8" />
19-
20-
</head>
21-
<body>
22-
<main>
23-
</main>
24-
<script src="sketch.js"></script>
25-
</body>
26-
</html>
27-
`;
28-
29-
const defaultCSS = `html, body {
30-
margin: 0;
31-
padding: 0;
32-
}
33-
canvas {
34-
display: block;
35-
}
36-
`;
37-
38-
const initialState = () => {
9+
export const initialState = () => {
3910
const a = objectID().toHexString();
4011
const b = objectID().toHexString();
4112
const c = objectID().toHexString();

client/modules/Preview/filesReducer.js

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,8 @@
11
import { useMemo } from 'react';
2-
import objectID from 'bson-objectid';
32
import blobUtil from 'blob-util';
43
import mime from 'mime';
54
import { PLAINTEXT_FILE_REGEX } from '../../../server/utils/fileUtils';
65

7-
const defaultSketch = `function setup() {
8-
createCanvas(400, 400);
9-
}
10-
11-
function draw() {
12-
background(220);
13-
}`;
14-
15-
const defaultHTML = `<!DOCTYPE html>
16-
<html lang="en">
17-
<head>
18-
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/p5.js"></script>
19-
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/addons/p5.sound.min.js"></script>
20-
<link rel="stylesheet" type="text/css" href="style.css">
21-
<meta charset="utf-8" />
22-
23-
</head>
24-
<body>
25-
<main>
26-
</main>
27-
<script src="sketch.js"></script>
28-
</body>
29-
</html>
30-
`;
31-
32-
const defaultCSS = `html, body {
33-
margin: 0;
34-
padding: 0;
35-
}
36-
canvas {
37-
display: block;
38-
}
39-
`;
40-
416
// https://gist.github.com/fnky/7d044b94070a35e552f3c139cdf80213
427
export function useSelectors(state, mapStateToSelectors) {
438
const selectors = useMemo(() => mapStateToSelectors(state), [state]);
@@ -52,48 +17,6 @@ export function getFileSelectors(state) {
5217
};
5318
}
5419

55-
export function initialState() {
56-
const a = objectID().toHexString();
57-
const b = objectID().toHexString();
58-
const c = objectID().toHexString();
59-
const r = objectID().toHexString();
60-
return [
61-
{
62-
name: 'root',
63-
id: r,
64-
_id: r,
65-
children: [b, a, c],
66-
fileType: 'folder',
67-
content: ''
68-
},
69-
{
70-
name: 'sketch.js',
71-
content: defaultSketch,
72-
id: a,
73-
_id: a,
74-
isSelectedFile: true,
75-
fileType: 'file',
76-
children: []
77-
},
78-
{
79-
name: 'index.html',
80-
content: defaultHTML,
81-
id: b,
82-
_id: b,
83-
fileType: 'file',
84-
children: []
85-
},
86-
{
87-
name: 'style.css',
88-
content: defaultCSS,
89-
id: c,
90-
_id: c,
91-
fileType: 'file',
92-
children: []
93-
}
94-
];
95-
}
96-
9720
function sortedChildrenId(state, children) {
9821
const childrenArray = state.filter((file) => children.includes(file.id));
9922
childrenArray.sort((a, b) => (a.name > b.name ? 1 : -1));

client/modules/Preview/previewIndex.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import {
88
MessageTypes,
99
dispatchMessage
1010
} from '../../utils/dispatcher';
11-
import { filesReducer, initialState, setFiles } from './filesReducer';
11+
import { filesReducer, setFiles } from './filesReducer';
1212
import EmbedFrame from './EmbedFrame';
1313
import getConfig from '../../utils/getConfig';
14+
import { initialState } from '../IDE/reducers/files';
1415

1516
const GlobalStyle = createGlobalStyle`
1617
body {

client/testData/testReduxStore.js

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { initialState as initialFilesState } from '../modules/IDE/reducers/files';
2+
13
const mockProjects = [
24
{
35
name: 'testsketch1',
@@ -43,47 +45,7 @@ const initialTestState = {
4345
runtimeErrorWarningVisible: true,
4446
parentId: undefined
4547
},
46-
files: [
47-
{
48-
name: 'root',
49-
id: '606fc1c46045e19ca2ee2648',
50-
_id: '606fc1c46045e19ca2ee2648',
51-
children: [
52-
'606fc1c46045e19ca2ee2646',
53-
'606fc1c46045e19ca2ee2645',
54-
'606fc1c46045e19ca2ee2647'
55-
],
56-
fileType: 'folder',
57-
content: ''
58-
},
59-
{
60-
name: 'sketch.js',
61-
content:
62-
'function setup() { createCanvas(400, 400); } function draw() { background(220); }',
63-
id: '606fc1c46045e19ca2ee2645',
64-
_id: '606fc1c46045e19ca2ee2645',
65-
isSelectedFile: true,
66-
fileType: 'file',
67-
children: []
68-
},
69-
{
70-
name: 'index.html',
71-
content: `<!DOCTYPE html> <html lang="en"> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/addons/p5.sound.min.js"></script> <link rel="stylesheet" type="text/css" href="style.css"> <meta charset="utf-8" /> </head> <body> <main> </main> <script src="sketch.js"></script> </body> </html>`,
72-
id: '606fc1c46045e19ca2ee2646',
73-
_id: '606fc1c46045e19ca2ee2646',
74-
fileType: 'file',
75-
children: []
76-
},
77-
{
78-
name: 'style.css',
79-
content:
80-
'html, body { margin: 0; padding: 0; } canvas { display: block; } ',
81-
id: '606fc1c46045e19ca2ee2647',
82-
_id: '606fc1c46045e19ca2ee2647',
83-
fileType: 'file',
84-
children: []
85-
}
86-
],
48+
files: initialFilesState(),
8749
preferences: {
8850
fontSize: 18,
8951
autosave: true,

server/domain-objects/createDefaultFiles.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const defaultSketch = `function setup() {
1+
export const defaultSketch = `function setup() {
22
createCanvas(400, 400);
33
}
44
55
function draw() {
66
background(220);
77
}`;
88

9-
const defaultHTML = `<!DOCTYPE html>
9+
export const defaultHTML = `<!DOCTYPE html>
1010
<html lang="en">
1111
<head>
1212
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.js"></script>
@@ -23,7 +23,7 @@ const defaultHTML = `<!DOCTYPE html>
2323
</html>
2424
`;
2525

26-
const defaultCSS = `html, body {
26+
export const defaultCSS = `html, body {
2727
margin: 0;
2828
padding: 0;
2929
}

server/scripts/examples.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,10 @@ import Q from 'q';
33
import mongoose from 'mongoose';
44
import objectID from 'bson-objectid';
55
import shortid from 'shortid';
6+
import { defaultCSS, defaultHTML } from '../domain-objects/createDefaultFiles';
67
import User from '../models/user';
78
import Project from '../models/project';
89

9-
const defaultHTML = `<!DOCTYPE html>
10-
<html lang="en">
11-
<head>
12-
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.js"></script>
13-
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/addons/p5.sound.min.js"></script>
14-
<link rel="stylesheet" type="text/css" href="style.css">
15-
<meta charset="utf-8" />
16-
</head>
17-
<body>
18-
<main></main>
19-
<script src="sketch.js"></script>
20-
</body>
21-
</html>
22-
`;
23-
24-
const defaultCSS = `html, body {
25-
margin: 0;
26-
padding: 0;
27-
}
28-
canvas {
29-
display: block;
30-
}
31-
`;
32-
3310
const clientId = process.env.GITHUB_ID;
3411
const clientSecret = process.env.GITHUB_SECRET;
3512

0 commit comments

Comments
 (0)