Skip to content

Commit a0a5fd9

Browse files
committed
Initial Commit
- Setup Webpack config with react, typescript and redux - Create Store with simple reducer - Add Dashboard component
0 parents  commit a0a5fd9

25 files changed

+533
-0
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
insert_final_newline = false
15+
trim_trailing_whitespace = false

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.vscode
2+
.idea
3+
.DS_STORE
4+
node_modules
5+
.module-cache
6+
*.log*
7+
build
8+
dist

.prettierrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"arrowParens": "always",
3+
"semi": true,
4+
"useTabs": false,
5+
"tabWidth": 2,
6+
"bracketSpacing": true,
7+
"singleQuote": true,
8+
"jsxBracketSameLine": false,
9+
"printWidth": 120
10+
}

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# CodeCharacter Web
2+
Web App for the frontend of CodeCharacter 2019
3+
4+
## Installation
5+
6+
```
7+
$ npm ci
8+
```
9+
10+
## Running
11+
12+
```
13+
$ npm start
14+
```
15+
16+
## Build
17+
18+
```
19+
$ npm run build
20+
```
21+
22+
## Format code (using [Prettier](https://github.com/prettier/prettier))
23+
24+
```
25+
$ npm run prettier
26+
```

package.json

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"name": "codecharacter-web-2019",
3+
"version": "1.0.0",
4+
"private": true,
5+
"description": "Web App for CodeCharacter",
6+
"main": "index.js",
7+
"scripts": {
8+
"predeploy": "npm run build",
9+
"test": "echo \"Error: no test specified\" && exit 1",
10+
"start": "webpack-dev-server --mode development --hot --progress --color --port 3000 --open",
11+
"build": "webpack -p --progress --colors",
12+
"prettier": "prettier --write \"src/**/*.{ts,tsx,css}\""
13+
},
14+
"devDependencies": {
15+
"@babel/core": "^7.1.2",
16+
"@types/classnames": "2.2.6",
17+
"@types/history": "4.7.1",
18+
"@types/node": "10.11.7",
19+
"@types/react": "16.4.16",
20+
"@types/react-dom": "16.0.9",
21+
"@types/react-redux": "6.0.9",
22+
"@types/react-router": "4.0.32",
23+
"@types/redux-actions": "2.3.1",
24+
"@types/webpack": "4.4.16",
25+
"@types/webpack-env": "1.13.6",
26+
"babel-loader": "^8.0.4",
27+
"css-loader": "^1.0.0",
28+
"file-loader": "^2.0.0",
29+
"gh-pages": "^2.0.1",
30+
"html-loader": "^1.0.0-alpha.0",
31+
"html-webpack-plugin": "^4.0.0-alpha",
32+
"mini-css-extract-plugin": "^0.4.4",
33+
"postcss": "^7.0.5",
34+
"postcss-browser-reporter": "^0.5.0",
35+
"postcss-import": "^12.0.0",
36+
"postcss-loader": "^3.0.0",
37+
"postcss-preset-env": "^6.1.1",
38+
"postcss-reporter": "^6.0.0",
39+
"postcss-url": "^8.0.0",
40+
"prettier": "^1.14.3",
41+
"react-hot-loader": "^4.3.11",
42+
"redux-devtools-extension": "^2.13.5",
43+
"style-loader": "^0.23.1",
44+
"ts-loader": "^5.2.1",
45+
"typescript": "^3.1.3",
46+
"url-loader": "^1.1.2",
47+
"webpack": "^4.20.2",
48+
"webpack-cleanup-plugin": "^0.5.1",
49+
"webpack-cli": "^3.1.2",
50+
"webpack-dev-server": "^3.1.9"
51+
},
52+
"dependencies": {
53+
"@types/react-split-pane": "^0.1.67",
54+
"classnames": "^2.2.6",
55+
"react": "^16.5.2",
56+
"react-ace": "^6.2.0",
57+
"react-dom": "^16.5.2",
58+
"react-redux": "^5.0.7",
59+
"react-router": "^4.3.1",
60+
"react-split-pane": "^0.1.84",
61+
"redux": "^4.0.1",
62+
"redux-actions": "^2.6.1"
63+
}
64+
}

