diff --git a/README.md b/README.md
index 49c5ece..1d355ae 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# Simple Todo list
This is a simple todo list, written in javascript, using express for the backend and react+redux for the frontend.
-It also can work in offline thanks to redux-offline (without any conflict resolving, though).
+It also can work in offline thanks to redux-offline (without any conflict resolving, though). The code is of somewhat questionable quality, so you probably don't want to look at it.
## Getting started
diff --git a/client/package-lock.json b/client/package-lock.json
index 30a5601..4742f8c 100644
--- a/client/package-lock.json
+++ b/client/package-lock.json
@@ -4411,11 +4411,13 @@
},
"balanced-match": {
"version": "1.0.0",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
+ "optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@@ -4428,15 +4430,18 @@
},
"code-point-at": {
"version": "1.1.0",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"concat-map": {
"version": "0.0.1",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"console-control-strings": {
"version": "1.1.0",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"core-util-is": {
"version": "1.0.2",
@@ -4539,7 +4544,8 @@
},
"inherits": {
"version": "2.0.3",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"ini": {
"version": "1.3.5",
@@ -4549,6 +4555,7 @@
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
+ "optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@@ -4561,17 +4568,20 @@
"minimatch": {
"version": "3.0.4",
"bundled": true,
+ "optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "0.0.8",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"minipass": {
"version": "2.2.4",
"bundled": true,
+ "optional": true,
"requires": {
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
@@ -4588,6 +4598,7 @@
"mkdirp": {
"version": "0.5.1",
"bundled": true,
+ "optional": true,
"requires": {
"minimist": "0.0.8"
}
@@ -4660,7 +4671,8 @@
},
"number-is-nan": {
"version": "1.0.1",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"object-assign": {
"version": "4.1.1",
@@ -4670,6 +4682,7 @@
"once": {
"version": "1.4.0",
"bundled": true,
+ "optional": true,
"requires": {
"wrappy": "1"
}
@@ -4775,6 +4788,7 @@
"string-width": {
"version": "1.0.2",
"bundled": true,
+ "optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
diff --git a/client/src/actions/defs.js b/client/src/actions/defs.js
index b251233..1a9da67 100644
--- a/client/src/actions/defs.js
+++ b/client/src/actions/defs.js
@@ -36,3 +36,7 @@ export const START_LOGIN = 'INVALIDATE_USER';
export const REQUEST_USER = 'REQUEST_USER';
export const VALIDATE_USER = 'VALIDATE_USER';
export const RESET_USER = 'RESET_USER';
+export const EDIT_START = 'EDIT_START';
+export const EDIT_SUCCESS = 'EDIT_SUCCESS';
+export const EDIT_FAIL = 'EDIT_FAIL';
+export const RESET_EDIT = 'RESET_EDIT';
diff --git a/client/src/actions/user.js b/client/src/actions/user.js
index 6202766..0d44929 100644
--- a/client/src/actions/user.js
+++ b/client/src/actions/user.js
@@ -7,6 +7,10 @@ import {
SIGNUP_FAIL,
RESET_USER,
LOGOUT,
+ EDIT_START,
+ EDIT_SUCCESS,
+ EDIT_FAIL,
+ RESET_EDIT,
} from './defs';
import { API_ROOT, getToken, setToken } from './util';
@@ -122,6 +126,57 @@ export function signup(user) {
};
}
+
+function startEdit(user) {
+ return { type: EDIT_START, user };
+}
+
+function editSuccess(user) {
+ return { type: EDIT_SUCCESS, user };
+}
+
+function editFail(error) {
+ return { type: EDIT_FAIL, error };
+}
+
+export function edit(user) {
+ return async dispatch => {
+ dispatch(startEdit());
+ const response = await fetch(`${API_ROOT}/users/user`, {
+ body: JSON.stringify(user),
+ headers: {
+ Authorization: `Bearer ${getToken()}`,
+ 'content-type': 'application/json',
+ },
+ method: 'PATCH',
+ });
+ const json = await response.json();
+ if (json.success) {
+ dispatch(editSuccess(json.data));
+ } else {
+ dispatch(editFail(json.error));
+ }
+ };
+}
+
+export function deleteUser() {
+ return async dispatch => {
+ await fetch(`${API_ROOT}/users/user`, {
+ headers: {
+ Authorization: `Bearer ${getToken()}`,
+ 'content-type': 'application/json',
+ },
+ method: 'DELETE',
+ });
+ dispatch(reset());
+ };
+}
+
+
+export function resetEdit() {
+ return { type: RESET_EDIT };
+}
+
export function reset() {
return { type: RESET_USER };
}
diff --git a/client/src/components/App.js b/client/src/components/App.js
index 5729a4b..15d7feb 100644
--- a/client/src/components/App.js
+++ b/client/src/components/App.js
@@ -10,19 +10,25 @@ import './App.css';
const LoadableTodosView = Loadable({
loader: () => import('./todolist/TodosView'),
loading: () => loading,
- delay: 200,
+ delay: 1000,
});
const LoadableLoginForm = Loadable({
loader: () => import('./user/LoginForm'),
loading: () => loading,
- delay: 200,
+ delay: 1000,
});
const LoadableSignupForm = Loadable({
loader: () => import('./user/SignupForm'),
loading: () => loading,
- delay: 200,
+ delay: 1000,
+});
+
+const LoadableEditView = Loadable({
+ loader: () => import('./user/EditForm'),
+ loading: () => loading,
+ delay: 1000,
});
export default class App extends React.PureComponent {
@@ -40,6 +46,7 @@ export default class App extends React.PureComponent {