Skip to content

Cleanup: Single source of default project contents #2211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 6 additions & 35 deletions client/modules/IDE/reducers/files.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,12 @@
import objectID from 'bson-objectid';
import * as ActionTypes from '../../../constants';
import {
defaultSketch,
defaultCSS,
defaultHTML
} from '../../../../server/domain-objects/createDefaultFiles';

const defaultSketch = `function setup() {
createCanvas(400, 400);
}

function draw() {
background(220);
}`;

const defaultHTML = `<!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>
`;

const defaultCSS = `html, body {
margin: 0;
padding: 0;
}
canvas {
display: block;
}
`;

const initialState = () => {
export const initialState = () => {
const a = objectID().toHexString();
const b = objectID().toHexString();
const c = objectID().toHexString();
Expand Down
77 changes: 0 additions & 77 deletions client/modules/Preview/filesReducer.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,8 @@
import { useMemo } from 'react';
import objectID from 'bson-objectid';
import blobUtil from 'blob-util';
import mime from 'mime';
import { PLAINTEXT_FILE_REGEX } from '../../../server/utils/fileUtils';

const defaultSketch = `function setup() {
createCanvas(400, 400);
}

function draw() {
background(220);
}`;

const defaultHTML = `<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.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>
`;

const defaultCSS = `html, body {
margin: 0;
padding: 0;
}
canvas {
display: block;
}
`;

// https://gist.github.com/fnky/7d044b94070a35e552f3c139cdf80213
export function useSelectors(state, mapStateToSelectors) {
const selectors = useMemo(() => mapStateToSelectors(state), [state]);
Expand All @@ -52,48 +17,6 @@ export function getFileSelectors(state) {
};
}

export function initialState() {
const a = objectID().toHexString();
const b = objectID().toHexString();
const c = objectID().toHexString();
const r = objectID().toHexString();
return [
{
name: 'root',
id: r,
_id: r,
children: [b, a, c],
fileType: 'folder',
content: ''
},
{
name: 'sketch.js',
content: defaultSketch,
id: a,
_id: a,
isSelectedFile: true,
fileType: 'file',
children: []
},
{
name: 'index.html',
content: defaultHTML,
id: b,
_id: b,
fileType: 'file',
children: []
},
{
name: 'style.css',
content: defaultCSS,
id: c,
_id: c,
fileType: 'file',
children: []
}
];
}

function sortedChildrenId(state, children) {
const childrenArray = state.filter((file) => children.includes(file.id));
childrenArray.sort((a, b) => (a.name > b.name ? 1 : -1));
Expand Down
3 changes: 2 additions & 1 deletion client/modules/Preview/previewIndex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
MessageTypes,
dispatchMessage
} from '../../utils/dispatcher';
import { filesReducer, initialState, setFiles } from './filesReducer';
import { filesReducer, setFiles } from './filesReducer';
import EmbedFrame from './EmbedFrame';
import getConfig from '../../utils/getConfig';
import { initialState } from '../IDE/reducers/files';

const GlobalStyle = createGlobalStyle`
body {
Expand Down
44 changes: 3 additions & 41 deletions client/testData/testReduxStore.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { initialState as initialFilesState } from '../modules/IDE/reducers/files';

const mockProjects = [
{
name: 'testsketch1',
Expand Down Expand Up @@ -43,47 +45,7 @@ const initialTestState = {
runtimeErrorWarningVisible: true,
parentId: undefined
},
files: [
{
name: 'root',
id: '606fc1c46045e19ca2ee2648',
_id: '606fc1c46045e19ca2ee2648',
children: [
'606fc1c46045e19ca2ee2646',
'606fc1c46045e19ca2ee2645',
'606fc1c46045e19ca2ee2647'
],
fileType: 'folder',
content: ''
},
{
name: 'sketch.js',
content:
'function setup() { createCanvas(400, 400); } function draw() { background(220); }',
id: '606fc1c46045e19ca2ee2645',
_id: '606fc1c46045e19ca2ee2645',
isSelectedFile: true,
fileType: 'file',
children: []
},
{
name: 'index.html',
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>`,
id: '606fc1c46045e19ca2ee2646',
_id: '606fc1c46045e19ca2ee2646',
fileType: 'file',
children: []
},
{
name: 'style.css',
content:
'html, body { margin: 0; padding: 0; } canvas { display: block; } ',
id: '606fc1c46045e19ca2ee2647',
_id: '606fc1c46045e19ca2ee2647',
fileType: 'file',
children: []
}
],
files: initialFilesState(),
preferences: {
fontSize: 18,
autosave: true,
Expand Down
6 changes: 3 additions & 3 deletions server/domain-objects/createDefaultFiles.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const defaultSketch = `function setup() {
export const defaultSketch = `function setup() {
createCanvas(400, 400);
}

function draw() {
background(220);
}`;

const defaultHTML = `<!DOCTYPE html>
export const defaultHTML = `<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.js"></script>
Expand All @@ -23,7 +23,7 @@ const defaultHTML = `<!DOCTYPE html>
</html>
`;

const defaultCSS = `html, body {
export const defaultCSS = `html, body {
margin: 0;
padding: 0;
}
Expand Down
25 changes: 1 addition & 24 deletions server/scripts/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,10 @@ import Q from 'q';
import mongoose from 'mongoose';
import objectID from 'bson-objectid';
import shortid from 'shortid';
import { defaultCSS, defaultHTML } from '../domain-objects/createDefaultFiles';
import User from '../models/user';
import Project from '../models/project';

const defaultHTML = `<!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>
`;

const defaultCSS = `html, body {
margin: 0;
padding: 0;
}
canvas {
display: block;
}
`;

const clientId = process.env.GITHUB_ID;
const clientSecret = process.env.GITHUB_SECRET;

Expand Down