diff --git a/backend/routes/auth/check.js b/backend/routes/auth/check.js index 858ea73..76c07f3 100644 --- a/backend/routes/auth/check.js +++ b/backend/routes/auth/check.js @@ -4,15 +4,15 @@ 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', - select: '_id title distance owner updated_at', - options: { - limit: 200, - sort: { updated_at: -1 }, - } - }); + const user = await User.findOne({ _id: id, token }); + // .populate({ + // path: 'routes', + // select: '_id title distance owner updated_at', + // options: { + // limit: 200, + // sort: { updated_at: -1 }, + // } + // }) const random_url = await generateRandomUrl(); diff --git a/backend/routes/route/list.js b/backend/routes/route/list.js index 423ad95..13c7fab 100644 --- a/backend/routes/route/list.js +++ b/backend/routes/route/list.js @@ -32,12 +32,12 @@ module.exports = async (req, res) => { { ...criteria, }, - '_id title distance owner updated_at', + '_id title distance owner updated_at is_public', { limit: 500, sort: { updated_at: -1 }, } - ).populate('owner'); + ).populate('owner', '_id'); list = list.filter(item => ( !author || item.owner._id === author diff --git a/src/components/Switch.jsx b/src/components/Switch.jsx index 022487b..d65662b 100644 --- a/src/components/Switch.jsx +++ b/src/components/Switch.jsx @@ -4,7 +4,6 @@ import classnames from 'classnames'; type Props = { active: Boolean, - onPress: Function, } export const Switch = ({ active, onPress = () => {} }: Props) => ( diff --git a/src/components/dialogs/MapListDialog.jsx b/src/components/dialogs/MapListDialog.jsx index a28dbee..36047cc 100644 --- a/src/components/dialogs/MapListDialog.jsx +++ b/src/components/dialogs/MapListDialog.jsx @@ -28,8 +28,11 @@ type Props = { author: String, distance: Array, tab: Array, - } + min: number, + max: number, + }, }, + marks: { [x: number]: string }, editing: Boolean, routes_sorted: Array, @@ -39,7 +42,18 @@ type Props = { setDialogActive: Function, }; -class Component extends React.Component { +type State = { + editing_item: ?string, +} + +class Component extends React.Component { + state = { + editing_item: null, + }; + + startEditing = editing_item => this.setState({ editing_item }); + stopEditing = () => this.setState({ editing_item: null }); + setTitle = ({ target: { value } }) => { this.props.searchSetTitle(value); }; @@ -67,6 +81,8 @@ class Component extends React.Component { marks, } = this.props; + const { editing_item } = this.state; + return (
{ list.length === 0 && loading && @@ -136,9 +152,12 @@ class Component extends React.Component { )) } diff --git a/src/components/maps/RouteRow.jsx b/src/components/maps/RouteRow.jsx index bdd1128..340f250 100644 --- a/src/components/maps/RouteRow.jsx +++ b/src/components/maps/RouteRow.jsx @@ -1,41 +1,67 @@ // @flow import React from 'react'; import { Icon } from '$components/panels/Icon'; +import classnames from 'classnames'; +import { RouteRowEditor } from '$components/maps/RouteRowEditor'; type Props = { - title: String, - distance: Number, - created_at: String, - _id: String, - editing: Boolean, + _id: string, + title: string, + distance: number, + tab: string, + is_editing: boolean, + is_public: boolean, - openRoute: Function, + + openRoute: (_id: string) => {}, + startEditing: (_id: string) => {}, + stopEditing: () => {}, }; export const RouteRow = ({ - title, distance, _id, openRoute, tab, + title, distance, _id, openRoute, tab, is_editing, startEditing, stopEditing, is_public }: Props) => ( -
-
openRoute(_id)} - > -
+
+ { + tab === 'mine' && +
startEditing(_id)}>
-
- {title || _id} -
-
- - - {_id} - - - - {(distance && `${distance} km`) || '0 km'} - -
-
+ } + { + !is_editing + ? +
+
openRoute(_id)}> +
+ {(title || _id)} +
+
+ + + {_id} + + + + {(distance && `${distance} km`) || '0 km'} + +
+
+
+
+ + Удалить +
+
startEditing(_id)}> + + Правка +
+
+
+ : + } +
); diff --git a/src/components/maps/RouteRowEditor.jsx b/src/components/maps/RouteRowEditor.jsx new file mode 100644 index 0000000..9f2d7d7 --- /dev/null +++ b/src/components/maps/RouteRowEditor.jsx @@ -0,0 +1,81 @@ +// @flow +import React from 'react'; +import { Icon } from '$components/panels/Icon'; +import { Switch } from '$components/Switch'; + +type Props = { + title: string, + is_public: boolean, + distance: number, + _id: string, +}; + +type State = { + title: string, + is_public: boolean, +}; + +export class RouteRowEditor extends React.PureComponent { + constructor(props) { + super(props); + + this.state = { + title: props.title, + is_public: props.is_public, + }; + } + + stopEditing = () => console.log(); + setPublic = () => this.setState({ is_public: !this.state.is_public }); + setTitle = ({ target: { value } }: { target: { value: string } }) => this.setState({ title: value }); + + render() { + const { + state: { title, is_public }, + props: { distance, _id } + } = this; + + return ( +
+
+ +
+
+ + + {_id} + + + + {(distance && `${distance} km`) || '0 km'} + +
+
+
+
+ + { + is_public + ? ' В каталоге карт' + : ' Только по ссылке' + } +
+
+ OK +
+
+
+
+ ); + } +} diff --git a/src/components/panels/UserPanel.jsx b/src/components/panels/UserPanel.jsx index 06e6e1c..6905ce6 100644 --- a/src/components/panels/UserPanel.jsx +++ b/src/components/panels/UserPanel.jsx @@ -92,8 +92,6 @@ export class Component extends React.PureComponent { state: { menuOpened }, } = this; - const route_count = Object.keys(user.routes).length; - return (
@@ -114,7 +112,6 @@ export class Component extends React.PureComponent {