├── .gitignore
├── README.md
├── _redirects
├── package.json
├── public
├── favicon.ico
├── index.html
├── manifest.json
└── robots.txt
├── src
├── components
│ ├── App.js
│ ├── AppWrapper.js
│ ├── Database.js
│ ├── Header.js
│ ├── Loading.js
│ ├── Login.js
│ ├── LogoutBtn.js
│ ├── Schema.js
│ ├── Todo
│ │ ├── TodoFilters.js
│ │ ├── TodoInput.js
│ │ ├── TodoItem.js
│ │ ├── TodoList.js
│ │ └── TodoListWrapper.js
│ ├── auth0-variables.js
│ └── loading.svg
├── images
│ ├── checked.svg
│ └── logo.svg
├── index.js
├── serviceWorker.js
├── styles
│ └── App.css
└── utils
│ └── history.js
└── yarn.lock
/.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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
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 | ### `yarn start`
8 |
9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11 |
12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console.
14 |
15 | ### `yarn test`
16 |
17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19 |
20 | ### `yarn build`
21 |
22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance.
24 |
25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed!
27 |
28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29 |
30 | ### `yarn eject`
31 |
32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33 |
34 | 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.
35 |
36 | 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.
37 |
38 | 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.
39 |
40 | ## Learn More
41 |
42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43 |
44 | To learn React, check out the [React documentation](https://reactjs.org/).
45 |
46 | ### Code Splitting
47 |
48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49 |
50 | ### Analyzing the Bundle Size
51 |
52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53 |
54 | ### Making a Progressive Web App
55 |
56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57 |
58 | ### Advanced Configuration
59 |
60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61 |
62 | ### Deployment
63 |
64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65 |
66 | ### `yarn build` fails to minify
67 |
68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
69 |
--------------------------------------------------------------------------------
/_redirects:
--------------------------------------------------------------------------------
1 | /* / 200
2 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rxdb-hasura-demo",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "auth0-js": "^9.10.1",
7 | "bootstrap": "^4.1.3",
8 | "pouchdb-adapter-idb": "^7.1.1",
9 | "prop-types": "^15.6.2",
10 | "react": "^16.12.0",
11 | "react-bootstrap": "^0.32.4",
12 | "react-dom": "^16.12.0",
13 | "react-router": "^5.1.2",
14 | "react-router-dom": "^5.1.2",
15 | "rxdb": "^8.7.4",
16 | "uuid": "^3.3.3",
17 | "subscriptions-transport-ws": "^0.9.16",
18 | "graphql": "^14.5.8"
19 | },
20 | "devDependencies": {
21 | "husky": "^1.0.0-rc.15",
22 | "lint-staged": "^7.3.0",
23 | "prettier": "1.14.3",
24 | "react-scripts": "^3.3.0"
25 | },
26 | "scripts": {
27 | "start": "react-scripts start",
28 | "build": "react-scripts build && cp _redirects build/",
29 | "eject": "react-scripts eject",
30 | "lint": "eslint src/**/*.js",
31 | "lint:fix": "eslint src/**/*.js --fix"
32 | },
33 | "browserslist": [
34 | ">0.2%",
35 | "not dead",
36 | "not ie <= 11",
37 | "not op_mini all"
38 | ]
39 | }
40 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasura/rxdb-hasura-demo/e3cf1d23e65155d7fb7a2f3c75cc45975668adab/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 |
12 |
13 |
14 |
15 |
16 |
25 | RxDB Hasura Demo
26 |
27 |
28 |
29 | You need to enable JavaScript to run this app.
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | }
10 | ],
11 | "start_url": "./index.html",
12 | "display": "standalone",
13 | "theme_color": "#000000",
14 | "background_color": "#ffffff"
15 | }
16 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 |
--------------------------------------------------------------------------------
/src/components/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | import Header from './Header';
4 | import TodoListWrapper from './Todo/TodoListWrapper';
5 |
6 | const App = ({auth, db, logoutHandler}) => {
7 |
8 | return (
9 |
15 | );
16 | };
17 |
18 | export default App;
19 |
--------------------------------------------------------------------------------
/src/components/AppWrapper.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import auth0 from 'auth0-js';
3 |
4 | import history from '../utils/history';
5 | import { AUTH_CONFIG } from './auth0-variables';
6 | import App from './App';
7 | import Login from './Login';
8 |
9 | import * as Database from './Database';
10 | import Loading from './Loading';
11 |
12 | export default class AppWrapper extends React.Component {
13 | auth0 = new auth0.WebAuth({
14 | domain: AUTH_CONFIG.domain,
15 | clientID: AUTH_CONFIG.clientId,
16 | redirectUri: AUTH_CONFIG.callbackUrl,
17 | audience: `https://${AUTH_CONFIG.domain}/userinfo`,
18 | responseType: 'token id_token',
19 | scope: 'openid profile'
20 | });
21 |
22 | constructor() {
23 | super();
24 | this.login = this.login.bind(this);
25 | this.logout = this.logout.bind(this);
26 | this.handleAuthentication = this.handleAuthentication.bind(this);
27 | this.isExpired = this.isExpired.bind(this);
28 | this.getAccessToken = this.getAccessToken.bind(this);
29 | this.getIdToken = this.getIdToken.bind(this);
30 | this.renewSession = this.renewSession.bind(this);
31 |
32 | this.state = {
33 | idToken: null,
34 | userId: localStorage.getItem("userId"),
35 | db: null,
36 | };
37 | }
38 |
39 | login() {
40 | this.auth0.authorize();
41 | }
42 |
43 | handleAuthentication = () => {
44 | this.auth0.parseHash((err, authResult) => {
45 | if (authResult && authResult.accessToken && authResult.idToken) {
46 | this.setSession(authResult);
47 | } else if (err) {
48 | this.logout();
49 | console.error(err);
50 | alert(`Error: ${err.error} - ${err.errorDescription}`);
51 | }
52 | });
53 | };
54 |
55 | getAccessToken() {
56 | return this.accessToken;
57 | }
58 |
59 | getIdToken() {
60 | return this.idToken;
61 | }
62 |
63 | setSession(authResult) {
64 | // Set isLoggedIn flag in localStorage
65 | localStorage.setItem('isLoggedIn', 'true');
66 |
67 | // Set the time that the access token will expire at
68 | let expiresAt = (authResult.expiresIn * 1000) + new Date().getTime();
69 | this.accessToken = authResult.accessToken;
70 | this.idToken = authResult.idToken;
71 | this.expiresAt = expiresAt;
72 | this.userId = authResult.idTokenPayload.sub;
73 |
74 | localStorage.setItem('userId', this.userId);
75 |
76 | // navigate to the home route
77 | history.replace('/');
78 | this.setState({
79 | idToken: authResult.idToken,
80 | userId: this.userId,
81 | });
82 |
83 | this.graphqlReplicator.restart({ userId: this.userId, idToken: this.idToken });
84 | }
85 |
86 | renewSession() {
87 | setInterval(() => {
88 | const shouldRenewSession = this.isLoggedIn && (!this.idToken || this.isExpired());
89 |
90 | if (window.navigator.onLine && shouldRenewSession) {
91 | this.auth0.checkSession({}, (err, authResult) => {
92 | if (authResult && authResult.accessToken && authResult.idToken) {
93 | this.setSession(authResult);
94 | } else if (err) {
95 | this.logout();
96 | console.log(err);
97 | alert(`Could not get a new token (${err.error}: ${err.error_description}).`);
98 | }
99 | });
100 | }
101 | }, 5000);
102 | }
103 |
104 | logout() {
105 | // Remove tokens and expiry time
106 | this.accessToken = null;
107 | this.idToken = null;
108 | this.expiresAt = 0;
109 |
110 | // Remove isLoggedIn flag from localStorage
111 | localStorage.removeItem('isLoggedIn');
112 |
113 | this.auth0.logout({
114 | return_to: window.location.origin
115 | });
116 |
117 | // navigate to the home route
118 | history.replace('/');
119 | this.setState({
120 | idToken: null
121 | });
122 | }
123 |
124 | isExpired() {
125 | // Check whether the current time is past the
126 | // access token's expiry time
127 | let expiresAt = this.expiresAt;
128 | return new Date().getTime() > expiresAt;
129 | }
130 |
131 | async componentDidMount() {
132 | const db = await Database.createDb()
133 |
134 | this.setState({ db });
135 |
136 | this.graphqlReplicator = new Database.GraphQLReplicator(db);
137 |
138 | // If this is a callback URL then do the right things
139 | const location = this.props.location;
140 | if (location && location.pathname.startsWith('/callback') && /access_token|id_token|error/.test(location.hash)) {
141 | this.handleAuthentication();
142 | return;
143 | }
144 |
145 | if (this.isLoggedIn()) {
146 | this.renewSession();
147 | return;
148 | }
149 | }
150 |
151 | isLoggedIn() {
152 | return localStorage.getItem('isLoggedIn') === 'true'
153 | }
154 |
155 | render() {
156 | const location = this.props.location;
157 | const isCallbackPage = location && location.pathname.startsWith('/callback');
158 |
159 | if (!this.isLoggedIn() && !isCallbackPage) {
160 | return ( );
161 | }
162 |
163 | if(!this.state.db) {
164 | return
165 | }
166 |
167 | return ( );
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/src/components/Database.js:
--------------------------------------------------------------------------------
1 | import RxDB from 'rxdb';
2 |
3 | import { todoSchema } from './Schema';
4 |
5 | import RxDBSchemaCheckModule from 'rxdb/plugins/schema-check';
6 | import RxDBErrorMessagesModule from 'rxdb/plugins/error-messages';
7 | import RxDBValidateModule from 'rxdb/plugins/validate';
8 | import RxDBReplicationGraphQL from 'rxdb/plugins/replication-graphql';
9 |
10 | import { SubscriptionClient } from 'subscriptions-transport-ws';
11 |
12 | RxDB.plugin(RxDBSchemaCheckModule);
13 | RxDB.plugin(RxDBErrorMessagesModule);
14 | RxDB.plugin(RxDBValidateModule);
15 | RxDB.plugin(RxDBReplicationGraphQL);
16 |
17 | RxDB.plugin(require('pouchdb-adapter-idb'));
18 |
19 | export const createDb = async () => {
20 | console.log('DatabaseService: creating database..');
21 |
22 | const db = await RxDB.create({
23 | name: 'tododb',
24 | adapter: 'idb',
25 | password: '|8S_~|nC1>Vf&-9',
26 | queryChangeDetection: true
27 | });
28 |
29 | console.log('DatabaseService: created database');
30 | window['db'] = db; // write to window for debugging
31 |
32 | await db.collection({
33 | name: 'todos',
34 | schema: todoSchema
35 | })
36 |
37 | return db;
38 | };
39 |
40 |
41 | const syncURL = 'https://hasura1234567.herokuapp.com/v1/graphql';
42 |
43 | const batchSize = 5;
44 | const pullQueryBuilder = (userId) => {
45 | return (doc) => {
46 | if (!doc) {
47 | doc = {
48 | id: '',
49 | updatedAt: new Date(0).toUTCString()
50 | };
51 | }
52 |
53 | const query = `{
54 | todos(
55 | where: {
56 | _or: [
57 | {updatedAt: {_gt: "${doc.updatedAt}"}},
58 | {
59 | updatedAt: {_eq: "${doc.updatedAt}"},
60 | id: {_gt: "${doc.id}"}
61 | }
62 | ],
63 | userId: {_eq: "${userId}"}
64 | },
65 | limit: ${batchSize},
66 | order_by: [{updatedAt: asc}, {id: asc}]
67 | ) {
68 | id
69 | text
70 | isCompleted
71 | deleted
72 | createdAt
73 | updatedAt
74 | userId
75 | }
76 | }`;
77 | return {
78 | query,
79 | variables: {}
80 | };
81 | };
82 | };
83 |
84 | const pushQueryBuilder = doc => {
85 | const query = `
86 | mutation InsertTodo($todo: [todos_insert_input!]!) {
87 | insert_todos(
88 | objects: $todo,
89 | on_conflict: {
90 | constraint: todos_pkey,
91 | update_columns: [text, isCompleted, deleted, updatedAt]
92 | }){
93 | returning {
94 | id
95 | }
96 | }
97 | }
98 | `;
99 | const variables = {
100 | todo: doc
101 | };
102 |
103 | return {
104 | query,
105 | variables
106 | };
107 | };
108 |
109 | export class GraphQLReplicator {
110 | constructor(db) {
111 | this.db = db;
112 | this.replicationState = null;
113 | this.subscriptionClient = null;
114 | }
115 |
116 | async restart(auth) {
117 | if(this.replicationState) {
118 | this.replicationState.cancel()
119 | }
120 |
121 | if(this.subscriptionClient) {
122 | this.subscriptionClient.close()
123 | }
124 |
125 | this.replicationState = await this.setupGraphQLReplication(auth)
126 | this.subscriptionClient = this.setupGraphQLSubscription(auth, this.replicationState)
127 | }
128 |
129 | async setupGraphQLReplication(auth) {
130 | const replicationState = this.db.todos.syncGraphQL({
131 | url: syncURL,
132 | headers: {
133 | 'Authorization': `Bearer ${auth.idToken}`
134 | },
135 | push: {
136 | batchSize,
137 | queryBuilder: pushQueryBuilder
138 | },
139 | pull: {
140 | queryBuilder: pullQueryBuilder(auth.userId)
141 | },
142 | live: true,
143 | /**
144 | * Because the websocket is used to inform the client
145 | * when something has changed,
146 | * we can set the liveIntervall to a high value
147 | */
148 | liveInterval: 1000 * 60 * 10, // 10 minutes
149 | deletedFlag: 'deleted'
150 | });
151 |
152 | replicationState.error$.subscribe(err => {
153 | console.error('replication error:');
154 | console.dir(err);
155 | });
156 |
157 | return replicationState;
158 | }
159 |
160 | setupGraphQLSubscription(auth, replicationState) {
161 | const endpointUrl = 'wss://hasura1234567.herokuapp.com/v1/graphql';
162 | const wsClient = new SubscriptionClient(endpointUrl, {
163 | reconnect: true,
164 | connectionParams: {
165 | headers: {
166 | 'Authorization': `Bearer ${auth.idToken}`
167 | }
168 | },
169 | timeout: 1000 * 60,
170 | onConnect: () => {
171 | console.log('SubscriptionClient.onConnect()');
172 | },
173 | connectionCallback: () => {
174 | console.log('SubscriptionClient.connectionCallback:');
175 | },
176 | reconnectionAttempts: 10000,
177 | inactivityTimeout: 10 * 1000,
178 | lazy: true
179 | });
180 |
181 | const query = `subscription onTodoChanged {
182 | todos {
183 | id
184 | deleted
185 | isCompleted
186 | text
187 | }
188 | }`;
189 |
190 | const ret = wsClient.request({ query });
191 |
192 | ret.subscribe({
193 | next(data) {
194 | console.log('subscription emitted => trigger run');
195 | console.dir(data);
196 | replicationState.run();
197 | },
198 | error(error) {
199 | console.log('got error:');
200 | console.dir(error);
201 | }
202 | });
203 |
204 | return wsClient
205 | }
206 | }
207 |
--------------------------------------------------------------------------------
/src/components/Header.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {Nav, Navbar, NavItem} from 'react-bootstrap';
3 | import LogoutBtn from './LogoutBtn';
4 |
5 | const Header = ({logoutHandler}) => (
6 |
7 |
8 |
9 | RxDB - Hasura Demo App
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | );
20 |
21 | export default Header;
22 |
--------------------------------------------------------------------------------
/src/components/Loading.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import loadingSVG from "./loading.svg";
3 |
4 | export default class Loading extends Component {
5 | render() {
6 | const style = {
7 | position: "absolute",
8 | display: "flex",
9 | justifyContent: "center",
10 | height: "100vh",
11 | width: "100vw",
12 | top: 0,
13 | bottom: 0,
14 | left: 0,
15 | right: 0,
16 | backgroundColor: "white"
17 | };
18 |
19 | return (
20 |
21 |
22 |
23 | );
24 | }
25 | }
--------------------------------------------------------------------------------
/src/components/Login.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import {Button} from "react-bootstrap";
3 |
4 | const Login = ({loginHandler}) => (
5 |
6 |
7 |
8 | Welcome to RxDB Hasura tutorial app
9 |
10 |
11 | Please login to continue
12 |
13 |
14 |
19 | Log In
20 |
21 |
22 |
23 |
24 | );
25 |
26 | export default Login;
27 |
--------------------------------------------------------------------------------
/src/components/LogoutBtn.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {Button} from "react-bootstrap";
3 |
4 | const LogoutBtn = ({logoutHandler}) => (
5 |
11 | Log Out
12 |
13 | );
14 |
15 | export default LogoutBtn;
16 |
--------------------------------------------------------------------------------
/src/components/Schema.js:
--------------------------------------------------------------------------------
1 | export const todoSchema = {
2 | 'title': 'todo schema',
3 | 'description': 'todo schema',
4 | 'version': 0,
5 | 'type': 'object',
6 | 'properties': {
7 | 'id': {
8 | 'type': 'string',
9 | 'primary': true
10 | },
11 | 'text': {
12 | 'type': 'string'
13 | },
14 | 'isCompleted': {
15 | 'type': 'boolean'
16 | },
17 | 'createdAt': {
18 | 'type': 'string',
19 | 'format': 'date-time',
20 | 'index': true,
21 | },
22 | 'updatedAt': {
23 | 'type': 'string',
24 | 'format': 'date-time'
25 | },
26 | 'userId': {
27 | 'type': 'string'
28 | },
29 | },
30 | 'required': ['text', 'isCompleted', 'userId', 'createdAt'],
31 | additionalProperties: true
32 | };
33 |
--------------------------------------------------------------------------------
/src/components/Todo/TodoFilters.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable jsx-a11y/anchor-is-valid */
2 | import React from 'react';
3 |
4 | const TodoFilters = ({
5 | todos,
6 | currentFilter,
7 | filterResultsFn,
8 | clearCompletedFn
9 | }) => {
10 | const filterResultsHandler = (filter) => {
11 | return () => {
12 | filterResultsFn(filter);
13 | }
14 | };
15 |
16 | const clearCompletedButton = (
17 |
18 | Clear completed
19 |
20 | );
21 |
22 | const activeTodos = todos.filter(todo => todo.isCompleted !== true);
23 |
24 | let itemCount = todos.length;
25 | if (currentFilter === 'active') {
26 | itemCount = activeTodos.length;
27 | } else if (currentFilter === 'completed') {
28 | itemCount = todos.length - activeTodos.length;
29 | }
30 |
31 | return (
32 |
33 |
{itemCount} item{itemCount !== 1 ? "s" : ""}
34 |
35 |
54 |
55 | {clearCompletedButton}
56 |
57 | );
58 | };
59 |
60 | export default TodoFilters;
61 |
--------------------------------------------------------------------------------
/src/components/Todo/TodoInput.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from "prop-types";
3 | import uuidv4 from 'uuid/v4';
4 |
5 | class TodoInput extends React.Component {
6 | constructor() {
7 | super();
8 | this.state = {
9 | textboxValue: ""
10 | };
11 | this.handleTextboxValueChange = this.handleTextboxValueChange.bind(this);
12 | this.handleTextboxKeyPress = this.handleTextboxKeyPress.bind(this);
13 | }
14 |
15 | handleTextboxValueChange(e) {
16 | this.setState({
17 | textboxValue: e.target.value
18 | });
19 | }
20 |
21 | addTodo(text) {
22 | this.props.db.todos.insert({
23 | id: uuidv4(),
24 | text: text,
25 | isCompleted: false,
26 | createdAt: new Date().toISOString(),
27 | userId: this.props.auth.userId
28 | });
29 | }
30 |
31 | handleTextboxKeyPress(e) {
32 | if (e.key === "Enter") {
33 | const newTodo = this.state.textboxValue;
34 |
35 | this.addTodo(newTodo)
36 |
37 | this.setState({
38 | textboxValue: ""
39 | })
40 | }
41 | }
42 |
43 | render() {
44 | return (
45 |
46 | {
52 | this.handleTextboxKeyPress(e);
53 | }}
54 | />
55 |
56 |
57 | );
58 | };
59 |
60 | }
61 |
62 | TodoInput.propTypes = {
63 | auth: PropTypes.any.isRequired,
64 | };
65 |
66 | export default TodoInput;
67 |
--------------------------------------------------------------------------------
/src/components/Todo/TodoItem.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | const TodoItem = ({index, todo}) => {
4 |
5 | const removeTodo = (e) => {
6 | e.preventDefault();
7 | e.stopPropagation();
8 |
9 | todo.remove()
10 | };
11 |
12 | const toggleTodo = () => {
13 | delete todo._data["_deleted"]
14 | delete todo._data["_revisions"]
15 |
16 | todo.update({
17 | $set: {
18 | isCompleted: !todo.isCompleted,
19 | }
20 | })
21 | };
22 |
23 | return (
24 |
25 |
36 |
37 |
38 | {todo.text}
39 |
40 |
41 |
42 | x
43 |
44 |
45 | );
46 | };
47 |
48 | export default TodoItem;
49 |
--------------------------------------------------------------------------------
/src/components/Todo/TodoList.js:
--------------------------------------------------------------------------------
1 | import React, { Component, Fragment } from "react";
2 |
3 | import TodoItem from "./TodoItem";
4 | import TodoFilters from "./TodoFilters";
5 | import PropTypes from "prop-types";
6 |
7 | class TodoList extends Component {
8 | constructor(props) {
9 | super(props);
10 |
11 | this.state = {
12 | filter: "all",
13 | clearInProgress: false,
14 | };
15 |
16 | this.filterResults = this.filterResults.bind(this);
17 | this.clearCompleted = this.clearCompleted.bind(this);
18 | }
19 |
20 | filterResults(filter) {
21 | this.setState({
22 | ...this.state,
23 | filter: filter
24 | });
25 | }
26 |
27 | clearCompleted() {
28 | this.props.db.todos.find({ isCompleted: true}).remove()
29 | }
30 |
31 | render() {
32 | let todos = this.props.todos;
33 | let filteredTodos = todos;
34 | if (this.state.filter === "active") {
35 | filteredTodos = todos.filter(todo => todo.isCompleted !== true);
36 | } else if (this.state.filter === "completed") {
37 | filteredTodos = todos.filter(todo => todo.isCompleted === true);
38 | }
39 |
40 | const todoList = [];
41 | filteredTodos.forEach((todo, index) => {
42 | todoList.push(
43 |
48 | );
49 | });
50 |
51 | return (
52 |
53 |
58 |
59 |
66 |
67 | );
68 | }
69 | }
70 |
71 | TodoList.propTypes = {
72 | todos: PropTypes.array.isRequired,
73 | auth: PropTypes.any.isRequired,
74 | };
75 |
76 | export default TodoList;
77 |
--------------------------------------------------------------------------------
/src/components/Todo/TodoListWrapper.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 |
3 | import TodoInput from "./TodoInput";
4 | import TodoList from "./TodoList";
5 | import PropTypes from "prop-types";
6 |
7 | class TodoListWrapper extends Component {
8 | state = {
9 | todos: []
10 | }
11 |
12 | rxSubs = []
13 |
14 | async componentDidMount() {
15 | const sub = this.props.db.todos.find()
16 | .sort('createdAt').$.subscribe(todos => {
17 | if (!todos) {
18 | return;
19 | }
20 |
21 | this.setState({todos});
22 | });
23 | this.rxSubs.push(sub);
24 | }
25 |
26 | render() {
27 | return (
28 |
29 |
Todos
30 |
31 |
32 |
33 |
34 |
35 | );
36 | }
37 | }
38 |
39 | TodoListWrapper.propTypes = {
40 | auth: PropTypes.any.isRequired,
41 | };
42 |
43 | export default TodoListWrapper;
44 |
--------------------------------------------------------------------------------
/src/components/auth0-variables.js:
--------------------------------------------------------------------------------
1 | export const AUTH_CONFIG = {
2 | domain: 'l1cache.auth0.com',
3 | clientId: 'g8VusvQ1M9BpCURVjm6shT9gQePDHyJE',
4 | callbackUrl: 'https://rxdb-hasura-demo.netlify.app/callback'
5 | };
6 |
--------------------------------------------------------------------------------
/src/components/loading.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/images/checked.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/images/logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import ReactDOM from "react-dom";
2 | import React from "react";
3 | import { Route, Router } from "react-router-dom";
4 |
5 | import './styles/App.css';
6 |
7 | import AppWrapper from "./components/AppWrapper";
8 | import history from "./utils/history";
9 | import * as serviceWorker from './serviceWorker';
10 |
11 | const mainRoutes = (
12 |
13 | ( )} />
14 |
15 | );
16 |
17 | ReactDOM.render(mainRoutes, document.getElementById("root"));
18 |
19 | serviceWorker.register();
20 |
--------------------------------------------------------------------------------
/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 https://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.0/8 are 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 https://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 https://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 | headers: { 'Service-Worker': 'script' }
105 | })
106 | .then(response => {
107 | // Ensure service worker exists, and that we really are getting a JS file.
108 | const contentType = response.headers.get('content-type');
109 | if (
110 | response.status === 404 ||
111 | (contentType != null && contentType.indexOf('javascript') === -1)
112 | ) {
113 | // No service worker found. Probably a different app. Reload the page.
114 | navigator.serviceWorker.ready.then(registration => {
115 | registration.unregister().then(() => {
116 | window.location.reload();
117 | });
118 | });
119 | } else {
120 | // Service worker found. Proceed as normal.
121 | registerValidSW(swUrl, config);
122 | }
123 | })
124 | .catch(() => {
125 | console.log(
126 | 'No internet connection found. App is running in offline mode.'
127 | );
128 | });
129 | }
130 |
131 | export function unregister() {
132 | if ('serviceWorker' in navigator) {
133 | navigator.serviceWorker.ready.then(registration => {
134 | registration.unregister();
135 | });
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/src/styles/App.css:
--------------------------------------------------------------------------------
1 | @import url("https://fonts.googleapis.com/css?family=Open+Sans:400,600,700");
2 |
3 | body {
4 | background-color: #f7f7f7;
5 | font-weight: 400;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | font-family: sans-serif;
9 | font-size: 14px;
10 | }
11 | @media (min-width: 899px) {
12 | .todo-list {
13 | margin-left: 300px;
14 | }
15 | }
16 |
17 | .todo-list {
18 | min-width: 230px;
19 | max-width: 550px;
20 | }
21 |
22 | .wd-95 {
23 | width: 95%;
24 | margin: 0 auto;
25 | }
26 |
27 | .p-left-0 {
28 | padding-left: 0;
29 | }
30 |
31 | .p-left-right-0 {
32 | padding-left: 0;
33 | padding-right: 0;
34 | }
35 |
36 | .p-30 {
37 | padding: 30px;
38 | }
39 |
40 | .p-top-bottom-30 {
41 | padding-top: 30px;
42 | padding-bottom: 30px;
43 | }
44 |
45 | .border-right {
46 | border-right: 1px solid #ccc;
47 | }
48 |
49 | .bg-gray {
50 | background-color: #efeded;
51 | }
52 |
53 | .display-block {
54 | display: block;
55 | }
56 |
57 | .m-bottom-0 {
58 | margin-bottom: 0;
59 | }
60 |
61 | .m-bottom-10 {
62 | margin-bottom: 10px;
63 | }
64 |
65 | .m-bottom-20 {
66 | margin-bottom: 20px;
67 | }
68 |
69 | .navHeader {
70 | width: 100%;
71 | }
72 |
73 | .navHeader button {
74 | padding: 3.75px 7.5px;
75 | font-size: 14px;
76 | }
77 |
78 | .breakWord {
79 | word-wrap: break-word;
80 | }
81 |
82 | .navBrand {
83 | font-size: 14px;
84 | }
85 |
86 | .todoWrapper {
87 | position: relative;
88 | width: 100%;
89 | }
90 |
91 | .sectionHeader {
92 | font-size: 80px;
93 | font-weight: 100;
94 | color: rgba(175, 47, 47, 0.15);
95 | padding-bottom: 20px;
96 | text-align: center;
97 | }
98 |
99 | .formInput input {
100 | height: 60px;
101 | padding: 16px 16px 16px 60px;
102 | border: none;
103 | background-color: #fff;
104 | width: 100%;
105 | -webkit-box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
106 | -moz-box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
107 | box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
108 | opacity: 0.6;
109 | font-size: 14px;
110 | }
111 |
112 |
113 | .formInput {
114 | position: relative;
115 | display: flex;
116 | align-items: center;
117 | }
118 |
119 | .inputMarker {
120 | position: absolute;
121 | left: 15px;
122 | font-size: 25px;
123 | opacity: 0.6;
124 | }
125 |
126 | .todoListWrapper {
127 | border-top: 1px solid #e6e6e6;
128 | -webkit-box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
129 | -moz-box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
130 | box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
131 | }
132 |
133 | .todoListWrapper ul {
134 | -webkit-padding-start: 0px;
135 | -moz-padding-start: 0px;
136 | margin-bottom: 0;
137 | }
138 |
139 | .todoListWrapper ul li {
140 | list-style-type: none;
141 | min-height: 60px;
142 | max-height: 60px;
143 | /* overflow: auto; */
144 | display: flex;
145 | font-size: 14px;
146 | align-items: center;
147 | border-bottom: 1px solid #ededed;
148 | background-color: #fff;
149 | position: relative;
150 | }
151 |
152 | .closeBtn {
153 | background-color: transparent;
154 | border: none;
155 | color: #cc9a9a;
156 | position: absolute;
157 | right: 15px;
158 | padding: 0;
159 | font-size: 25px;
160 | }
161 |
162 | .closeBtn i {
163 | font-size: 20px;
164 | }
165 |
166 | .closeBtn:hover {
167 | color: #af5b5e;
168 | }
169 |
170 | .closeBtn:focus {
171 | outline: none;
172 | }
173 |
174 | .labelContent {
175 | padding: 15px 15px 15px 15px;
176 | font-size: 20px;
177 | color: #777;
178 | width: calc(100% - 128px);
179 | max-height: 60px;
180 | overflow: auto;
181 | display: flex;
182 | align-items: center;
183 | }
184 |
185 | .labelContent.completed {
186 | text-decoration: line-through;
187 | }
188 |
189 | .view {
190 | width: 28px;
191 | height: 28px;
192 | margin: 0 15px;
193 | }
194 |
195 | .footerList {
196 | height: 60px;
197 | background-color: #fff;
198 | border-bottom: 1px solid #ededed;
199 | display: flex;
200 | align-items: center;
201 | padding: 0 15px;
202 | margin-bottom: 30px;
203 | }
204 |
205 | .footerList:before {
206 | content: "";
207 | position: absolute;
208 | right: 0;
209 | bottom: 0;
210 | left: 0;
211 | height: 50px;
212 | overflow: hidden;
213 | box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2), 0 8px 0 -3px #f6f6f6,
214 | 0 9px 1px -3px rgba(0, 0, 0, 0.2), 0 16px 0 -6px #f6f6f6,
215 | 0 17px 2px -6px rgba(0, 0, 0, 0.2);
216 | -moz-box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2), 0 8px 0 -3px #f6f6f6,
217 | 0 9px 1px -3px rgba(0, 0, 0, 0.2), 0 16px 0 -6px #f6f6f6,
218 | 0 17px 2px -6px rgba(0, 0, 0, 0.2);
219 | -webkit-box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2), 0 8px 0 -3px #f6f6f6,
220 | 0 9px 1px -3px rgba(0, 0, 0, 0.2), 0 16px 0 -6px #f6f6f6,
221 | 0 17px 2px -6px rgba(0, 0, 0, 0.2);
222 | }
223 |
224 | .footerList ul {
225 | -webkit-padding-start: 0px;
226 | -moz-padding-start: 0px;
227 | margin-bottom: 0;
228 | padding-left: 20px;
229 | z-index: 1;
230 | }
231 |
232 | .footerList ul li {
233 | list-style-type: none;
234 | display: inline-block;
235 | }
236 |
237 | .footerList ul li a {
238 | padding: 3px 7px;
239 | border: 1px solid transparent;
240 | border-radius: 3px;
241 | color: #777;
242 | cursor: pointer;
243 | }
244 |
245 | .footerList ul li a.selected {
246 | border-color: rgba(175, 47, 47, 0.2);
247 | }
248 |
249 | .clearComp {
250 | background-color: transparent;
251 | border: none;
252 | color: #777;
253 | position: absolute;
254 | right: 15px;
255 | padding: 0;
256 | }
257 |
258 | .clearComp:focus {
259 | outline: none;
260 | }
261 |
262 | .sliderMenu {
263 | height: calc(100vh - 50px);
264 | overflow-y: auto;
265 | }
266 |
267 | .sliderHeader {
268 | padding-bottom: 20px;
269 | text-transform: uppercase;
270 | font-weight: 600;
271 | }
272 |
273 | .userInfo {
274 | padding: 10px 0 10px 15px;
275 | display: flex;
276 | align-items: center;
277 | }
278 |
279 | .userInfo:hover {
280 | background-color: #e0e0e0;
281 | }
282 |
283 | .userImg {
284 | text-align: center;
285 | padding-right: 10px;
286 | }
287 |
288 | .userImg i {
289 | font-size: 20px;
290 | }
291 |
292 | .userImg img {
293 | width: 30px;
294 | }
295 |
296 | /*Custom Checkbox */
297 | .round {
298 | position: relative;
299 | }
300 |
301 | .round label {
302 | background-color: #fff;
303 | border: 1px solid #ccc;
304 | border-radius: 50%;
305 | cursor: pointer;
306 | height: 28px;
307 | left: 0;
308 | position: absolute;
309 | top: 0;
310 | width: 28px;
311 | min-width: 28px;
312 | }
313 |
314 | .round label:after {
315 | border: 2px solid #66bb6a;
316 | border-top: none;
317 | border-right: none;
318 | content: "";
319 | height: 6px;
320 | left: 7px;
321 | opacity: 0;
322 | position: absolute;
323 | top: 8px;
324 | transform: rotate(-45deg);
325 | width: 12px;
326 | }
327 |
328 | .round input[type="checkbox"] {
329 | visibility: hidden;
330 | }
331 |
332 | .round input[type="checkbox"]:checked + label {
333 | background-color: #fff;
334 | border-color: #66bb6a;
335 | }
336 |
337 | .round input[type="checkbox"]:checked + label:after {
338 | opacity: 1;
339 | }
340 |
341 | .loadMoreSection {
342 | list-style-type: none;
343 | height: 30px;
344 | display: -ms-flexbox;
345 | display: flex;
346 | font-size: 14px;
347 | -ms-flex-align: center;
348 | align-items: center;
349 | border-bottom: 1px solid #ededed;
350 | background-color: #e6ecf0;
351 | position: relative;
352 | justify-content: center;
353 | cursor: pointer;
354 | }
355 |
356 | .overlay {
357 | position: fixed;
358 | display: block;
359 | top: 0;
360 | left: 0;
361 | right: 0;
362 | bottom: 0;
363 | background-color: #ddd;
364 | z-index: 2;
365 | }
366 |
367 | .overlay .overlay-content {
368 | position: absolute;
369 | top: 40%;
370 | left: 50%;
371 | font-size: 18px;
372 | text-align: center;
373 | transform: translate(-50%,-50%);
374 | -ms-transform: translate(-50%,-50%);
375 | }
376 |
377 | .overlay .overlay-heading {
378 | font-size: 24px;
379 | font-weight: 500;
380 | margin-bottom: 20px;
381 | color: #444;
382 | }
383 |
384 | .overlay .overlay-message {
385 | color: #5f5f5f;
386 | }
387 |
388 | .overlay .overlay-action {
389 | margin-top: 10px;
390 | }
391 |
392 | @media (max-width: 991px) {
393 | .sliderMenu {
394 | height: auto;
395 | }
396 |
397 | .labelContent {
398 | display: block;
399 | }
400 | }
401 |
--------------------------------------------------------------------------------
/src/utils/history.js:
--------------------------------------------------------------------------------
1 | import createHistory from "history/createBrowserHistory";
2 |
3 | export default createHistory();
4 |
--------------------------------------------------------------------------------