diff --git a/client/modules/IDE/reducers/files.js b/client/modules/IDE/reducers/files.js
index ec9aaec830..42635fe3e4 100644
--- a/client/modules/IDE/reducers/files.js
+++ b/client/modules/IDE/reducers/files.js
@@ -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 = `
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-`;
-
-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();
diff --git a/client/modules/Preview/filesReducer.js b/client/modules/Preview/filesReducer.js
index 63ffed9cfb..098ae54824 100644
--- a/client/modules/Preview/filesReducer.js
+++ b/client/modules/Preview/filesReducer.js
@@ -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 = `
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-`;
-
-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]);
@@ -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));
diff --git a/client/modules/Preview/previewIndex.jsx b/client/modules/Preview/previewIndex.jsx
index 5f89a688ce..b590dff399 100644
--- a/client/modules/Preview/previewIndex.jsx
+++ b/client/modules/Preview/previewIndex.jsx
@@ -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 {
diff --git a/client/testData/testReduxStore.js b/client/testData/testReduxStore.js
index 5e475df75e..86a01a683f 100644
--- a/client/testData/testReduxStore.js
+++ b/client/testData/testReduxStore.js
@@ -1,3 +1,5 @@
+import { initialState as initialFilesState } from '../modules/IDE/reducers/files';
+
const mockProjects = [
{
name: 'testsketch1',
@@ -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: ` `,
- 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,
diff --git a/server/domain-objects/createDefaultFiles.js b/server/domain-objects/createDefaultFiles.js
index 3f40d43ab7..690b5b0007 100644
--- a/server/domain-objects/createDefaultFiles.js
+++ b/server/domain-objects/createDefaultFiles.js
@@ -1,4 +1,4 @@
-const defaultSketch = `function setup() {
+export const defaultSketch = `function setup() {
createCanvas(400, 400);
}
@@ -6,7 +6,7 @@ function draw() {
background(220);
}`;
-const defaultHTML = `
+export const defaultHTML = `
@@ -23,7 +23,7 @@ const defaultHTML = `
`;
-const defaultCSS = `html, body {
+export const defaultCSS = `html, body {
margin: 0;
padding: 0;
}
diff --git a/server/scripts/examples.js b/server/scripts/examples.js
index a4d54d6400..ddb5d5ad6b 100644
--- a/server/scripts/examples.js
+++ b/server/scripts/examples.js
@@ -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 = `
-
-
-
-
-
-
-
-
-
-
-
-
-`;
-
-const defaultCSS = `html, body {
- margin: 0;
- padding: 0;
-}
-canvas {
- display: block;
-}
-`;
-
const clientId = process.env.GITHUB_ID;
const clientSecret = process.env.GITHUB_SECRET;