From 2c7054f36b534db38515f980d1df699d1296ac27 Mon Sep 17 00:00:00 2001 From: Bulah Sergey Date: Tue, 31 Oct 2017 20:48:02 +0200 Subject: [PATCH] refactor some code --- README.md | 16 ++++++++-------- client/api/index.js | 3 +++ client/components/App.jsx | 16 ++++++---------- client/components/App.less | 8 -------- client/components/Navbar.jsx | 1 + client/components/Navbar.less | 11 ++++++++++- client/main.js | 7 +++++-- package.json | 2 +- public/css/style.css | 28 ++++++++++++++++++++++++++++ public/index.html | 7 +++++-- server/controllers/note.js | 4 ++++ 11 files changed, 71 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 0fe7385..4874e49 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ # notes -############ +########################################################### training project based on: ---node ---express - ---react - ---flux -############ + ---react with flux pattern +########################################################### thanks to: +awesome vebinar ==> https://github.com/krambertech @@ -13,8 +12,9 @@ thanks to: https://www.youtube.com/watch?v=iGbw7FFpvXQ +awesome flux ==> https://habrahabr.ru/post/249279 - -todo: - -colorpicker; - -auth; + +awesome best-practice ==> + https://github.com/khotey + + + diff --git a/client/api/index.js b/client/api/index.js index 138cad0..3f60595 100644 --- a/client/api/index.js +++ b/client/api/index.js @@ -4,6 +4,8 @@ import { apiPrefix } from '../etc/config.json'; //super agent instead of axis + +//todo:add an api for updateNote export default { listNote () { return request.get(`${apiPrefix}/notes`).then(); @@ -11,6 +13,7 @@ export default { createNote (data) { return request.post(`${apiPrefix}/notes`).send(data).then(); }, + //updateNote () deleteNote (noteId) { return request.del(`${apiPrefix}/notes/${noteId}`).then(); } diff --git a/client/components/App.jsx b/client/components/App.jsx index 59ef1b7..300f672 100644 --- a/client/components/App.jsx +++ b/client/components/App.jsx @@ -3,19 +3,19 @@ import React from 'react'; import NotesStore from '../stores/NotesStore'; import NotesActions from '../actions/NotesActions'; -import {NotesEditor} from "./NotesEditor.jsx"; -import {NotesGrid} from "./NotesGrid.jsx"; -import {Navbar} from "./Navbar.jsx"; +import {NotesEditor} from './NotesEditor.jsx'; +import {NotesGrid} from './NotesGrid.jsx'; +import {Navbar} from './Navbar.jsx'; import './App.less'; -function getStateFromFlux() { +const getStateFromFlux = () => { return { isLoading: NotesStore.isLoading(), notes: NotesStore.getNotes() } -} +}; export class App extends React.Component { constructor(props) { @@ -49,14 +49,10 @@ export class App extends React.Component { this.setState({noteToEdit: data}); } - handleAuthentication() { - - } render() { return ( -
-

Notes App

+
Category
About
+

Notes App

diff --git a/client/components/Navbar.less b/client/components/Navbar.less index e8ff183..b80900f 100644 --- a/client/components/Navbar.less +++ b/client/components/Navbar.less @@ -3,7 +3,6 @@ flex-direction: row; flex-wrap: wrap; justify-content: space-between; - background-color: #FFFFFF; box-sizing: border-box; margin-bottom: 15px; border-radius: 2px; @@ -38,6 +37,16 @@ } } +.Navbar__header { + align-self: center; + text-align: center; + font-weight: 500; + color: grey; + text-shadow: 0px 2px 3px rgba(255,255,255,0.5); + margin: 0 auto; +} + + .Navbar__authentication { display: flex; align-items: stretch; diff --git a/client/main.js b/client/main.js index 48d2774..4a08004 100644 --- a/client/main.js +++ b/client/main.js @@ -1,8 +1,11 @@ import React from 'react'; import ReactDOM from 'react-dom'; +import {BrowserRouter} from 'react-router-dom'; import {App} from "./components/App.jsx"; ReactDOM.render( - , - document.getElementById('mount-point') + + + + , document.getElementById('mount-point') ); \ No newline at end of file diff --git a/package.json b/package.json index 25c5a38..a3f6e85 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,9 @@ "cors": "^2.8.4", "events": "^1.1.1", "express": "^4.15.4", - "express-jwt": "^5.3.0", "express-session": "^1.15.5", "flux": "^3.1.3", + "jsonwebtoken": "^8.0.0", "keymirror": "^0.1.1", "less": "^2.7.2", "mongoose": "^4.11.7", diff --git a/public/css/style.css b/public/css/style.css index fcf6b4c..a6a8b9c 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -12,4 +12,32 @@ body { display: flex; flex-direction: column; align-items: center; + align-content: center; +} + +#loader { + position: absolute; + left: 50%; + top: 50%; + z-index: 1; + width: 150px; + height: 150px; + margin: -75px 0 0 -75px; + border: 16px solid #f3f3f3; + border-radius: 50%; + border-top: 16px solid #80D8FF; + width: 120px; + height: 120px; + -webkit-animation: spin 2s linear infinite; + animation: spin 2s linear infinite; +} + +@-webkit-keyframes spin { + 0% { -webkit-transform: rotate(0deg); } + 100% { -webkit-transform: rotate(360deg); } +} + +@keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } } \ No newline at end of file diff --git a/public/index.html b/public/index.html index ca8aff2..771fbaa 100644 --- a/public/index.html +++ b/public/index.html @@ -3,11 +3,14 @@ NotePad + -
- +
+
+ + \ No newline at end of file diff --git a/server/controllers/note.js b/server/controllers/note.js index dd3ca10..119f49e 100644 --- a/server/controllers/note.js +++ b/server/controllers/note.js @@ -14,7 +14,11 @@ export const getNotes = (req, res, next) => { }; export const addNote = (req, res, next) => { + console.log(req.body); const data = req.body; + const userId = req.user ? req.userId : undefined; + + Note.userId = userId; Note.create(data) .then(data => {