src/app/actions/dashboard.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// import { createAction } from 'redux-actions';
2+
3+
export namespace DashboardActions {
4+
export enum Type {}
5+
}
6+
7+
export type DashboardActions = Omit<typeof DashboardActions, 'Type'>;

src/app/actions/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from 'app/actions/dashboard';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as React from 'react';
2+
import AceEditor from 'react-ace';
3+
4+
import 'brace/theme/monokai';
5+
6+
export class Editor extends React.Component<Editor.Props, Editor.State> {
7+
render() {
8+
return (
9+
<AceEditor
10+
mode="c_cpp"
11+
theme="monokai"
12+
name="editor"
13+
style={{
14+
height: window.innerHeight,
15+
width: '100%'
16+
}}
17+
editorProps={{ $blockScrolling: true }}
18+
/>
19+
);
20+
}
21+
}
22+
23+
export namespace Editor {
24+
export interface Props {}
25+
export interface State {}
26+
}
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.Resizer.horizontal {
2+
background: #000;
3+
opacity: 0.2;
4+
width: 2px;
5+
z-index: 1;
6+
-moz-box-sizing: border-box;
7+
-webkit-box-sizing: border-box;
8+
box-sizing: border-box;
9+
-moz-background-clip: padding;
10+
-webkit-background-clip: padding;
11+
background-clip: padding-box;
12+
height: 11px;
13+
margin: -5px 0;
14+
border-top: 5px solid rgba(255, 255, 255, 0);
15+
border-bottom: 5px solid rgba(255, 255, 255, 0);
16+
cursor: row-resize;
17+
width: 100%;
18+
}
19+
20+
.Resizer.horizontal:hover {
21+
border-top: 5px solid rgba(0, 0, 0, 0.5);
22+
border-bottom: 5px solid rgba(0, 0, 0, 0.5);
23+
-webkit-transition: all 2s ease;
24+
transition: all 2s ease;
25+
}
26+
27+
.Resizer.vertical {
28+
background: #000;
29+
opacity: 0.2;
30+
width: 2px;
31+
z-index: 1;
32+
-moz-box-sizing: border-box;
33+
-webkit-box-sizing: border-box;
34+
box-sizing: border-box;
35+
-moz-background-clip: padding;
36+
-webkit-background-clip: padding;
37+
background-clip: padding-box;
38+
width: 11px;
39+
margin: 0 -5px;
40+
border-left: 5px solid rgba(255, 255, 255, 0);
41+
border-right: 5px solid rgba(255, 255, 255, 0);
42+
cursor: col-resize;
43+
}
44+
45+
.Resizer.vertical:hover {
46+
-webkit-transition: all 2s ease;
47+
transition: all 2s ease;
48+
border-left: 5px solid rgba(0, 0, 0, 0.5);
49+
border-right: 5px solid rgba(0, 0, 0, 0.5);
50+
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as React from 'react';
2+
import * as style from './index.css';
3+
import SplitPane from 'react-split-pane';
4+
import { Editor } from './Code/editor';
5+
6+
export namespace Dashboard {
7+
export interface Props {}
8+
9+
export interface State {
10+
code: String;
11+
}
12+
}
13+
14+
export class Dashboard extends React.Component<Dashboard.Props, Dashboard.State> {
15+
constructor(props: Dashboard.Props, context?: any) {
16+
super(props, context);
17+
this.state = {
18+
code: ''
19+
};
20+
}
21+
22+
render() {
23+
return (
24+
<SplitPane split="vertical" minSize={50} defaultSize={100} resizerClassName={style.vertical}>
25+
<Editor />
26+
<SplitPane split="horizontal" resizerClassName={style.horizontal}>
27+
<div />
28+
<div />
29+
</SplitPane>
30+
</SplitPane>
31+
);
32+
}
33+
}

src/app/index.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react';
2+
import { Route, Switch } from 'react-router';
3+
import { Dashboard } from 'app/components/Dashboard';
4+
import { hot } from 'react-hot-loader';
5+
6+
export const App = hot(module)(() => (
7+
<Switch>
8+
<Route path="/dashboard" component={Dashboard} />
9+
</Switch>
10+
));

src/app/middleware/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './logger';

src/app/middleware/logger.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Middleware } from 'redux';
2+
3+
export const logger: Middleware = (store) => (next) => (action) => {
4+
if (process.env.NODE_ENV !== 'production') {
5+
console.log(action);
6+
}
7+
return next(action);
8+
};

