Skip to content

Commit b422d70

Browse files
committed
Add skeleton files for scratch paper
1 parent 84a972c commit b422d70

File tree

10 files changed

+47
-15
lines changed

10 files changed

+47
-15
lines changed

src/frontend/common/config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
import { CODE_JS, CODE_JAVA, CODE_CPP } from '/skeletons';
2+
13
const languages = [{
24
name: 'JavaScript',
35
ext: 'js',
46
mode: 'javascript',
7+
skeleton: CODE_JS,
58
}, {
69
name: 'C++',
710
ext: 'cpp',
811
mode: 'c_cpp',
12+
skeleton: CODE_CPP,
913
}, {
1014
name: 'Java',
1115
ext: 'java',
1216
mode: 'java',
13-
}, {
14-
name: 'Python',
15-
ext: 'py',
16-
mode: 'python',
17+
skeleton: CODE_JAVA,
1718
}];
1819

1920
const exts = languages.map(language => language.ext);

src/frontend/components/App/index.jsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ import { CategoryApi, GitHubApi } from '/apis';
2222
import { tracerManager } from '/core';
2323
import { actions } from '/reducers';
2424
import { extension, refineGist } from '/common/util';
25-
import { exts, us } from '/common/config';
26-
import README from '/static/README.md';
27-
import SCRATCH_PAPER from '/static/SCRATCH_PAPER.md';
25+
import { languages, exts, us } from '/common/config';
26+
import { README_MD, SCRATCH_PAPER_MD } from '/skeletons';
2827
import styles from './stylesheet.scss';
2928

3029
loadProgressBar();
@@ -135,15 +134,16 @@ class App extends React.Component {
135134
fetchPromise = CategoryApi.getAlgorithm(categoryKey, algorithmKey)
136135
.then(({ algorithm }) => algorithm);
137136
} else if (gistId === 'new') {
137+
const language = languages.find(language => language.ext === ext);
138138
fetchPromise = Promise.resolve({
139139
titles: ['Scratch Paper', 'Untitled'],
140140
files: [{
141141
name: 'README.md',
142-
content: SCRATCH_PAPER,
142+
content: SCRATCH_PAPER_MD,
143143
contributors: undefined,
144144
}, {
145145
name: `code.${ext}`,
146-
content: '', // TODO: put import statements as default
146+
content: language ? language.skeleton : '', // TODO: put import statements as default
147147
contributors: undefined,
148148
}],
149149
});
@@ -156,7 +156,7 @@ class App extends React.Component {
156156
.then(algorithm => this.props.setCurrent(categoryKey, algorithmKey, gistId, algorithm.titles, algorithm.files))
157157
.catch(() => this.props.setCurrent(undefined, undefined, undefined, ['Algorithm Visualizer'], [{
158158
name: 'README.md',
159-
content: README,
159+
content: README_MD,
160160
contributors: [us],
161161
}]))
162162
.finally(() => {
@@ -245,7 +245,6 @@ class App extends React.Component {
245245
<FontAwesomeIcon fixedWidth icon={faPlus} />,
246246
);
247247

248-
// TODO: let google search within algorithm-visualizer.org
249248
return (
250249
<div className={styles.app}>
251250
<Helmet>
@@ -268,7 +267,7 @@ class App extends React.Component {
268267
<TabContainer className={styles.editor_tab_container} titles={editorTitles} tabIndex={editorTabIndex}
269268
onChangeTabIndex={tabIndex => this.handleChangeEditorTabIndex(tabIndex)}>
270269
{
271-
files.map((file, i) => (
270+
files.map((file, i) => ( // TODO: editor cursor should stay when moved to scratch paper
272271
<CodeEditor key={[...titles, i].join('--')} file={file}
273272
onDeleteFile={file => this.handleDeleteFile(file)} />
274273
))

src/frontend/components/Header/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class Header extends React.Component {
102102
const { gistId, titles } = this.props.current;
103103
const { ext, user } = this.props.env;
104104

105+
// TODO: remove the 'run' button and add 'build' and 'play' buttons
105106
return (
106107
<header className={classes(styles.header, className)}>
107108
<div className={styles.row}>
File renamed without changes.
File renamed without changes.

src/frontend/skeletons/code.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "LogTracer.h"
2+
3+
int main() {
4+
LogTracer logTracer = LogTracer("Scratch Paper");
5+
6+
logTracer.print("Visualize your own algorithm here!");
7+
8+
return 0;
9+
}

src/frontend/skeletons/code.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import org.algorithm_visualizer.tracers.*;
2+
3+
class Main {
4+
public static void main(String[] args) {
5+
LogTracer logTracer = new LogTracer("Scratch Paper");
6+
7+
logTracer.print("Visualize your own algorithm here!");
8+
}
9+
}

src/frontend/skeletons/code.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { LogTracer } from 'algorithm-visualizer';
2+
3+
const logTracer = new LogTracer('Scratch Paper');
4+
5+
logTracer.print('Visualize your own algorithm here!');

src/frontend/skeletons/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { default as CODE_CPP } from 'raw-loader!./code.cpp';
2+
export { default as CODE_JAVA } from 'raw-loader!./code.java';
3+
export { default as CODE_JS } from 'raw-loader!./code.js';
4+
export { default as README_MD } from 'raw-loader!./README.md';
5+
export { default as SCRATCH_PAPER_MD } from 'raw-loader!./SCRATCH_PAPER.md';

webpack.frontend.config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ module.exports = {
4444
},
4545
module: {
4646
rules: [
47-
{ test: /\.(js|jsx)$/, use: 'babel-loader', include: srcPath },
4847
{
48+
test: /\.(js|jsx)$/,
49+
use: 'babel-loader',
50+
include: srcPath,
51+
exclude: path.resolve(srcPath, 'skeletons'),
52+
}, {
4953
test: /\.scss$/,
5054
use: filter([
5155
__DEV__ && 'css-hot-loader',
@@ -63,7 +67,6 @@ module.exports = {
6367
]),
6468
exclude: srcPath,
6569
},
66-
{ test: /\.md$/, use: 'raw-loader' },
6770
],
6871
},
6972
plugins: filter([
@@ -84,4 +87,4 @@ module.exports = {
8487
// new BundleAnalyzerPlugin(),
8588
]),
8689
mode: __DEV__ ? 'development' : 'production',
87-
};
90+
};

0 commit comments

Comments
 (0)