From cc4dff0ca1a9dde4397e3cfed60b0e615cccb804 Mon Sep 17 00:00:00 2001 From: muerwre Date: Thu, 6 Dec 2018 14:13:36 +0700 Subject: [PATCH] backend: fixed loading of routes --- backend/models/Route.js | 5 +- backend/routes/auth/check.js | 21 +++++--- backend/routes/route/post.js | 4 +- package-lock.json | 13 +++-- package.json | 1 + src/components/dialogs/MapListDialog.jsx | 20 +++++--- src/components/dialogs/StickersDialog.jsx | 2 +- src/modules/Sticker.js | 61 ++++++----------------- src/redux/user/sagas.js | 12 ++++- src/styles/dialogs.less | 8 +++ 10 files changed, 73 insertions(+), 74 deletions(-) diff --git a/backend/models/Route.js b/backend/models/Route.js index 51426b7..0d3ba0f 100644 --- a/backend/models/Route.js +++ b/backend/models/Route.js @@ -14,10 +14,9 @@ const RouteSchema = new Schema( logo: { type: String, default: 'DEFAULT' }, distance: { type: Number, default: 0 }, public: { type: Boolean, default: true }, + created_at: { type: Date, default: Date.now() }, + updated_at: { type: Date, default: Date.now() }, }, - { - timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' } - } ); module.exports.RouteSchema = RouteSchema; diff --git a/backend/routes/auth/check.js b/backend/routes/auth/check.js index 4053922..0cecf94 100644 --- a/backend/routes/auth/check.js +++ b/backend/routes/auth/check.js @@ -4,17 +4,22 @@ const { generateGuest, generateRandomUrl } = require('./guest'); module.exports = async (req, res) => { const { id, token } = req.query; - const user = await User.findOne({ _id: id, token }).populate({ - path: 'routes', - options: { - limit: 100, - sort: { updated_at: -1 }, - } - }); + const user = await User.findOne({ _id: id, token }) + .populate({ + path: 'routes', + select: '_id title distance owner updated_at', + options: { + limit: 100, + sort: { updated_at: -1 }, + } + }); + const random_url = await generateRandomUrl(); if (user) { - return res.send({ success: true, ...user.toObject(), id: user._id, random_url }); + return res.send({ + success: true, ...user.toObject(), id: user._id, random_url + }); } const guest = await generateGuest(); diff --git a/backend/routes/route/post.js b/backend/routes/route/post.js index e22a5d8..a551961 100644 --- a/backend/routes/route/post.js +++ b/backend/routes/route/post.js @@ -25,7 +25,9 @@ module.exports = async (req, res) => { if (exists && !force) return res.send({ success: false, mode: 'overwriting' }); if (exists) { - exists.set({ title, route, stickers, logo, distance }).save(); + exists.set({ + title, route, stickers, logo, distance, updated_at: Date.now(), + }).save(); return res.send({ success: true, title, address, route, stickers, mode: 'overwrited' diff --git a/package-lock.json b/package-lock.json index 21f2b2e..582b9c0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4108,10 +4108,9 @@ } }, "date-fns": { - "version": "1.29.0", - "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.29.0.tgz", - "integrity": "sha512-lbTXWZ6M20cWH8N9S6afb0SBm6tMk+uUg6z3MqHPKE9atmsY3kJkTm8vKe93izJ2B2+q5MV990sM2CHgtAZaOw==", - "dev": true + "version": "2.0.0-alpha.25", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.0.0-alpha.25.tgz", + "integrity": "sha512-iQzJkHF0L4wah9Ae9PkvwemwFz6qmRLuNZcghmvf2t+ptLs1qXzONLiGtjmPQzL6+JpC01JjlTopY2AEy4NFAg==" }, "date-now": { "version": "0.1.4", @@ -8437,6 +8436,12 @@ "restore-cursor": "^1.0.1" } }, + "date-fns": { + "version": "1.29.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.29.0.tgz", + "integrity": "sha512-lbTXWZ6M20cWH8N9S6afb0SBm6tMk+uUg6z3MqHPKE9atmsY3kJkTm8vKe93izJ2B2+q5MV990sM2CHgtAZaOw==", + "dev": true + }, "figures": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz", diff --git a/package.json b/package.json index e30246b..e86b11b 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "clean-webpack-plugin": "^0.1.9", "cookie-parser": "~1.4.3", "croppr": "^2.3.1", + "date-fns": "^2.0.0-alpha.25", "debug": "~2.6.9", "express": "~4.16.0", "file-saver": "^2.0.0", diff --git a/src/components/dialogs/MapListDialog.jsx b/src/components/dialogs/MapListDialog.jsx index c65d605..39b11de 100644 --- a/src/components/dialogs/MapListDialog.jsx +++ b/src/components/dialogs/MapListDialog.jsx @@ -4,28 +4,32 @@ import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import { RouteRow } from '$components/maps/RouteRow'; import type { Route } from '$constants/types'; +import { compareDesc } from 'date-fns'; type Props = { routes: { [id: String]: Route }, editing: Boolean, + routes_sorted: Array, }; -const Component = ({ routes, editing }: Props) => ( +const Component = ({ routes, editing, routes_sorted }: Props) => (
{ - Object.keys(routes).map(id => ( - + routes_sorted.map(id => ( + )) }
); const mapStateToProps = ({ user: { editing, user: { routes } } }) => ({ - routes, editing, + routes, + editing, + routes_sorted: Object.keys(routes).sort((a, b) => compareDesc(routes[a].updated_at, routes[b].updated_at)), }); const mapDispatchToProps = dispatch => bindActionCreators({ diff --git a/src/components/dialogs/StickersDialog.jsx b/src/components/dialogs/StickersDialog.jsx index 792a56d..6819443 100644 --- a/src/components/dialogs/StickersDialog.jsx +++ b/src/components/dialogs/StickersDialog.jsx @@ -11,7 +11,7 @@ export const StickersDialog = ({ setActiveSticker }: Props) => (
{ Object.keys(STICKERS).map(set => ( -
+
{STICKERS[set].title || null}
{ diff --git a/src/modules/Sticker.js b/src/modules/Sticker.js index 942e00b..1931a6a 100644 --- a/src/modules/Sticker.js +++ b/src/modules/Sticker.js @@ -35,11 +35,17 @@ export class Sticker {
{ this.stickerImage = el; }} - onMouseDown={this.onDragStart} - onMouseUp={this.onDragStop} > - {this.generateStickerSVG(set, sticker)} +
{ @@ -116,16 +102,15 @@ export class Sticker { onDragStop = e => { this.preventPropagations(e); - if (!this.marker) return; - this.triggerOnChange(); this.isDragging = false; - this.marker.enableEdit(); window.removeEventListener('mousemove', this.onDrag); window.removeEventListener('mouseup', this.onDragStop); this.lockMapClicks(false); + + this.marker.enableEdit(); }; onDrag = e => { @@ -150,34 +135,16 @@ export class Sticker { } const rad = 56; - // const mrad = 76; + const x = ((Math.cos(angle + Math.PI) * rad) - 30); const y = ((Math.sin(angle + Math.PI) * rad) - 30); - // const ax = ((Math.cos(angle + 3.4) * mrad) - 12); - // const ay = ((Math.sin(angle + 3.4) * mrad) - 12); - this.stickerImage.style.left = 6 + x; this.stickerImage.style.top = 6 + y; - // this.stickerDelete.style.left = ax; - // this.stickerDelete.style.top = ay; - this.stickerArrow.style.transform = `rotate(${angle + Math.PI}rad)`; }; - generateStickerSVG = (set, sticker) => { - return ( -
- ); - }; - dumpData = () => ({ angle: this.angle, latlng: { ...this.marker.getLatLng() }, diff --git a/src/redux/user/sagas.js b/src/redux/user/sagas.js index f1773f5..ed1955b 100644 --- a/src/redux/user/sagas.js +++ b/src/redux/user/sagas.js @@ -242,15 +242,24 @@ function* sendSaveRequestSaga({ title, address, force }) { return yield put(setSaveSuccess({ address: result.address, save_error: TIPS.SAVE_SUCCESS, title })); } +function* refreshUserData() { + const user = yield select(getUser); + const data = yield call(checkUserToken, user); + + return yield put(setUser(data)); +} + function* setSaveSuccessSaga({ address, title }) { const { id } = yield select(getUser); pushPath(`/${address}/edit`); yield put(setTitle(title)); yield put(setAddress(address)); - // yield editor.setAddress(address); + yield editor.owner = id; + yield call(refreshUserData); + return yield editor.setInitialData(); } @@ -353,7 +362,6 @@ function* locationChangeSaga({ location }) { function* gotVkUserSaga({ user }) { const data = yield call(checkUserToken, user); - yield put(setUser(data)); } diff --git a/src/styles/dialogs.less b/src/styles/dialogs.less index 19da2df..7586d2f 100644 --- a/src/styles/dialogs.less +++ b/src/styles/dialogs.less @@ -52,6 +52,10 @@ .route-title { margin-bottom: 5px; font-weight: bold; + + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; } .route-description { @@ -71,5 +75,9 @@ span { padding-right: 10px; + + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; } }