Skip to content

Commit 06fd423

Browse files
initial commit from create React App
0 parents  commit 06fd423

31 files changed

+17256
-0
lines changed

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `npm install`
8+
9+
It Will Installs all dependencies in package.json.
10+
11+
### `npm start`
12+
13+
Runs the app in the development mode.<br />
14+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
15+
16+
The page will reload if you make edits in any files.<br/>
17+
18+
### `npm run build`
19+
20+
Builds the app for production to the `build` folder.<br/>
21+
It correctly bundles React in production mode and optimizes the build for the best performance.
22+
23+
The build is minified and the filenames include the hashes.<br/>
24+
Your app is ready to be deployed!
25+
26+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

package-lock.json

Lines changed: 16068 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "truecaller-blog",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@testing-library/jest-dom": "^4.2.4",
7+
"@testing-library/react": "^9.3.2",
8+
"@testing-library/user-event": "^7.1.2",
9+
"@types/jest": "^24.0.0",
10+
"@types/node": "^12.0.0",
11+
"@types/react": "^16.9.0",
12+
"@types/react-dom": "^16.9.0",
13+
"@types/react-redux": "^7.1.9",
14+
"@types/react-router": "^5.1.8",
15+
"@types/react-router-redux": "^5.0.18",
16+
"axios": "^0.20.0",
17+
"react": "^16.13.1",
18+
"react-dom": "^16.13.1",
19+
"react-redux": "^7.2.1",
20+
"react-router-config": "^5.1.1",
21+
"react-router-dom": "^5.2.0",
22+
"react-router-redux": "^5.0.0-alpha.9",
23+
"react-scripts": "3.4.3",
24+
"redux": "^4.0.5",
25+
"typescript": "~3.7.2"
26+
},
27+
"scripts": {
28+
"start": "react-scripts start",
29+
"build": "react-scripts build",
30+
"test": "react-scripts test",
31+
"eject": "react-scripts eject"
32+
},
33+
"eslintConfig": {
34+
"extends": "react-app"
35+
},
36+
"browserslist": {
37+
"production": [
38+
">0.2%",
39+
"not dead",
40+
"not op_mini all"
41+
],
42+
"development": [
43+
"last 1 chrome version",
44+
"last 1 firefox version",
45+
"last 1 safari version"
46+
]
47+
}
48+
}

public/favicon.png

3.06 KB
Loading

public/index.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.png" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta
9+
name="description"
10+
content="Truecaller Blog -"
11+
/>
12+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/favicon.png" />
13+
<!--
14+
manifest.json provides metadata used when your web app is installed on a
15+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16+
-->
17+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18+
<!--
19+
Notice the use of %PUBLIC_URL% in the tags above.
20+
It will be replaced with the URL of the `public` folder during the build.
21+
Only files inside the `public` folder can be referenced from the HTML.
22+
23+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24+
work correctly both with client-side routing and a non-root public URL.
25+
Learn how to configure a non-root public URL by running `npm run build`.
26+
-->
27+
<title>Truecaller Blog -</title>
28+
</head>
29+
<body>
30+
<noscript>You need to enable JavaScript to run this app.</noscript>
31+
<div id="root"></div>
32+
<!--
33+
This HTML file is a template.
34+
If you open it directly in the browser, you will see an empty page.
35+
36+
You can add webfonts, meta tags, or analytics to this file.
37+
The build step will place the bundled scripts into the <body> tag.
38+
39+
To begin the development, run `npm start` or `yarn start`.
40+
To create a production bundle, use `npm run build` or `yarn build`.
41+
-->
42+
</body>
43+
</html>

public/manifest.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.png",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
}
10+
],
11+
"start_url": ".",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}

public/robots.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:

public/truecaller-logo.png

6.48 KB
Loading

src/App.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from 'react'
2+
import './css/index.css'
3+
import Home from './components/home/Home'
4+
import SinglePost from './components/post/SinglePost'
5+
import { Router, Route, Switch } from 'react-router'
6+
import Header from './components/common/Header'
7+
import Categories from './components/common/Categories'
8+
import TopTags from './components/common/TopTags'
9+
import Footer from './components/common/Footer'
10+
import { history } from './utils/router'
11+
12+
const App = () => {
13+
return (
14+
<div>
15+
<Header/>
16+
<div className="container">
17+
<div className="main-container">
18+
<Router history={history}>
19+
<Switch>
20+
<Route path="/post/:postId/:postSlug">
21+
<SinglePost />
22+
</Route>
23+
<Route path="/:type/:subType">
24+
<Home />
25+
</Route>
26+
<Route path="/">
27+
<Home />
28+
</Route>
29+
</Switch>
30+
</Router>
31+
</div>
32+
<div className="side-container">
33+
<div className="categories-container">
34+
<h2> Categories </h2>
35+
<Categories/>
36+
</div>
37+
<div className="top-tags-container">
38+
<h2> Top Tags </h2>
39+
<TopTags/>
40+
</div>
41+
</div>
42+
</div>
43+
<Footer/>
44+
</div>
45+
)
46+
}
47+
48+
export default App
49+

