Skip to content

Commit 83a224f

Browse files
committed
add home, blog and details pages in web module
1 parent 1be0dac commit 83a224f

File tree

13 files changed

+201
-154
lines changed

13 files changed

+201
-154
lines changed

resources/assets/js/common/articles/listing/components/Article.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function render ({ article }) {
2626
<h4 className="card-title">{article.title}</h4>
2727
<h6 className="card-subtitle mb-2 text-muted">{renderPublishedAt(article)}</h6>
2828
<p className="card-text">{ article.description }</p>
29-
<Link to={`articles/${article.slug}`} className="card-link">Read More</Link>
29+
<Link to={`blog/${article.slug}`} className="card-link">Read More</Link>
3030
</div>
3131
</div>
3232
</div>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// import libs
2+
import React, {Component} from 'react'
3+
import PropTypes from 'prop-types'
4+
import DocumentTitle from 'react-document-title';
5+
import {articleFetchRequest} from '../../../../../store/services/article'
6+
import {APP_TITLE} from '../../../../../values/index'
7+
8+
class Page extends Component {
9+
static displayName = 'ArticleShowPage'
10+
static propTypes = {
11+
match: PropTypes.object.isRequired,
12+
article: PropTypes.object.isRequired,
13+
dispatch: PropTypes.func.isRequired
14+
}
15+
16+
constructor(props) {
17+
super(props)
18+
19+
this.state = {
20+
//
21+
}
22+
}
23+
24+
componentWillMount() {
25+
this.loadArticle()
26+
}
27+
28+
loadArticle() {
29+
const {match, article, dispatch} = this.props
30+
31+
if (!article.slug) {
32+
dispatch(articleFetchRequest(match.params.slug))
33+
}
34+
}
35+
36+
renderPublishedDate() {
37+
const {publishedAt} = this.props.article
38+
39+
if (publishedAt) {
40+
return `at ${publishedAt.format('MMMM d, YYYY')}`
41+
}
42+
}
43+
44+
renderAuthor() {
45+
const {user} = this.props.article
46+
47+
if (user) {
48+
return `by ${user.name}`
49+
}
50+
51+
}
52+
53+
createMarkup() {
54+
return {__html: this.props.article.content};
55+
}
56+
57+
renderArticle() {
58+
const {article} = this.props
59+
return (<div className="col-12 col-sm-9 mb-5 mx-auto">
60+
<h2>{article.title}</h2>
61+
<small className="text-muted mb-5">{this.renderPublishedDate()} {this.renderAuthor()}</small>
62+
<p className="text-muted mb-5">{article.description}</p>
63+
<div dangerouslySetInnerHTML={this.createMarkup()}/>
64+
</div>)
65+
}
66+
67+
render() {
68+
return (
69+
<DocumentTitle title={`${this.props.article.title} - ${APP_TITLE}`}>
70+
<section id="components-articles">
71+
<div className="container">
72+
<div className="row">
73+
{this.renderArticle()}
74+
</div>
75+
</div>
76+
</section>
77+
</DocumentTitle>
78+
)
79+
}
80+
}
81+
82+
export default Page

resources/assets/js/pages/articles/show/index.js renamed to resources/assets/js/modules/web/pages/blog/details/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { connect } from 'react-redux'
2-
import Article from '../../../models/Article'
2+
import Article from '../../../../../models/Article'
33

44
// import components
55
import Page from './Page'
66

77
const mapStateToProps = (state, router) => {
88
const { params } = router.match
9-
9+
1010
const article = state.articles.data.find(article => article.slug === params.slug)
1111
return {
1212
article: article ? new Article(article) : new Article({})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { Component } from "react"
2+
import PropTypes from "prop-types"
3+
4+
// import components
5+
import Articles from "../../../../../common/articles/listing/index"
6+
7+
// import services
8+
import { articleListRequest } from "../../../../../store/services/article"
9+
10+
class Page extends Component {
11+
static displayName = "HomePage"
12+
static propTypes = {
13+
dispatch: PropTypes.func.isRequired,
14+
}
15+
16+
componentDidMount() {
17+
this.props.dispatch(articleListRequest({ url: '/articles/published' }))
18+
}
19+
20+
render() {
21+
return <div>
22+
<Articles/>
23+
</div>
24+
}
25+
}
26+
27+
export default Page
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// import libs
2-
import { connect } from 'react-redux'
2+
import { connect } from "react-redux"
33

44
// import components
5-
import Page from './Page'
5+
import Page from "./Page"
66

77
export default connect()(Page)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React, { Component } from "react"
2+
import PropTypes from "prop-types"
3+
4+
// import components
5+
import Header from "./components/Header"
6+
import Articles from "../../../../common/articles/listing"
7+
8+
// import services
9+
import { articleListRequest } from "../../../../store/services/article"
10+
11+
class Page extends Component {
12+
static displayName = "HomePage"
13+
static propTypes = {
14+
dispatch: PropTypes.func.isRequired,
15+
}
16+
17+
componentDidMount() {
18+
this.props.dispatch(articleListRequest({ url: '/articles/published' }))
19+
}
20+
21+
render() {
22+
return <div>
23+
<Header/>
24+
<Articles/>
25+
</div>
26+
}
27+
}
28+
29+
export default Page
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from "react"
2+
3+
const displayName = "HomePageHeader"
4+
5+
function Header() {
6+
return <header className="bg-primary text-white">
7+
<div className="container text-center">
8+
<img width="125" height="125" src="/img/moeen.jpg" alt="..." className="rounded-circle" />
9+
<h1>Moeen Farooq Basra</h1>
10+
<p className="lead">Master in Information Technology</p>
11+
<p className="lead">Fullstack Developer at&nbsp;
12+
<a className="text-white"
13+
href="http://awok.com"
14+
target="_blank"
15+
rel="noreferrer noopener">Awok.com</a>
16+
</p>
17+
<p className="lead"><i className="fa fa-heart text-danger" />{`{ PHP, JavaScript, Python, MySQL, MongoDB }`}</p>
18+
</div>
19+
</header>
20+
}
21+
Header.displayName = displayName
22+
23+
export default Header
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// import libs
2+
import { connect } from "react-redux"
3+
4+
// import components
5+
import Page from "./Page"
6+
7+
export default connect()(Page)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Home from "./pages/home"
2+
import Blog from "./pages/blog/list"
3+
import BlogDetails from "./pages/blog/details"
4+
5+
const routes = [
6+
{
7+
path: '/',
8+
exact: true,
9+
component: Home,
10+
},
11+
{
12+
path: '/blog',
13+
exact: true,
14+
component: Blog,
15+
},
16+
{
17+
path: '/blog/:slug',
18+
exact: true,
19+
component: BlogDetails,
20+
},
21+
]
22+
23+
export default routes

resources/assets/js/pages/articles/show/Page.js

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)