Skip to content

Commit

Permalink
Refactor(frontend): better project structure for scale
Browse files Browse the repository at this point in the history
* merge container and its corresponding component file
* move related reducer, action, api, and saga files into one service folder
* add css-modules support
* add *.spec.tsx test files
  • Loading branch information
Armour committed Aug 11, 2018
1 parent d4a0012 commit e235c45
Show file tree
Hide file tree
Showing 107 changed files with 957 additions and 1,048 deletions.
1 change: 0 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
environment:
nodejs_version: "10"
NODE_ENV: production

install:
- ps: Install-Product node $env:nodejs_version
Expand Down
2 changes: 1 addition & 1 deletion backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ server.listen(port, (error) => {
if (isProduction) {
console.info(`\nExpress: Listening on port ${port}, open up http://localhost:${port}/ in your broswer!\n`.green);
} else {
console.info(`\nExpress: Listening on port ${port}, now you can access api on http://localhost:${port}/ \n`.green);
console.info(`\nExpress: Serve api on http://localhost:${port}/ \n`);
}
});

Expand Down
16 changes: 15 additions & 1 deletion frontend/public/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta content="ie=edge" http-equiv="x-ua-compatible">
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
<meta content="Full-stack boilerplate that using express with webpack, react and typescirpt!" name="description">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
Expand All @@ -24,5 +23,20 @@
To begin the development, run `yarn dev`.
To run in production mode, use `yarn prod`.
-->
<script>
// Async load Google Material Icons, eliminate render-blocking resources.
// See https://github.com/typekit/webfontloader#get-started for details.
WebFontConfig = {
google: {
families: ['Material Icons']
}
};
(function (d) {
var wf = d.createElement('script'), s = d.scripts[0];
wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js';
wf.async = true;
s.parentNode.insertBefore(wf, s);
})(document);
</script>
</body>
</html>
12 changes: 3 additions & 9 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { ConnectedRouter } from 'connected-react-router';
import { History } from 'history';
import * as React from 'react';
import { Provider } from 'react-redux';
import { Store } from 'redux';

import { ConnectedRouter } from 'connected-react-router';
import { History } from 'history';

import { router } from 'router';
import { IGlobalState } from 'types';

import 'materialize-css';
import 'prismjs/prism.js';
import 'prismjs/themes/prism.css';
import 'sass/index.scss';
import { IGlobalState } from 'types/global';

interface IAppProps {
store: Store<IGlobalState>;
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/actions/index.tsx

This file was deleted.

1 change: 0 additions & 1 deletion frontend/src/apis/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';

import { Link } from 'react-router-dom';

import { upperCaseFirstChar } from 'utils';
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Dropdown/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dropdown';
58 changes: 0 additions & 58 deletions frontend/src/components/FetchNote.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
footer.page-footer {
@import 'sass/variables';

.footer {
background-color: $primary-color;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as React from 'react';

const styles = require('./footer.scss');

export class Footer extends React.Component {
public render() {
return (
<footer className='page-footer'>
<footer className={`page-footer ${styles.footer}`}>
<div className='container'>
<div className='row'>
<div className='col l6 s12'>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './footer';
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
nav {
@import 'sass/variables';

.header {
background-color: $primary-color;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import * as React from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';

import { Dropdown } from './Dropdown';
import { Dropdown } from 'components/Dropdown';
import { IGlobalState } from 'types/global';

export interface IHeaderProps {
const styles = require('./header.scss');

// Component

interface IHeaderProps {
dropdownLists: string[];
pathname: string;
}

export class Header extends React.Component<IHeaderProps> {
class HeaderComponent extends React.Component<IHeaderProps> {
public checkActive(urls: string[]) {
let active = false;
urls.forEach((url) => {
Expand All @@ -27,7 +33,7 @@ export class Header extends React.Component<IHeaderProps> {
public render() {
return (
<div>
<nav>
<nav className={styles.header}>
<div className='nav-wrapper'>
<div className='container'>
<a className='brand-logo'><Link to='/'>Logo</Link></a>
Expand Down Expand Up @@ -55,3 +61,15 @@ export class Header extends React.Component<IHeaderProps> {
);
}
}

// Container

const mapStateToProps = (state: IGlobalState): IHeaderProps => ({
dropdownLists: ['parallax'],
pathname: state.router!.location.pathname,
});

export const Header = connect(
mapStateToProps,
null,
)(HeaderComponent);
1 change: 1 addition & 0 deletions frontend/src/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './header';
34 changes: 0 additions & 34 deletions frontend/src/components/TodoFilter.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions frontend/src/components/TodoFooter.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions frontend/src/components/TodoLayout.tsx

This file was deleted.

40 changes: 0 additions & 40 deletions frontend/src/components/TodoList.tsx

This file was deleted.

35 changes: 0 additions & 35 deletions frontend/src/containers/FetchNoteContainer.tsx

This file was deleted.

14 changes: 0 additions & 14 deletions frontend/src/containers/HeaderContainer.tsx

This file was deleted.

Loading

0 comments on commit e235c45

Please sign in to comment.