src/components/common/BlogPost.tsx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import React from 'react'
2+
import { IBlogFeed } from '../../interfaces'
3+
import { timeInAge, stopEventBubbleAndCall } from '../../utils/common'
4+
import { navigateTo } from '../../utils/router'
5+
6+
const BlogPost = ({post, showCompletePost = false}: {post: IBlogFeed, showCompletePost?: boolean}) => {
7+
return (
8+
<article className="article-content" >
9+
<header>
10+
{
11+
post.featured_image &&
12+
(<img src={`${post.featured_image}`} alt="Post Thumbnail" className="post-thumbnail"/>)
13+
}
14+
<div className="article-category-wrapper">
15+
{
16+
Object.keys(post.categories).map(
17+
(category) => (
18+
<div
19+
className="article-category"
20+
key={category}
21+
onClick={
22+
(event) => stopEventBubbleAndCall(
23+
() => navigateTo(
24+
`/category/${post.categories[category]['slug']}`
25+
),
26+
event
27+
)
28+
}
29+
>
30+
{category}
31+
</div>
32+
)
33+
)
34+
}
35+
</div>
36+
<h2 className="post-title">
37+
{ post.title }
38+
</h2>
39+
</header>
40+
<footer className="post-meta-container">
41+
<div className="post-meta">
42+
• &nbsp;
43+
{ timeInAge(new Date(post.date)) }
44+
</div>
45+
{post.author && post.author.name &&
46+
(
47+
<div className="post-meta">
48+
• &nbsp;
49+
{ post.author.name }
50+
</div>
51+
)}
52+
</footer>
53+
<div className="content-section">
54+
<div dangerouslySetInnerHTML={
55+
{ __html: post[showCompletePost ? 'content' : 'excerpt'] }
56+
} />
57+
</div>
58+
<div className="article-category-wrapper">
59+
{
60+
Object.keys(post.tags).map(
61+
(tag) => (
62+
<div
63+
className="article-tag"
64+
key={tag}
65+
onClick={
66+
(event) => stopEventBubbleAndCall(
67+
() => navigateTo(
68+
`/tag/${post.tags[tag]['slug']}`
69+
),
70+
event
71+
)
72+
}
73+
>
74+
{tag}
75+
</div>
76+
)
77+
)
78+
}
79+
</div>
80+
</ article >
81+
)
82+
}
83+
84+
export default BlogPost

src/components/common/Categories.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react'
2+
import { useGetCategories } from '../../utils/apis'
3+
import { navigateTo } from '../../utils/router'
4+
5+
const Categories = () => {
6+
const {isLoading, data: categories} = useGetCategories()
7+
if(isLoading) {
8+
return <p>Loading....</p>
9+
}
10+
return !categories ?
11+
(
12+
<p>Loading Categories Failed </p>
13+
) :
14+
(
15+
<>
16+
{
17+
categories.map(
18+
({slug, name}) => (
19+
<p key={slug} onClick={() => navigateTo(`/category/${slug}`)}>
20+
{`${name}`}
21+
</p>
22+
)
23+
)
24+
}
25+
</>
26+
)
27+
}
28+
29+
export default React.memo(Categories)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, { ErrorInfo } from 'react'
2+
3+
interface IErrorBoundaryProps {}
4+
interface IErrorBoundaryState {
5+
hasError: boolean
6+
}
7+
8+
class ErrorBoundary extends React.Component<IErrorBoundaryProps, IErrorBoundaryState> {
9+
constructor(props: IErrorBoundaryProps) {
10+
super(props)
11+
this.state = { hasError: false }
12+
}
13+
14+
static getDerivedStateFromError(error: Error) {
15+
return { hasError: true }
16+
}
17+
18+
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
19+
// Log the error to an error reporting service
20+
console.log(error, errorInfo)
21+
}
22+
23+
render() {
24+
if (this.state.hasError) {
25+
// Fallback UI
26+
return <h1>Error 405</h1>
27+
}
28+
29+
return this.props.children
30+
}
31+
}
32+
export default ErrorBoundary
33+

src/components/common/Footer.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
const Footer = () => (
3+
<footer className="site-footer" role="contentinfo">
4+
<div className="copyright text-center">
5+
<h4><strong> Made with <span role="img" aria-label="heart">💖</span> by Devanshu Vashishtha </strong></h4>
6+
<p> © Copyright 2020 | All Rights Reserved.</p>
7+
</div>
8+
</footer>
9+
)
10+
export default React.memo(Footer)

0 commit comments

Comments
 (0)