Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jun68ykt committed Aug 24, 2019
0 parents commit ccfd346
Show file tree
Hide file tree
Showing 9 changed files with 10,511 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .gitignore
@@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

/.idea
9 changes: 9 additions & 0 deletions README.md
@@ -0,0 +1,9 @@
# tl;dr

This repo contains my answer codes of a React app for
[the question No.207924 of teratail](https://teratail.com/questions/207924), which is a Japanese Programming Q&A site.

# how to run

- yarn install
- yarn start
34 changes: 34 additions & 0 deletions package.json
@@ -0,0 +1,34 @@
{
"name": "q207924",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.3.3",
"axios": "^0.19.0",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-router": "^5.0.1",
"react-scripts": "3.1.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
9 changes: 9 additions & 0 deletions public/index.html
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="ja">
<head>
<title>Q207924</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
12 changes: 12 additions & 0 deletions src/App.js
@@ -0,0 +1,12 @@
import React from 'react';
import Index from './containers/Index'

function App() {
return (
<div className="App">
<Index />
</div>
);
}

export default App;
19 changes: 19 additions & 0 deletions src/component/Post.js
@@ -0,0 +1,19 @@
import React from 'react';

class Post extends React.Component {
render() {
const { title, name, content, createdAt } = this.props
return (
<div className="post">
<ul>
<li>タイトル:{title}</li>
<li>投稿者:{name}</li>
<li>本文:{content}</li>
<li>日時:{createdAt}</li>
</ul>
</div>
)
}
}

export default Post
49 changes: 49 additions & 0 deletions src/containers/Index.js
@@ -0,0 +1,49 @@
import React, { Component } from 'react'
import { withRouter } from 'react-router';
import axios from 'axios';
import Typography from '@material-ui/core/Typography'
import Post from '../component/Post';

class Index extends Component {
constructor(props) {
super(props)
this.state = {
posts: []
}
}


componentDidMount() {
axios
.get('https://demo2746340.mockable.io/q207924/posts')
.then((results) => {
console.log(results)
this.setState({ posts: results.data })
})
.catch((data) =>{
console.log(data)
})
}

render(){
return(
<div>
{(() => {
if (this.state.posts != []) {
this.state.posts.map( post => {
return(
<Post title={post.created_at} name='testUser' title={post.title} content={post.content} />
)
})
} else {
<Typography variant="h1" component="h2">
まだなにも投稿されていません。
</Typography>
}
})()}
</div>
);
}
}

export default Index;
5 changes: 5 additions & 0 deletions src/index.js
@@ -0,0 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(<App />, document.getElementById('root'));

0 comments on commit ccfd346

Please sign in to comment.