src/app/models/index.ts

Whitespace-only changes.

src/app/reducers/dashboard.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { handleActions } from 'redux-actions';
2+
import { RootState } from './state';
3+
// import { DashboardActions } from 'app/actions/dashboard';
4+
5+
const initialState: RootState = {};
6+
7+
export interface Action {}
8+
9+
export const DashboardReducer = handleActions<RootState, Action>({}, initialState);

src/app/reducers/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { combineReducers } from 'redux';
2+
import { RootState } from './state';
3+
import { DashboardReducer } from './dashboard';
4+
5+
export { RootState };
6+
7+
export const rootReducer = combineReducers<RootState>({
8+
dashboard: DashboardReducer as any
9+
});

src/app/reducers/state.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export interface RootState {}

src/app/store/index.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Store, createStore, applyMiddleware } from 'redux';
2+
import { composeWithDevTools } from 'redux-devtools-extension';
3+
import { logger } from 'app/middleware';
4+
import { RootState, rootReducer } from 'app/reducers';
5+
6+
export function configureStore(initialState?: RootState): Store<RootState> {
7+
let middleware = applyMiddleware(logger);
8+
9+
if (process.env.NODE_ENV !== 'production') {
10+
middleware = composeWithDevTools(middleware);
11+
}
12+
13+
const store = createStore(rootReducer as any, initialState as any, middleware) as Store<RootState>;
14+
15+
if (module.hot) {
16+
module.hot.accept('app/reducers', () => {
17+
const nextReducer = require('app/reducers');
18+
store.replaceReducer(nextReducer);
19+
});
20+
}
21+
22+
return store;
23+
}

src/app/utils/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function omit<T extends object, K extends keyof T>(target: T, ...omitKeys: K[]): Omit<T, K> {
2+
return (Object.keys(target) as K[]).reduce(
3+
(res, key) => {
4+
if (!omitKeys.includes(key)) {
5+
res[key] = target[key];
6+
}
7+
return res;
8+
},
9+
{} as any
10+
);
11+
}

src/assets/index.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<script src="//cdn.polyfill.io/v2/polyfill.min.js"></script>
6+
<title>Code Character</title>
7+
</head>
8+
<body>
9+
<div id="root"></div>
10+
</body>
11+
</html>

src/main.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as React from 'react';
2+
import * as ReactDOM from 'react-dom';
3+
import { Provider } from 'react-redux';
4+
import { createBrowserHistory } from 'history';
5+
import { configureStore } from 'app/store';
6+
import { Router } from 'react-router';
7+
import { App } from './app';
8+
9+
// prepare store
10+
const history = createBrowserHistory();
11+
const store = configureStore();
12+
13+
ReactDOM.render(
14+
<Provider store={store}>
15+
<Router history={history}>
16+
<App />
17+
</Router>
18+
</Provider>,
19+
document.getElementById('root')
20+
);

tsconfig.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"sourceMap": true,
4+
"target": "es5",
5+
"jsx": "react",
6+
"module": "es6",
7+
"moduleResolution": "node",
8+
"experimentalDecorators": true,
9+
"declaration": false,
10+
"removeComments": true,
11+
"noImplicitReturns": true,
12+
"noUnusedLocals": true,
13+
"strict": true,
14+
"outDir": "build",
15+
"lib": ["es6", "es7", "dom"],
16+
"baseUrl": "src",
17+
"paths": {
18+
"app/*": ["./app/*"]
19+
}
20+
},
21+
"exclude": ["build", "node_modules"]
22+
}

types/global.d.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** Global definitions for development **/
2+
3+
// for style loader
4+
declare module '*.css' {
5+
const styles: any;
6+
export = styles;
7+
}
8+
9+
// Omit type https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377567046
10+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
11+
type PartialPick<T, K extends keyof T> = Partial<T> & Pick<T, K>;

0 commit comments

Comments
 (0)