Skip to content

Commit 72392be

Browse files
committed
first commit
0 parents  commit 72392be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+7134
-0
lines changed

.babelrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
"next/babel",
4+
"@zeit/next-typescript/babel"
5+
],
6+
"plugins": [
7+
["@babel/plugin-proposal-decorators", { "legacy": true }]
8+
]
9+
}

.editorconfig

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

.gcloudignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file specifies files that are *not* uploaded to Google Cloud Platform
2+
# using gcloud. It follows the same syntax as .gitignore, with the addition of
3+
# "#!include" directives (which insert the entries of the given .gitignore-style
4+
# file at that point).
5+
#
6+
# For more information, run:
7+
# $ gcloud topic gcloudignore
8+
#
9+
.gcloudignore
10+
# If you would like to upload your .git directory, .gitignore file or files
11+
# from your .gitignore file, remove the corresponding line
12+
# below:
13+
.git
14+
.gitignore
15+
16+
# Node.js dependencies:
17+
node_modules/
18+
.vscode/
19+
next.config.js
20+
.editorconfig
21+
.prettierrc
22+
deploy.sh
23+
yarn-error.log

.gitignore

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
### https://raw.github.com/github/gitignore/656f766bfc75f912d611a973158be0fe9e2ba2f2/Node.gitignore
2+
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
13+
# Directory for instrumented libs generated by jscoverage/JSCover
14+
lib-cov
15+
16+
# Coverage directory used by tools like istanbul
17+
coverage
18+
19+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
20+
.grunt
21+
22+
# node-waf configuration
23+
.lock-wscript
24+
25+
# Compiled binary addons (http://nodejs.org/api/addons.html)
26+
build/Release
27+
28+
# Dependency directory
29+
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
30+
node_modules
31+
32+
# Optional npm cache directory
33+
.npm
34+
35+
# Optional REPL history
36+
.node_repl_history
37+
38+
39+
## Next.js
40+
.next

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": false,
3+
"trailingComma": "es5",
4+
"semi": false
5+
}

.vscode/settings.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"files.exclude": {
3+
"**/.DS_Store": true
4+
},
5+
"search.exclude": {
6+
"**/node_modules": true,
7+
".next": true
8+
},
9+
"files.insertFinalNewline": true,
10+
"javascript.format.enable": false,
11+
"prettier.tslintIntegration": true,
12+
"[javascript]": {
13+
"editor.formatOnSave": true,
14+
"editor.formatOnPaste": true,
15+
"editor.codeActionsOnSave": {
16+
"source.organizeImports": true
17+
}
18+
},
19+
"[typescript]": {
20+
"editor.formatOnSave": true,
21+
"editor.formatOnPaste": true,
22+
"editor.codeActionsOnSave": {
23+
"source.organizeImports": true
24+
}
25+
},
26+
"[typescriptreact]": {
27+
"editor.formatOnSave": true,
28+
"editor.formatOnPaste": true,
29+
"editor.codeActionsOnSave": {
30+
"source.organizeImports": true
31+
}
32+
},
33+
"[jsonc]": {
34+
"editor.formatOnSave": true,
35+
"editor.formatOnPaste": true
36+
}
37+
}

