diff --git a/backend/models/Route.js b/backend/models/Route.js index d773c55..8bef460 100644 --- a/backend/models/Route.js +++ b/backend/models/Route.js @@ -12,7 +12,7 @@ const RouteSchema = new Schema( stickers: { type: Array, default: [] }, owner: { type: Schema.Types.ObjectId, ref: 'User' }, distance: { type: Number, default: 0 }, - public: { type: Boolean, default: true }, + is_public: { type: Boolean, default: false }, created_at: { type: Date, default: Date.now() }, updated_at: { type: Date, default: Date.now() }, logo: { type: String, default: 'DEFAULT' }, diff --git a/backend/routes/route/list.js b/backend/routes/route/list.js index 25cf6e0..423ad95 100644 --- a/backend/routes/route/list.js +++ b/backend/routes/route/list.js @@ -24,7 +24,7 @@ module.exports = async (req, res) => { if (!author || !user || (user._id !== author)) { criteria = { ...criteria, - public: true, + is_public: true, }; } diff --git a/backend/tools/import.js b/backend/tools/import.js index 3eae5a7..78dabb3 100755 --- a/backend/tools/import.js +++ b/backend/tools/import.js @@ -141,6 +141,7 @@ const run = async () => { title: '', version: 1, distance: calcPolyDistance(route), + is_public: false, }; })); })); diff --git a/src/components/dialogs/SaveDialog.jsx b/src/components/dialogs/SaveDialog.jsx index 1fc6c10..121b9b5 100644 --- a/src/components/dialogs/SaveDialog.jsx +++ b/src/components/dialogs/SaveDialog.jsx @@ -11,6 +11,7 @@ import classnames from 'classnames'; type Props = { address: String, // initial? title: String, // initial? + is_public: Boolean, save_error: String, save_finished: Boolean, @@ -25,7 +26,7 @@ type Props = { type State = { address: String, title: String, - public: Boolean, + is_public: Boolean, }; export class SaveDialog extends React.Component { @@ -35,7 +36,7 @@ export class SaveDialog extends React.Component { this.state = { address: props.address || '', title: props.title || '', - is_public: props.public || false, + is_public: props.is_public || false, }; } @@ -54,11 +55,11 @@ export class SaveDialog extends React.Component { cancelSaving = () => this.props.setMode(MODES.NONE); sendSaveRequest = (e, force = false) => { - const { title } = this.state; + const { title, is_public } = this.state; const address = this.getAddress(); this.props.sendSaveRequest({ - title, address, force, + title, address, force, is_public }); }; diff --git a/src/modules/Editor.js b/src/modules/Editor.js index 7cb65ba..caa961f 100644 --- a/src/modules/Editor.js +++ b/src/modules/Editor.js @@ -15,7 +15,7 @@ import { setDistance, setLogo, setMode, - setProvider, + setProvider, setPublic, setRouterPoints, setTitle, } from '$redux/user/actions'; @@ -86,15 +86,6 @@ export class Editor { [MODES.ROUTER]: this.router.pushWaypointOnClick, }; - // this.clearChanged = clearChanged; - // this.setActiveSticker = setActiveSticker; - // this.setMode = setMode; - // this.setEditing = setEditing; - // this.setTitle = setTitle; - // this.setAddress = setAddress; - // this.getUser = getUser; - // this.getTitle = getTitle; - map.addEventListener('mouseup', this.onClick); map.addEventListener('dragstart', () => lockMapClicks(true)); map.addEventListener('dragstop', () => lockMapClicks(false)); @@ -114,6 +105,7 @@ export class Editor { setActiveSticker = value => store.dispatch(setActiveSticker(value)); setTitle = value => store.dispatch(setTitle(value)); setAddress = value => store.dispatch(setAddress(value)); + setPublic = value => store.dispatch(setPublic(value)); resetSaveDialog = () => store.dispatch(resetSaveDialog()); @@ -228,7 +220,7 @@ export class Editor { }; setData = ({ - route = [], stickers = [], owner, title, address, provider = DEFAULT_PROVIDER, logo = DEFAULT_LOGO, + route = [], stickers = [], owner, title, address, provider = DEFAULT_PROVIDER, logo = DEFAULT_LOGO, public: is_public, }) => { this.setTitle(title || ''); const { id } = this.getUser(); @@ -253,6 +245,7 @@ export class Editor { ); } + this.setPublic(is_public); this.setLogo((logo && LOGOS[DEFAULT_LOGO] && logo) || DEFAULT_LOGO); this.setProvider((provider && PROVIDERS[provider] && provider) || DEFAULT_PROVIDER); if (owner) this.owner = owner; diff --git a/src/redux/user/actions.js b/src/redux/user/actions.js index 333bd6d..53cc083 100644 --- a/src/redux/user/actions.js +++ b/src/redux/user/actions.js @@ -13,6 +13,7 @@ export const setActiveSticker = activeSticker => ({ type: ACTIONS.SET_ACTIVE_STI export const setLogo = logo => ({ type: ACTIONS.SET_LOGO, logo }); export const setTitle = title => ({ type: ACTIONS.SET_TITLE, title }); export const setAddress = address => ({ type: ACTIONS.SET_ADDRESS, address }); +export const setPublic = is_public => ({ type: ACTIONS.SET_PUBLIC, is_public }); export const startEditing = () => ({ type: ACTIONS.START_EDITING }); export const stopEditing = () => ({ type: ACTIONS.STOP_EDITING }); diff --git a/src/redux/user/constants.js b/src/redux/user/constants.js index 31bfbe2..8d7dbe0 100644 --- a/src/redux/user/constants.js +++ b/src/redux/user/constants.js @@ -13,6 +13,7 @@ export const ACTIONS = ({ SET_LOGO: 'SET_LOGO', SET_TITLE: 'SET_TITLE', SET_ADDRESS: 'SET_ADDRESS', + SET_PUBLIC: 'SET_PUBLIC', START_EDITING: 'START_EDITING', STOP_EDITING: 'STOP_EDITING', diff --git a/src/redux/user/reducer.js b/src/redux/user/reducer.js index 4a7a0e8..32dd92f 100644 --- a/src/redux/user/reducer.js +++ b/src/redux/user/reducer.js @@ -152,6 +152,11 @@ const searchSetLoading = (state, { loading = false }) => ({ } }); +const setPublic = (state, { is_public = false }) => ({ + ...state, + is_public, +}); + const HANDLERS = ({ [ACTIONS.SET_USER]: setUser, [ACTIONS.SET_EDITING]: setEditing, @@ -185,6 +190,7 @@ const HANDLERS = ({ [ACTIONS.SEARCH_SET_TAB]: searchSetTab, [ACTIONS.SEARCH_PUT_ROUTES]: searchPutRoutes, [ACTIONS.SEARCH_SET_LOADING]: searchSetLoading, + [ACTIONS.SET_PUBLIC]: setPublic, }: { [key: String]: Function }); export const INITIAL_STATE = { @@ -201,6 +207,7 @@ export const INITIAL_STATE = { address: '', changed: false, provider: DEFAULT_PROVIDER, + is_public: false, save_error: '', save_finished: false, diff --git a/src/redux/user/sagas.js b/src/redux/user/sagas.js index ca54fe7..974b0a1 100644 --- a/src/redux/user/sagas.js +++ b/src/redux/user/sagas.js @@ -257,7 +257,7 @@ function* clearSaga({ type }) { yield put(setMode(MODES.NONE)); } -function* sendSaveRequestSaga({ title, address, force }) { +function* sendSaveRequestSaga({ title, address, force, is_public }) { if (editor.isEmpty) return yield put(setSaveError(TIPS.SAVE_EMPTY)); const { route, stickers, provider } = editor.dumpData(); @@ -266,7 +266,7 @@ function* sendSaveRequestSaga({ title, address, force }) { const { result, timeout, cancel } = yield race({ result: postMap({ - id, token, route, stickers, title, force, address, logo, distance, provider, + id, token, route, stickers, title, force, address, logo, distance, provider, is_public }), timeout: delay(10000), cancel: take(ACTIONS.RESET_SAVE_DIALOG), @@ -280,12 +280,12 @@ 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* refreshUserData() { +// const user = yield select(getUser); +// const data = yield call(checkUserToken, user); +// +// return yield put(setUser(data)); +// } function* getRenderData() { yield put(setRenderer({ info: 'Загрузка тайлов', progress: 0.1 })); diff --git a/src/utils/api.js b/src/utils/api.js index ec90c9d..93b58c6 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -39,10 +39,10 @@ export const checkIframeToken = ({ viewer_id, auth_key }) => axios.get(API.IFRAM }).then(result => (result && result.data && result.data.success && result.data.user)).catch(() => (false)); export const getRouteList = ({ - title, distance, author, starred + title, distance, author, starred, id, token, }) => axios.get(API.GET_ROUTE_LIST, { params: { - title, distance, author, starred + title, distance, author, starred, id, token, } }).then(result => (result && result.data && result.data.success && result.data)) .catch(() => ({ list: [], min: 0, max: 0 }));