├── public
├── favicon.ico
├── android-chrome-512x512.png
├── chrome-touch-icon-192x192.png
├── manifest.json
└── index.html
├── src
├── images
│ └── admin.png
├── App.js
├── App.test.js
├── CSS
│ ├── addnews.css
│ ├── dashboard.css
│ └── login.css
├── config
│ └── config.js
├── services
│ ├── authentication.js
│ └── news.js
├── App.css
├── components
│ ├── dashboard.js
│ ├── news.js
│ ├── login.js
│ ├── addnews.js
│ └── singlenews.js
├── index.js
├── index.css
├── logo.svg
└── serviceWorker.js
├── app.js
├── .gitignore
├── package.json
├── bucket.json
└── README.md
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosmicjs/react-pwa/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/src/images/admin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosmicjs/react-pwa/HEAD/src/images/admin.png
--------------------------------------------------------------------------------
/public/android-chrome-512x512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosmicjs/react-pwa/HEAD/public/android-chrome-512x512.png
--------------------------------------------------------------------------------
/public/chrome-touch-icon-192x192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosmicjs/react-pwa/HEAD/public/chrome-touch-icon-192x192.png
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | const express = require('express')
2 | const app = express()
3 |
4 | app.use(express.static('./build'));
5 |
6 | app.listen(process.env.PORT || 5000, function () {
7 | });
8 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import './App.css';
3 |
4 | class App extends Component {
5 | render() {
6 | return (
7 |
8 |
9 | );
10 | }
11 | }
12 |
13 | export default App;
14 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import App from './App';
4 |
5 | it('renders without crashing', () => {
6 | const div = document.createElement('div');
7 | ReactDOM.render( , div);
8 | ReactDOM.unmountComponentAtNode(div);
9 | });
10 |
--------------------------------------------------------------------------------
/src/CSS/addnews.css:
--------------------------------------------------------------------------------
1 |
2 |
3 | .box-height
4 | {
5 | height: 20px
6 | }
7 |
8 | .margin-up
9 | {
10 | margin-top: 38px
11 | }
12 |
13 | .ql-container
14 | {
15 | height: 100px;
16 |
17 |
18 | }
19 |
20 | #news-title
21 | {
22 | width: 98%;
23 | padding: 10px;
24 | display:block;
25 | border-radius:10px;
26 | border:1px solid #ccc;
27 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
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*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/src/config/config.js:
--------------------------------------------------------------------------------
1 | const config = {
2 | bucket_name: process.env.REACT_APP_BUCKET_SLUG || "996304b0-28d1-11e9-9e3f-b139f5a50259",
3 | bucket_slug: process.env.REACT_APP_BUCKET_SLUG || "996304b0-28d1-11e9-9e3f-b139f5a50259",
4 | bucket_id: process.env.REACT_APP_BUCKET_ID || "",
5 | read_key: process.env.REACT_APP_BUCKET_READ_KEY || "",
6 | write_key: process.env.REACT_APP_BUCKET_WRITE_KEY || "",
7 | url: "https://api.cosmicjs.com/v1/"
8 | }
9 | export default config;
--------------------------------------------------------------------------------
/src/CSS/dashboard.css:
--------------------------------------------------------------------------------
1 | ul {
2 | list-style-type: none;
3 | /* display: inline-block; */
4 | }
5 | #ul_top_hypers li {
6 | display: inline;
7 | }
8 |
9 | .btn
10 | {
11 |
12 | background-color: #3583aa;
13 | color: white;
14 |
15 | }
16 | .btn:hover {
17 | background: #80c9ee;
18 | color: rgb(59, 57, 57);
19 | }
20 |
21 | .text-center
22 | {
23 | text-align: center;
24 | margin-bottom: 10em
25 | }
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "PWA in Cosmic JS",
3 | "name": "Progressive Web App in React & Cosmic JS",
4 | "icons": [
5 | {
6 | "src": "chrome-touch-icon-192x192.png",
7 | "sizes": "192x192",
8 | "type": "image/png"
9 | },
10 | {
11 | "src": "android-chrome-512x512.png",
12 | "sizes": "512x512",
13 | "type": "image/png"
14 | }
15 | ],
16 | "start_url": "./",
17 | "display": "standalone",
18 | "theme_color": "#000000",
19 | "background_color": "#ffffff"
20 | }
--------------------------------------------------------------------------------
/src/services/authentication.js:
--------------------------------------------------------------------------------
1 | import config from './../config/config';
2 | import axios from 'axios';
3 |
4 | const authentication = {
5 |
6 | login(email)
7 | {
8 | return axios.get(config.url+config.bucket_slug+"/object-type/admins/search",{
9 | params:{
10 | metafield_key: 'email',
11 | metafield_value: email,
12 | limit: 1,
13 | read_key: config.read_key
14 | }
15 | })
16 | }
17 | }
18 |
19 | export default authentication;
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | }
4 |
5 | .App-logo {
6 | animation: App-logo-spin infinite 20s linear;
7 | height: 40vmin;
8 | }
9 |
10 | .App-header {
11 | background-color: #282c34;
12 | min-height: 100vh;
13 | display: flex;
14 | flex-direction: column;
15 | align-items: center;
16 | justify-content: center;
17 | font-size: calc(10px + 2vmin);
18 | color: white;
19 | }
20 |
21 | .App-link {
22 | color: #61dafb;
23 | }
24 |
25 | @keyframes App-logo-spin {
26 | from {
27 | transform: rotate(0deg);
28 | }
29 | to {
30 | transform: rotate(360deg);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-pwa",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "axios": "^0.18.0",
7 | "bootstrap": "^4.2.1",
8 | "react": "^16.7.0",
9 | "react-dom": "^16.7.0",
10 | "react-html-parser": "^2.0.2",
11 | "react-quill": "^1.3.3",
12 | "react-router-dom": "^4.3.1",
13 | "react-scripts": "2.1.3",
14 | "reactstrap": "^7.0.2"
15 | },
16 | "scripts": {
17 | "start": "node app.js",
18 | "build": "react-scripts build",
19 | "test": "react-scripts test",
20 | "eject": "react-scripts eject",
21 | "postinstall": "npm run build"
22 | },
23 | "keywords": [
24 | "example",
25 | "heroku"
26 | ],
27 | "engines": {
28 | "node": "8.12.0",
29 | "npm": "6.4.1"
30 | },
31 | "eslintConfig": {
32 | "extends": "react-app"
33 | },
34 | "browserslist": [
35 | ">0.2%",
36 | "not dead",
37 | "not ie <= 11",
38 | "not op_mini all"
39 | ]
40 | }
41 |
--------------------------------------------------------------------------------
/bucket.json:
--------------------------------------------------------------------------------
1 | {
2 | "bucket": {
3 | "_id": "5c3f6c46081d3062a56ea573",
4 | "slug": "react-pwa",
5 | "title": "react-pwa",
6 | "object_types": [
7 | {
8 | "title": "admins",
9 | "slug": "admins",
10 | "singular": "admin",
11 | "metafields": [],
12 | "options": {
13 | "slug_field": 1,
14 | "content_editor": 1
15 | },
16 | "preview_link": "",
17 | "priority_locale": null
18 | },
19 | {
20 | "title": "news",
21 | "slug": "news",
22 | "singular": "news",
23 | "metafields": [],
24 | "options": {
25 | "slug_field": 1,
26 | "content_editor": 1
27 | },
28 | "preview_link": "",
29 | "priority_locale": null
30 | },
31 | {
32 | "title": "comments",
33 | "slug": "comments",
34 | "singular": "comment",
35 | "metafields": [],
36 | "options": {
37 | "slug_field": 1,
38 | "content_editor": 1
39 | },
40 | "preview_link": "",
41 | "priority_locale": null
42 | }
43 | ],
44 | "objects": [],
45 | "media": []
46 | }
47 | }
--------------------------------------------------------------------------------
/src/components/dashboard.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Link } from 'react-router-dom';
3 | import './../CSS/dashboard.css';
4 |
5 |
6 | class dashboard extends Component {
7 | constructor(props) {
8 | super(props);
9 | this.state = {
10 | };
11 | this.logout = this.logout.bind(this);
12 | };
13 |
14 | //logout function
15 | logout()
16 | {
17 | localStorage.removeItem('currentUser');
18 | this.props.history.push('/');
19 | }
20 |
21 | render() {
22 | return (
23 |
24 |
25 |
26 |
27 |
28 | Home
29 |
30 |
31 |
32 | Add News
33 |
34 |
35 |
36 | Logout
37 |
38 |
39 |
40 |
Hey Admin, Welcome to Dashboard!
41 |
42 |
43 | );
44 | }
45 |
46 | componentDidMount() {
47 | if(!localStorage.getItem('currentUser'))
48 | {
49 | this.props.history.push('/');
50 | }
51 | }
52 |
53 | }
54 |
55 | export default dashboard;
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
6 |
7 | import { BrowserRouter as Router, Route } from 'react-router-dom';
8 | import news from './components/news';
9 | import login from './components/login';
10 | import 'bootstrap/dist/css/bootstrap.css';
11 | import dashboard from './components/dashboard';
12 | import addnews from './components/addnews';
13 | import singlenews from './components/singlenews';
14 |
15 |
16 | ReactDOM.render( , document.getElementById('root'));
17 |
18 |
19 |
20 | // If you want your app to work offline and load faster, you can change
21 | // unregister() to register() below. Note this comes with some pitfalls.
22 | // Learn more about service workers: http://bit.ly/CRA-PWA
23 |
24 | ReactDOM.render(
25 |
26 |
27 |
28 |
29 |
React PWA in Cosmic JS
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
41 |
42 |
43 | ,
44 | document.getElementById('root')
45 | );
46 |
47 |
48 | serviceWorker.register();
49 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
10 |
11 |
15 |
16 |
25 | Progressive Web App
26 |
27 |
28 | You need to enable JavaScript to run this app.
29 |
30 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/services/news.js:
--------------------------------------------------------------------------------
1 | import config from './../config/config';
2 | import axios from 'axios';
3 |
4 | const newsData = {
5 |
6 | // add news to Cosmic JS database
7 | addnews(title, description, newsbody, date)
8 | {
9 | return axios.post(config.url+config.bucket_slug+"/add-object/", {
10 | title: title, slug: title, content: newsbody, type_slug: 'news', write_key: config.write_key,
11 |
12 | metafields: [
13 | {
14 | key: "description",
15 | type: "text",
16 | value: description
17 | },
18 | {
19 | key: "date",
20 | type: "text",
21 | value: date
22 | }
23 | ]
24 |
25 | })
26 | },
27 |
28 | // fetch all news from Cosmic JS database
29 | getNews()
30 | {
31 | return axios.get(config.url+config.bucket_slug+"/object-type/news",{
32 | params: {
33 | read_key: config.read_key
34 | }
35 | })
36 | },
37 |
38 | // submiting comment
39 | submitComment(name, comment, newsId)
40 | {
41 | return axios.post(config.url+config.bucket_slug+"/add-object/", {
42 | title: name, slug: name, content: newsId, type_slug: 'comments', write_key: config.write_key,
43 | metafields: [
44 | {
45 | key: "comment",
46 | type: "text",
47 | value: comment
48 | }
49 | ]
50 |
51 | })
52 | },
53 |
54 | // all comments
55 | allComments()
56 | {
57 | return axios.get(config.url+config.bucket_slug+"/object-type/comments",{
58 | params: {
59 | read_key: config.read_key
60 | }
61 | })
62 | }
63 |
64 | }
65 |
66 | export default newsData;
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
5 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
6 | sans-serif;
7 | -webkit-font-smoothing: antialiased;
8 | -moz-osx-font-smoothing: grayscale;
9 | }
10 |
11 | code {
12 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
13 | monospace;
14 | }
15 |
16 | .button-right
17 | {
18 | float: right;
19 | clear: both;
20 | }
21 |
22 | .blog {
23 | width:100%;
24 | float: left;
25 | margin: 5px 0;
26 | }
27 | .blog ul {
28 | width:100%;
29 | display: block;
30 | margin: 0 0 30px;
31 | float: left;
32 | /* padding: 0; */
33 | }
34 |
35 | .blog h3 {
36 | font-weight: 500;
37 | margin-bottom: 15px;
38 | }
39 |
40 | .heading-set
41 | {
42 | text-decoration: none;
43 | color: rgb(31, 29, 29);
44 | }
45 |
46 | .margin-top
47 | {
48 | margin-top: 30px
49 | }
50 |
51 | /* .btn-success:hover {
52 | color: none;
53 | background-color: none !important;
54 | border-color: none !important;
55 | } */
56 |
57 | /* .btn-success {
58 | color: #fff;
59 | background-color: none;
60 | border-color: none;
61 | } */
62 |
63 | .btn-success:not(:disabled):not(.disabled):active, .btn-success:not(:disabled):not(.disabled).active, .show > .btn-success.dropdown-toggle {
64 | color: #fff;
65 | background-color: #80c9ee !important;
66 | border-color: #80c9ee !important;
67 | }
68 |
69 | #commentBody
70 | {
71 | height: 50px;
72 | width: 80%;
73 | padding:10px;
74 | display:block;
75 | border-radius:5px;
76 | border:1px solid #3583aa;
77 | }
78 |
79 | #commentName
80 | {
81 | width: 80%;
82 | width: 80%;
83 | padding: 10px;
84 | display:block;
85 | border-radius:5px;
86 | border:1px solid #3583aa;
87 | }
88 | /*
89 | #comment-button
90 | {
91 | width: 20px
92 | } */
93 |
94 | #comment-button
95 | {
96 | background-color: #3583aa;
97 | border: none;
98 | color: white;
99 | padding: 10px 30px;
100 | text-align: center;
101 | text-decoration: none;
102 | display: inline-block;
103 | text-transform: uppercase;
104 | font-size: 13px;
105 | box-shadow: 0 10px 30px 0 rgba(95,186,233,0.4);
106 | border-radius: 5px 5px 5px 5px;
107 | margin: 5px 20px 40px 20px;
108 | -webkit-transition: all 0.3s ease-in-out;
109 | transition: all 0.3s ease-in-out;
110 | }
111 |
--------------------------------------------------------------------------------
/src/components/news.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import newsData from './../services/news';
3 | import ReactHtmlParser from 'react-html-parser';
4 | import { Link } from 'react-router-dom';
5 |
6 | class news extends Component {
7 | data;
8 | constructor(props) {
9 | super(props);
10 | this.state = {
11 | newsArray: [],
12 | };
13 | this.loginCall = this.loginCall.bind(this);
14 | this.dashboardCall = this.dashboardCall.bind(this);
15 | };
16 |
17 | getNews()
18 | {
19 | if(navigator.onLine)
20 | {
21 | newsData.getNews()
22 | .then((result)=>{
23 | // console.log(result.data.objects);
24 | if(result.data.objects)
25 | {
26 | this.setState({newsArray: result.data.objects})
27 | localStorage.setItem('news', JSON.stringify(result.data.objects))
28 | // console.log(this.state.newsArray)
29 | }
30 |
31 | })
32 | }
33 | else
34 | {
35 | this.setState({newsArray: JSON.parse(localStorage.getItem('news'))})
36 | }
37 | }
38 |
39 | loginCall()
40 | {
41 | this.props.history.push('/login');
42 | }
43 |
44 | dashboardCall()
45 | {
46 | this.props.history.push('/dashboard');
47 | }
48 |
49 | render() {
50 | return (
51 |
52 |
53 |
{this.data ? (
54 | Dashboard
55 | ) : (
56 | Admin Login
57 | )}
58 |
59 |
60 | {this.state.newsArray.map(newsData =>
61 |
75 | )}
76 |
77 | );
78 | }
79 |
80 | componentDidMount() {
81 | this.data = localStorage.getItem('currentUser');
82 | this.getNews();
83 |
84 | }
85 |
86 | }
87 |
88 | export default news;
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/components/login.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import authentication from './../services/authentication';
3 | import { Link } from 'react-router-dom';
4 | import './../App.css';
5 | import './../CSS/login.css';
6 |
7 | class login extends Component {
8 | returnedData;
9 |
10 | constructor(props) {
11 | super(props);
12 | this.state = {
13 | email: "",
14 | password: "",
15 | message: "",
16 | isLoading: "",
17 | };
18 | };
19 |
20 | onChange = (e) => {
21 | const state = this.state
22 | state[e.target.name] = e.target.value;
23 | this.setState(state);
24 |
25 | }
26 |
27 | onSubmit = (e) =>
28 | {
29 | e.preventDefault();
30 | // this.state.isLoading = "Please wait..";
31 | this.setState({isLoading: "Please wait.."});
32 | authentication.login(this.state.email)
33 | .then((result)=>{
34 | // console.log(result.data.message)
35 | console.log(result.data.objects[0].metadata.email)
36 | if(result.data.message === "No objects returned.")
37 | {
38 | this.setState({message: "Wrong credentials, try again!!"});
39 | this.setState({isLoading: ""});
40 | this.timeout();
41 | }
42 | else
43 | {
44 | this.setState({message: ""});
45 | this.setState({isLoading: ""});
46 | localStorage.setItem('currentUser', result.data.objects[0].metadata.email)
47 | this.props.history.push('/dashboard');
48 |
49 |
50 | }
51 | // console.log(result.data.objects[0].metadata)
52 | // this.returnedData = result;
53 | // var jsondata = JSON.parse(this.returnedData._body);
54 | // console.log(jsondata.message)
55 | })
56 | }
57 |
58 | //timeout function
59 | timeout()
60 | {
61 | setTimeout(
62 | function() {
63 | this.setState({message: ""});
64 | }
65 | .bind(this),
66 | 5000
67 | );
68 | }
69 |
70 |
71 |
72 | render() {
73 | return (
74 |
75 |
76 | Back
77 |
78 |
79 |
80 |
81 |
Admin Login
82 |
83 |
84 | {/*
85 |
86 |
87 |
*/}
88 |
89 |
101 |
102 |
103 |
104 |
105 |
106 | );
107 | }
108 |
109 | componentDidMount() {
110 | if(localStorage.getItem('currentUser'))
111 | {
112 | this.props.history.push('/dashboard');
113 | }
114 | }
115 |
116 | }
117 |
118 | export default login;
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React PWA with Authentication
2 |
3 | 
4 | ### [View Demo](https://cosmicjs.com/apps/react-pwa-with-authentication)
5 |
6 | [Read how this app was built](https://cosmicjs.com/articles/how-to-build-a-pwa-in-reactjs-and-cosmic-js-jraynd4c). This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
7 |
8 | # Get Started
9 |
10 | ## Running server:
11 |
12 | ```
13 | git clone https://github.com/a9kitkumar/cosmicjs-pwa
14 | cd cosmicjs-pwa
15 | npm install
16 | npm run build
17 | npm install -g serve
18 | serve -s build
19 | ```
20 |
21 | ## Available Scripts
22 |
23 | In the project directory, you can run:
24 |
25 | ### `npm start`
26 |
27 | Runs the app in the development mode.
28 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
29 |
30 | The page will reload if you make edits.
31 | You will also see any lint errors in the console.
32 |
33 | ### `npm test`
34 |
35 | Launches the test runner in the interactive watch mode.
36 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
37 |
38 | ### `npm run build`
39 |
40 | Builds the app for production to the `build` folder.
41 | It correctly bundles React in production mode and optimizes the build for the best performance.
42 |
43 | The build is minified and the filenames include the hashes.
44 | Your app is ready to be deployed!
45 |
46 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
47 |
48 | ### `npm run eject`
49 |
50 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
51 |
52 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
53 |
54 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
55 |
56 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
57 |
58 | ## Learn More
59 |
60 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
61 |
62 | To learn React, check out the [React documentation](https://reactjs.org/).
63 |
64 | ### Code Splitting
65 |
66 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
67 |
68 | ### Analyzing the Bundle Size
69 |
70 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
71 |
72 | ### Making a Progressive Web App
73 |
74 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
75 |
76 | ### Advanced Configuration
77 |
78 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
79 |
80 | ### Deployment
81 |
82 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
83 |
84 | ### `npm run build` fails to minify
85 |
86 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
87 |
--------------------------------------------------------------------------------
/src/components/addnews.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import ReactQuill from 'react-quill';
3 | import 'react-quill/dist/quill.snow.css';
4 | import './../CSS/addnews.css';
5 | import newsData from './../services/news';
6 | import { Link } from 'react-router-dom';
7 |
8 | class addnews extends Component {
9 | constructor(props) {
10 | super(props);
11 | this.state = {
12 | title: '',
13 | description: '',
14 | newsbody: '',
15 | message: '',
16 | date: '',
17 | };
18 | this.handleChange = this.handleChange.bind(this);
19 | this.handleChange2 = this.handleChange2.bind(this)
20 | };
21 |
22 | onChange = (e) => {
23 | const state = this.state
24 | state[e.target.name] = e.target.value;
25 | this.setState(state);
26 | }
27 |
28 | handleChange(value) {
29 | this.setState({ newsbody: value })
30 | }
31 |
32 | handleChange2(value) {
33 | this.setState({ description: value })
34 | }
35 |
36 | todayDate()
37 | {
38 | var today = new Date(),
39 | date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
40 | // console.log(date)
41 | this.setState({date: date});
42 |
43 | }
44 |
45 | onSubmit = (e) => {
46 | e.preventDefault();
47 | this.setState({ message: "Please wait..." });
48 | newsData.addnews(this.state.title, this.state.description, this.state.newsbody, this.state.date)
49 | .then((result)=>{
50 | console.log(result)
51 | this.setState({ message: "News published successfully" });
52 | this.timeout();
53 | })
54 |
55 | }
56 |
57 | //timeout function to null the message
58 | timeout()
59 | {
60 | setTimeout(
61 | function() {
62 | this.setState({message: ""});
63 | }
64 | .bind(this),
65 | 5000
66 | );
67 | }
68 |
69 |
70 | render() {
71 | return (
72 |
73 |
74 | Back
75 |
76 |
77 |
78 |
79 |
80 |
Publish News:
81 |
102 |
103 | );
104 | }
105 |
106 | componentDidMount() {
107 | this.todayDate();
108 | }
109 |
110 | }
111 |
112 | export default addnews;
--------------------------------------------------------------------------------
/src/components/singlenews.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import newsData from './../services/news';
3 | import ReactHtmlParser from 'react-html-parser';
4 | import { Link } from 'react-router-dom';
5 | import { Form} from 'reactstrap';
6 |
7 | class singlenews extends Component {
8 | // singleNewsData = [];
9 | constructor(props) {
10 | super(props);
11 | this.state = {
12 | newsId: '',
13 | allNews: '',
14 | singleNewsData: [],
15 | name: '',
16 | comment: '',
17 | message: '',
18 | allComments: [],
19 |
20 | };
21 | // this.singleNews = this.singleNews.bind(this);
22 | };
23 |
24 | onChange = (e) => {
25 | const state = this.state
26 | state[e.target.name] = e.target.value;
27 | this.setState(state);
28 |
29 | }
30 |
31 | // getting single news
32 | singleNews()
33 | {
34 | newsData.getNews()
35 | .then((result)=>{
36 | console.log(result.data.objects);
37 | var allData = result.data.objects;
38 | // this.setState({allNews: result.data.objects})
39 |
40 | var singleNewsFilteredData = allData.filter((
41 | news) => news._id === this.state.newsId);
42 | this.setState({singleNewsData: singleNewsFilteredData[0]})
43 | console.log(this.state.singleNewsData.metadata.date)
44 | })
45 | }
46 |
47 | // fetching all comments
48 | allComments()
49 | {
50 | newsData.allComments()
51 | .then((result)=>
52 | {
53 | console.log(result.data.objects);
54 | var allData = result.data.objects;
55 | if(allData){
56 | // this.setState({allComments:result.data.objects})
57 |
58 |
59 | var singleNewsFilteredData = allData.filter((
60 | comment) => comment.content === this.state.newsId);
61 | this.setState({allComments: singleNewsFilteredData})
62 | // console.log(singleNewsFilteredData)
63 |
64 | }
65 | })
66 |
67 | }
68 |
69 |
70 |
71 |
72 | // submitting comment
73 | submitComment = (e) =>
74 | {
75 | e.preventDefault();
76 | this.setState({message: "Posting comment..."})
77 | newsData.submitComment(this.state.name, this.state.comment, this.state.newsId)
78 | .then((result)=>{
79 | console.log(result);
80 | this.setState({message: ""});
81 | this.allComments();
82 | })
83 | }
84 |
85 |
86 |
87 | render() {
88 | return (
89 |
90 |
91 | Back
92 |
93 |
94 | {this.state.singleNewsData.title}
95 |
96 |
97 |
98 | {ReactHtmlParser(this.state.singleNewsData.content)}
99 |
100 |
101 |
102 |
103 | {/* comments */}
104 |
105 |
Comments:
106 | {this.state.allComments.map(newsData =>
107 |
108 |
{newsData.title}
109 |
{newsData.metadata.comment}
110 |
111 |
112 | )}
113 |
114 |
115 | {/* comment box */}
116 |
133 |
134 |
135 |
136 | );
137 | }
138 |
139 | componentDidMount() {
140 |
141 | console.log(this.props.match.params.id);
142 | this.setState({newsId: this.props.match.params.id});
143 | this.singleNews();
144 | this.allComments();
145 | }
146 |
147 | }
148 |
149 | export default singlenews;
--------------------------------------------------------------------------------
/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read http://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.1/8 is considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit http://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl)
104 | .then(response => {
105 | // Ensure service worker exists, and that we really are getting a JS file.
106 | const contentType = response.headers.get('content-type');
107 | if (
108 | response.status === 404 ||
109 | (contentType != null && contentType.indexOf('javascript') === -1)
110 | ) {
111 | // No service worker found. Probably a different app. Reload the page.
112 | navigator.serviceWorker.ready.then(registration => {
113 | registration.unregister().then(() => {
114 | window.location.reload();
115 | });
116 | });
117 | } else {
118 | // Service worker found. Proceed as normal.
119 | registerValidSW(swUrl, config);
120 | }
121 | })
122 | .catch(() => {
123 | console.log(
124 | 'No internet connection found. App is running in offline mode.'
125 | );
126 | });
127 | }
128 |
129 | export function unregister() {
130 | if ('serviceWorker' in navigator) {
131 | navigator.serviceWorker.ready.then(registration => {
132 | registration.unregister();
133 | });
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/src/CSS/login.css:
--------------------------------------------------------------------------------
1 | @import url('https://fonts.googleapis.com/css?family=Poppins');
2 |
3 | /* BASIC */
4 |
5 | /* html {
6 | background-color: #56baed;
7 | } */
8 |
9 | body {
10 | font-family: "Poppins", sans-serif;
11 | height: 100vh;
12 | }
13 |
14 | a {
15 | color: #92badd;
16 | display:inline-block;
17 | text-decoration: none;
18 | font-weight: 400;
19 | }
20 |
21 | h2 {
22 | /* text-align: center; */
23 | font-size: 16px;
24 | font-weight: 600;
25 |
26 | display:inline-block;
27 | /* margin: 40px 8px 10px 8px; */
28 | color: #cccccc;
29 | }
30 |
31 |
32 |
33 | /* STRUCTURE */
34 |
35 | .wrapper {
36 | display: flex;
37 | align-items: center;
38 | flex-direction: column;
39 | justify-content: center;
40 | width: 100%;
41 | min-height: 100%;
42 | padding: 20px;
43 | }
44 |
45 | #formContent {
46 | -webkit-border-radius: 10px 10px 10px 10px;
47 | border-radius: 10px 10px 10px 10px;
48 | background: #fff;
49 | padding: 30px;
50 | width: 90%;
51 | max-width: 450px;
52 | position: relative;
53 | padding: 0px;
54 | -webkit-box-shadow: 0 30px 60px 0 rgba(0,0,0,0.3);
55 | box-shadow: 0 30px 60px 0 rgba(0,0,0,0.3);
56 | text-align: center;
57 | }
58 |
59 | #formFooter {
60 | background-color: #f6f6f6;
61 | border-top: 1px solid #dce8f1;
62 | padding: 25px;
63 | text-align: center;
64 | -webkit-border-radius: 0 0 10px 10px;
65 | border-radius: 0 0 10px 10px;
66 | }
67 |
68 |
69 |
70 | /* TABS */
71 |
72 | h2.inactive {
73 | color: #cccccc;
74 | }
75 |
76 | h2.active {
77 | color: #0d0d0d;
78 |
79 | }
80 |
81 |
82 |
83 | /* FORM TYPOGRAPHY*/
84 |
85 | input[type=button], input[type=submit], input[type=reset] {
86 | background-color: #3583aa;
87 | border: none;
88 | color: white;
89 | padding: 15px 80px;
90 | text-align: center;
91 | text-decoration: none;
92 | display: inline-block;
93 | text-transform: uppercase;
94 | font-size: 13px;
95 | -webkit-box-shadow: 0 10px 30px 0 rgba(95,186,233,0.4);
96 | box-shadow: 0 10px 30px 0 rgba(95,186,233,0.4);
97 | -webkit-border-radius: 5px 5px 5px 5px;
98 | border-radius: 5px 5px 5px 5px;
99 | margin: 5px 20px 40px 20px;
100 | -webkit-transition: all 0.3s ease-in-out;
101 | -moz-transition: all 0.3s ease-in-out;
102 | -ms-transition: all 0.3s ease-in-out;
103 | -o-transition: all 0.3s ease-in-out;
104 | transition: all 0.3s ease-in-out;
105 | }
106 |
107 | input[type=button]:hover, input[type=submit]:hover, input[type=reset]:hover {
108 | background-color: #39ace7;
109 | cursor: pointer;
110 | }
111 |
112 | input[type=button]:active, input[type=submit]:active, input[type=reset]:active {
113 | -moz-transform: scale(0.95);
114 | -webkit-transform: scale(0.95);
115 | -o-transform: scale(0.95);
116 | -ms-transform: scale(0.95);
117 | transform: scale(0.95);
118 | }
119 |
120 | input[type=text] {
121 | background-color: #f6f6f6;
122 | border: none;
123 | color: #0d0d0d;
124 | padding: 15px 32px;
125 |
126 | text-decoration: none;
127 | display: inline-block;
128 | font-size: 16px;
129 | margin: 5px;
130 | width: 85%;
131 | border: 2px solid #f6f6f6;
132 | -webkit-transition: all 0.5s ease-in-out;
133 | -moz-transition: all 0.5s ease-in-out;
134 | -ms-transition: all 0.5s ease-in-out;
135 | -o-transition: all 0.5s ease-in-out;
136 | transition: all 0.5s ease-in-out;
137 | -webkit-border-radius: 5px 5px 5px 5px;
138 | border-radius: 5px 5px 5px 5px;
139 | }
140 |
141 | input[type=text]:focus {
142 | background-color: #fff;
143 | border-bottom: 2px solid #5fbae9;
144 | }
145 |
146 | input[type=text]:placeholder {
147 | color: #cccccc;
148 | }
149 |
150 | /* input type email */
151 | input[type=email] {
152 | background-color: #f6f6f6;
153 | border: none;
154 | color: #0d0d0d;
155 | padding: 15px 32px;
156 |
157 | text-decoration: none;
158 | display: inline-block;
159 | font-size: 16px;
160 | margin: 5px;
161 | width: 85%;
162 | border: 2px solid #f6f6f6;
163 | -webkit-transition: all 0.5s ease-in-out;
164 | -moz-transition: all 0.5s ease-in-out;
165 | -ms-transition: all 0.5s ease-in-out;
166 | -o-transition: all 0.5s ease-in-out;
167 | transition: all 0.5s ease-in-out;
168 | -webkit-border-radius: 5px 5px 5px 5px;
169 | border-radius: 5px 5px 5px 5px;
170 | }
171 |
172 | input[type=email]:focus {
173 | background-color: #fff;
174 | border-bottom: 2px solid #5fbae9;
175 | }
176 |
177 | input[type=email]:placeholder {
178 | color: #cccccc;
179 | }
180 |
181 | /* input type password */
182 | input[type=password] {
183 | background-color: #f6f6f6;
184 | border: none;
185 | color: #0d0d0d;
186 | padding: 15px 32px;
187 |
188 | text-decoration: none;
189 | display: inline-block;
190 | font-size: 16px;
191 | margin: 5px;
192 | width: 85%;
193 | border: 2px solid #f6f6f6;
194 | -webkit-transition: all 0.5s ease-in-out;
195 | -moz-transition: all 0.5s ease-in-out;
196 | -ms-transition: all 0.5s ease-in-out;
197 | -o-transition: all 0.5s ease-in-out;
198 | transition: all 0.5s ease-in-out;
199 | -webkit-border-radius: 5px 5px 5px 5px;
200 | border-radius: 5px 5px 5px 5px;
201 | }
202 |
203 | input[type=password]:focus {
204 | background-color: #fff;
205 | border-bottom: 2px solid #5fbae9;
206 | }
207 |
208 | input[type=password]:placeholder {
209 | color: #cccccc;
210 | }
211 |
212 |
213 | .loginalert
214 | {
215 | color: red;
216 | }
217 |
218 | .center{
219 |
220 | text-align: center;
221 | font-size: 80px;
222 | color: white;
223 | background: #3583aa !important
224 | }
225 |
226 | .footer-center
227 | {
228 | text-align: center;
229 | }
230 |
231 |
232 |
233 | /* ANIMATIONS */
234 |
235 | /* Simple CSS3 Fade-in-down Animation */
236 | .fadeInDown {
237 | -webkit-animation-name: fadeInDown;
238 | animation-name: fadeInDown;
239 | -webkit-animation-duration: 1s;
240 | animation-duration: 1s;
241 | -webkit-animation-fill-mode: both;
242 | animation-fill-mode: both;
243 | }
244 |
245 | @-webkit-keyframes fadeInDown {
246 | 0% {
247 | opacity: 0;
248 | -webkit-transform: translate3d(0, -100%, 0);
249 | transform: translate3d(0, -100%, 0);
250 | }
251 | 100% {
252 | opacity: 1;
253 | -webkit-transform: none;
254 | transform: none;
255 | }
256 | }
257 |
258 | @keyframes fadeInDown {
259 | 0% {
260 | opacity: 0;
261 | -webkit-transform: translate3d(0, -100%, 0);
262 | transform: translate3d(0, -100%, 0);
263 | }
264 | 100% {
265 | opacity: 1;
266 | -webkit-transform: none;
267 | transform: none;
268 | }
269 | }
270 |
271 | /* Simple CSS3 Fade-in Animation */
272 | @-webkit-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
273 | @-moz-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
274 | @keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
275 |
276 | .fadeIn {
277 | opacity:0;
278 | -webkit-animation:fadeIn ease-in 1;
279 | -moz-animation:fadeIn ease-in 1;
280 | animation:fadeIn ease-in 1;
281 |
282 | -webkit-animation-fill-mode:forwards;
283 | -moz-animation-fill-mode:forwards;
284 | animation-fill-mode:forwards;
285 |
286 | -webkit-animation-duration:1s;
287 | -moz-animation-duration:1s;
288 | animation-duration:1s;
289 | }
290 |
291 | .fadeIn.first {
292 | -webkit-animation-delay: 0.4s;
293 | -moz-animation-delay: 0.4s;
294 | animation-delay: 0.4s;
295 | }
296 |
297 | .fadeIn.second {
298 | -webkit-animation-delay: 0.6s;
299 | -moz-animation-delay: 0.6s;
300 | animation-delay: 0.6s;
301 | }
302 |
303 | .fadeIn.third {
304 | -webkit-animation-delay: 0.8s;
305 | -moz-animation-delay: 0.8s;
306 | animation-delay: 0.8s;
307 | }
308 |
309 | .fadeIn.fourth {
310 | -webkit-animation-delay: 1s;
311 | -moz-animation-delay: 1s;
312 | animation-delay: 1s;
313 | }
314 |
315 | /* Simple CSS3 Fade-in Animation */
316 | .underlineHover:after {
317 | display: block;
318 | left: 0;
319 | bottom: -10px;
320 | width: 0;
321 | height: 2px;
322 | background-color: #56baed;
323 | content: "";
324 | transition: width 0.2s;
325 | }
326 |
327 | .underlineHover:hover {
328 | color: #0d0d0d;
329 | }
330 |
331 | .underlineHover:hover:after{
332 | width: 100%;
333 | }
334 |
335 |
336 |
337 | /* OTHERS */
338 |
339 | *:focus {
340 | outline: none;
341 | }
342 |
343 | #icon {
344 | width:60%;
345 | }
346 |
347 | * {
348 | box-sizing: border-box;
349 | }
350 |
351 |
--------------------------------------------------------------------------------