README.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# typescript-nextjs-redux-material-ui-example
2+
3+
This using typescript, next.js, redux, material-ui is simple, and is a sample corresponding to the server side rendering.
4+
5+
By VSCode and prettier and TSLint, realtime code format and realtime sentence structure check and rearranging of unused import are carried out in real time.
6+
7+
これは、typescript, next.js, redux, material-ui を使った、シンプルでサーバーサイドレンダリングに対応したサンプルです。
8+
9+
VSCode と prettier と TSLint によって、リアルタイムに整形と構文チェックと未使用 import の整理が行われます。
10+
11+
## Features
12+
13+
- [Google App Engine Node.js Standard Environment](https://cloud.google.com/appengine/docs/standard/nodejs/)
14+
- [Visual Studio Code](https://code.visualstudio.com/)
15+
- [yarn](https://yarnpkg.com/lang/ja/)
16+
- [Typescript v3](https://www.typescriptlang.org/)
17+
- [Next.js v7](https://nextjs.org/)
18+
- [MATERIAL-UI v3](https://material-ui.com/)
19+
- [Redux](https://redux.js.org/)
20+
- [TSLint](https://palantir.github.io/tslint/)
21+
22+
## Requirement
23+
24+
- [Google Chrome](https://www.google.com/intl/ja_ALL/chrome/)
25+
- [Visual Studio Code](https://code.visualstudio.com/)
26+
- [yarn](https://yarnpkg.com/lang/ja/)
27+
28+
## Install Google Chrome addon
29+
30+
- [Redux DevTools](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=ja)
31+
32+
## Recommended VSCode addons
33+
34+
- [EditorConfig for VS Code](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig)
35+
- [Prettier - Code formatter](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
36+
- [TSLint](https://marketplace.visualstudio.com/items?itemName=eg2.tslint)
37+
- [Bracket Pair Colorizer 2](https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2)
38+
39+
## Usage
40+
41+
### Download and install
42+
43+
```bash
44+
git clone https://github.com/treetips/typescript-nextjs-redux-material-ui-example.git
45+
cd typescript-nextjs-redux-material-ui-example
46+
yarn
47+
```
48+
49+
### Start local
50+
51+
```bash
52+
yarn dev
53+
```
54+
55+
### Build and start production express server
56+
57+
```bash
58+
yarn build
59+
yarn start
60+
```
61+
62+
## For google appengine
63+
64+
### [Optional] appengine deploy Settings
65+
66+
```bash
67+
vi ./deploy.sh
68+
```
69+
70+
### Deploy appengine
71+
72+
```bash
73+
./deploy.sh
74+
```

app.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
service: default
2+
runtime: nodejs8
3+
default_expiration: "1m"
4+
5+
handlers:
6+
- url: /.*
7+
script: server.js

components/MuiColorPalette.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import green from "@material-ui/core/colors/green"
2+
import grey from "@material-ui/core/colors/grey"
3+
4+
/**
5+
* material-ui theme color pallete
6+
* @see https://material-ui.com/style/color/
7+
*/
8+
export const palette = {
9+
typography: {
10+
// https://material-ui.com/style/typography/#strategies
11+
useNextVariants: true,
12+
},
13+
primary: {
14+
light: grey[700],
15+
main: grey[800],
16+
dark: grey[900],
17+
},
18+
secondary: {
19+
light: green[300],
20+
main: green[500],
21+
dark: green[700],
22+
},
23+
}

components/atoms/index.ts

Whitespace-only changes.

components/getPageContext.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {
2+
createGenerateClassName,
3+
createMuiTheme,
4+
} from "@material-ui/core/styles"
5+
import { SheetsRegistry } from "jss"
6+
import { palette } from "./MuiColorPalette"
7+
8+
// @see https://github.com/mui-org/material-ui/blob/master/examples/nextjs/src/getPageContext.js
9+
10+
// A theme with custom primary and secondary color.
11+
const theme = createMuiTheme({ palette: palette })
12+
13+
const createPageContext = () => {
14+
return {
15+
theme,
16+
// This is needed in order to deduplicate the injection of CSS in the page.
17+
sheetsManager: new Map(),
18+
// This is needed in order to inject the critical CSS.
19+
sheetsRegistry: new SheetsRegistry(),
20+
// The standard class name generator.
21+
generateClassName: createGenerateClassName(),
22+
}
23+
}
24+
25+
export default function getPageContext() {
26+
// Make sure to create a new context for every server-side request so that data
27+
// isn't shared between connections (which would be bad).
28+
if (!process.browser) {
29+
return createPageContext()
30+
}
31+
32+
// Reuse context on the client-side.
33+
if (!global.__INIT_MATERIAL_UI__) {
34+
global.__INIT_MATERIAL_UI__ = createPageContext()
35+
}
36+
37+
return global.__INIT_MATERIAL_UI__
38+
}

components/libs/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./DefaultMenuSelector"

components/libs/with-redux-store.tsx

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from "react"
2+
import { initializeStore } from "../store"
3+
4+
const isServer = typeof window === "undefined"
5+
const __NEXT_REDUX_STORE__ = "__NEXT_REDUX_STORE__"
6+
7+
function getOrCreateStore(initialState) {
8+
// Always make a new store if server, otherwise state is shared between requests
9+
if (isServer) {
10+
return initializeStore(initialState)
11+
}
12+
13+
// Create store if unavailable on the client and set it on the window object
14+
if (!window[__NEXT_REDUX_STORE__]) {
15+
window[__NEXT_REDUX_STORE__] = initializeStore(initialState)
16+
}
17+
return window[__NEXT_REDUX_STORE__]
18+
}
19+
20+
export default App => {
21+
return class AppWithRedux extends React.Component {
22+
static async getInitialProps(appContext) {
23+
// Get or Create the store with `undefined` as initialState
24+
// This allows you to set a custom default initialState
25+
const reduxStore = getOrCreateStore()
26+
27+
// Provide the store to getInitialProps of pages
28+
appContext.ctx.reduxStore = reduxStore
29+
30+
let appProps = {}
31+
if (typeof App.getInitialProps === "function") {
32+
appProps = await App.getInitialProps(appContext)
33+
}
34+
35+
return {
36+
...appProps,
37+
initialReduxState: reduxStore.getState(),
38+
}
39+
}
40+
41+
constructor(props) {
42+
super(props)
43+
this.reduxStore = getOrCreateStore(props.initialReduxState)
44+
}
45+
46+
render() {
47+
return <App {...this.props} reduxStore={this.reduxStore} />
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)