Skip to content

Commit 42afd7a

Browse files
committed
Re-structure project, optimize import paths and fix code styles
1 parent 59e4920 commit 42afd7a

36 files changed

+264
-235
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ trim_trailing_whitespace = true
1010
indent_style = space
1111
indent_size = 4
1212

13+
[config/**.js]
14+
indent_style = space
15+
indent_size = 2
16+
1317
[{*.json,*.yml}]
1418
indent_style = space
1519
indent_size = 2

config/webpack.config.dev.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
88
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
99
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
1010
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
11+
const TSConfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
1112
const getClientEnvironment = require('./env');
1213
const paths = require('./paths');
1314

@@ -95,7 +96,6 @@ module.exports = {
9596
'.jsx',
9697
],
9798
alias: {
98-
9999
// Support React Native Web
100100
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
101101
'react-native': 'react-native-web',
@@ -107,6 +107,8 @@ module.exports = {
107107
// please link the files into your node_modules/ and let module-resolution kick in.
108108
// Make sure your source files are compiled, as they will not be processed in any way.
109109
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
110+
// Support paths configurations in tsconfig.json
111+
new TSConfigPathsPlugin(),
110112
],
111113
},
112114
module: {

config/webpack.config.prod.js

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const ManifestPlugin = require('webpack-manifest-plugin');
99
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1010
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
1111
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
12+
const TSConfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
1213
const paths = require('./paths');
1314
const getClientEnvironment = require('./env');
1415

@@ -111,6 +112,8 @@ module.exports = {
111112
// please link the files into your node_modules/ and let module-resolution kick in.
112113
// Make sure your source files are compiled, as they will not be processed in any way.
113114
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
115+
// Support paths configurations in tsconfig.json
116+
new TSConfigPathsPlugin(),
114117
],
115118
},
116119
module: {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"sw-precache-webpack-plugin": "0.11.4",
5858
"ts-jest": "^20.0.7",
5959
"ts-loader": "^2.3.7",
60+
"tsconfig-paths-webpack-plugin": "^3.2.0",
6061
"tslint": "^5.7.0",
6162
"tslint-loader": "^3.5.3",
6263
"tslint-react": "^3.2.0",

src/components/Article.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import './Article.scss';
22
import React from 'react';
33
import { RouteComponentProps } from 'react-router';
44
import { Card, Tag } from 'antd';
5-
import { Article as ArticleType, ArticleStatus, nullArticle } from '../types';
5+
import { Article as ArticleType, ArticleStatus, nullArticle } from '@/types';
66
import Loading from './parts/Loading';
77
import WithSidebar from './parts/WithSidebar';
8-
import renderMarkdown from '../libs/markdown';
8+
import renderMarkdown from '@/libs/markdown';
99
import gql from 'graphql-tag';
10-
import { client as apollo } from '../apollo';
10+
import { client as apollo } from '@/apollo';
1111

1212
enum Status {
1313
Loading,

src/components/EditArticle.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import './parts/Editor.scss';
22
import React from 'react';
3-
import { Article, nullArticle, User } from '../types';
4-
import { State } from '../reducers';
5-
import { DISABLE_IMMERSIVE, ENABLE_IMMERSIVE } from '../actions';
3+
import { Article, nullArticle, User } from '@/types';
4+
import { State } from '@/reducers';
5+
import { DISABLE_IMMERSIVE, ENABLE_IMMERSIVE } from '@/actions';
66
import { connect, Dispatch } from 'react-redux';
77
import { Redirect, RouteComponentProps } from 'react-router';
88
import { message } from 'antd';
99
import gql from 'graphql-tag';
1010
import Editor from './parts/Editor';
11-
import { client as apollo } from '../apollo';
12-
import { errorText, later } from '../libs/utils';
11+
import { client as apollo } from '@/apollo';
12+
import { errorText, later } from '@/libs/utils';
1313
import Loading from './parts/Loading';
1414

1515
enum EditArticleStatus {

src/components/Home.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import React from 'react';
33
import { RouteComponentProps } from 'react-router';
44
import { Link } from 'react-router-dom';
55
import { Button, Card, Layout, Pagination, Tag } from 'antd';
6-
import { Article } from '../types';
6+
import { Article } from '@/types';
77
import WithSidebar from './parts/WithSidebar';
8-
import renderMarkdown from '../libs/markdown';
8+
import renderMarkdown from '@/libs/markdown';
99
import gql from 'graphql-tag';
10-
import { client as apollo } from '../apollo';
10+
import { client as apollo } from '@/apollo';
1111

1212
interface HomeRouterProps {
1313
page: string;
@@ -32,6 +32,7 @@ export default class Home extends React.Component<HomeProps, HomeState> {
3232
}
3333

3434
async getArticles() {
35+
// @TODO: Page
3536
const page = this.getPage();
3637

3738
let response = await apollo.query<{ latestArticles: Array<Article> }>({

src/components/Join.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import './Join.scss';
22
import React, { FormEvent } from 'react';
3-
import { JoinInfo, User } from '../types';
4-
import { State } from '../reducers';
3+
import { JoinInfo, User } from '@/types';
4+
import { State } from '@/reducers';
55
import { connect, Dispatch } from 'react-redux';
66
import { Button, Card, Form, Icon, Input, message, Tag } from 'antd';
77
import { Redirect, RouteComponentProps } from 'react-router';
88
import { Link } from 'react-router-dom';
99
import Loading from './parts/Loading';
1010
import WithSidebar from './parts/WithSidebar';
1111
import RegionMap from './parts/RegionMap';
12-
import { names as regionNames } from '../libs/regions';
13-
import { errorText } from '../libs/utils';
14-
import { client as apollo } from '../apollo';
12+
import { names as regionNames } from '@/libs/regions';
13+
import { errorText } from '@/libs/utils';
14+
import { client as apollo } from '@/apollo';
1515
import gql from 'graphql-tag';
1616

1717
interface BindingEvent {

src/components/Login.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import './Login.scss';
22
import React from 'react';
3-
import { User } from '../types';
4-
import { State } from '../reducers';
5-
import { GOOGLE_SIGNED_IN, LOGIN_SUCCESS } from '../actions';
3+
import { User } from '@/types';
4+
import { State } from '@/reducers';
5+
import { GOOGLE_SIGNED_IN, LOGIN_SUCCESS } from '@/actions';
66
import { connect, Dispatch } from 'react-redux';
77
import { Redirect, RouteComponentProps } from 'react-router';
88
import { Card } from 'antd';
99
import gql from 'graphql-tag';
10-
import { client as apollo } from '../apollo';
11-
import { signin2 } from '../libs/googleAuth2';
10+
import { client as apollo } from '@/apollo';
11+
import { signin2 } from '@/libs/googleAuth2';
1212

1313
interface LoginProps extends RouteComponentProps<{}> {
1414
user: User | null;

src/components/NewArticle.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import './parts/Editor.scss';
22
import React from 'react';
3-
import { Article, nullArticle, User } from '../types';
4-
import { State } from '../reducers';
3+
import { Article, nullArticle, User } from '@/types';
4+
import { State } from '@/reducers';
55
import { connect, Dispatch } from 'react-redux';
66
import { Redirect, RouteComponentProps } from 'react-router';
77
import { message } from 'antd';
88
import gql from 'graphql-tag';
99
import Editor from './parts/Editor';
10-
import { client as apollo } from '../apollo';
11-
import { errorText, later } from '../libs/utils';
12-
import { DISABLE_IMMERSIVE, ENABLE_IMMERSIVE } from '../actions';
10+
import { client as apollo } from '@/apollo';
11+
import { errorText, later } from '@/libs/utils';
12+
import { DISABLE_IMMERSIVE, ENABLE_IMMERSIVE } from '@/actions';
1313

1414
enum NewArticleStatus {
1515
Loading,

src/components/Profile.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import './Profile.scss';
22
import React from 'react';
33
import { Redirect, RouteComponentProps, withRouter } from 'react-router';
4-
import { Article, User } from '../types';
4+
import { Article, User } from '@/types';
55
import { Card, Icon, Pagination, Tag } from 'antd';
66
import { Link } from 'react-router-dom';
77
import Loading from './parts/Loading';
88
import WithSidebar from './parts/WithSidebar';
99
import ProfileSidebar from './parts/ProfileSidebar';
1010
import ArticleTools from './parts/ArticleTools';
1111
import { connect, Dispatch } from 'react-redux';
12-
import { State } from '../reducers';
12+
import { State } from '@/reducers';
1313
import gql from 'graphql-tag';
14-
import { resizeGoogleAvatar } from '../libs/utils';
15-
import { client as apollo } from '../apollo';
16-
import renderMarkdown from '../libs/markdown';
14+
import { resizeGoogleAvatar } from '@/libs/utils';
15+
import { client as apollo } from '@/apollo';
16+
import renderMarkdown from '@/libs/markdown';
1717

1818
enum ProfileStatus {
1919
Loading,

src/components/Register.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import './Register.scss';
22
import React, { FormEvent } from 'react';
3-
import { User } from '../types';
4-
import { State } from '../reducers';
3+
import { User } from '@/types';
4+
import { State } from '@/reducers';
55
import { connect, Dispatch } from 'react-redux';
66
import { Redirect, RouteComponentProps } from 'react-router';
77
import { Alert, Button, Card, Form, Icon, Input, Radio } from 'antd';
88
import gql from 'graphql-tag';
9-
import { client as apollo } from '../apollo';
10-
import { AUTH_RESET, LOGIN_SUCCESS } from '../actions';
11-
import { errorText } from '../libs/utils';
12-
import { auth2 } from '../libs/googleAuth2';
9+
import { client as apollo } from '@/apollo';
10+
import { AUTH_RESET, LOGIN_SUCCESS } from '@/actions';
11+
import { errorText } from '@/libs/utils';
12+
import { auth2 } from '@/libs/googleAuth2';
1313

1414
interface LoginProps extends RouteComponentProps<{}> {
1515
user: User | null;

src/components/admin/Admin.tsx

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import './Admin.css';
22
import React from 'react';
3-
import { User } from '../../types';
4-
import { State } from '../../reducers';
3+
import { User } from '@/types';
4+
import { State } from '@/reducers';
55
import { connect, Dispatch } from 'react-redux';
66
import { Layout, Menu } from 'antd';
77
import { Redirect, Route, RouteComponentProps, withRouter } from 'react-router';
88
import { Link, Switch } from 'react-router-dom';
99
import Overview from './Overview';
10-
import AllArticles from './AllArticles';
11-
import PendingArticles from './PendingArticles';
12-
import PublishedArticles from './PublishedArticles';
13-
import PreviewArticle from './PreviewArticle';
10+
import AllArticles from './articles/AllArticles';
11+
import PendingArticles from './articles/PendingArticles';
12+
import PublishedArticles from './articles/PublishedArticles';
13+
import PreviewArticle from './articles/PreviewArticle';
1414

1515
const { Sider } = Layout;
1616

@@ -26,7 +26,11 @@ export class Admin extends React.PureComponent<AdminProps> {
2626
return <Redirect to="/" />;
2727
}
2828

29-
let current = location.pathname.substr(7).split('/')[0];
29+
let current = location.pathname
30+
.substr(7)
31+
.split('/')
32+
.filter(s => s.trim())
33+
.join('/');
3034

3135
if (current === '') {
3236
current = 'overview';
@@ -42,14 +46,14 @@ export class Admin extends React.PureComponent<AdminProps> {
4246
>
4347
<Menu.Item key="overview"><Link to="/admin">Overview</Link></Menu.Item>
4448
<Menu.ItemGroup key="articles" title="文章管理">
45-
<Menu.Item key="allArticles">
46-
<Link to="/admin/allArticles">所有文章</Link>
49+
<Menu.Item key="articles/all">
50+
<Link to="/admin/articles/all">所有文章</Link>
4751
</Menu.Item>
48-
<Menu.Item key="pendingArticles">
49-
<Link to="/admin/pendingArticles">待审文章</Link>
52+
<Menu.Item key="articles/pending">
53+
<Link to="/admin/articles/pending">待审文章</Link>
5054
</Menu.Item>
51-
<Menu.Item key="publishedArticles">
52-
<Link to="/admin/publishedArticles">已发布文章</Link>
55+
<Menu.Item key="articles/published">
56+
<Link to="/admin/articles/published">已发布文章</Link>
5357
</Menu.Item>
5458
</Menu.ItemGroup>
5559
</Menu>
@@ -58,10 +62,10 @@ export class Admin extends React.PureComponent<AdminProps> {
5862
<div className={'flex-spacer ' + (this.props.immersive || 'container-fluid panel-container')}>
5963
<Switch>
6064
<Route exact path="/admin" component={Overview} />
61-
<Route path="/admin/allArticles" component={AllArticles} />
62-
<Route path="/admin/pendingArticles" component={PendingArticles} />
63-
<Route path="/admin/publishedArticles" component={PublishedArticles} />
64-
<Route path="/admin/previewArticle/:id(\w+)" component={PreviewArticle} />
65+
<Route path="/admin/articles/all" component={AllArticles} />
66+
<Route path="/admin/articles/pending" component={PendingArticles} />
67+
<Route path="/admin/articles/published" component={PublishedArticles} />
68+
<Route path="/admin/articles/preview/:id(\w+)" component={PreviewArticle} />
6569
</Switch>
6670
</div>
6771
</Layout>

src/components/admin/AllArticles.tsx

-43
This file was deleted.

src/components/admin/PendingArticles.tsx

-46
This file was deleted.

0 commit comments

Comments
 (0)