save: public switch

This commit is contained in:
muerwre 2018-12-18 14:45:45 +07:00
parent 69f23c9e48
commit b7f2c7c382
10 changed files with 31 additions and 27 deletions

View file

@ -12,7 +12,7 @@ const RouteSchema = new Schema(
stickers: { type: Array, default: [] }, stickers: { type: Array, default: [] },
owner: { type: Schema.Types.ObjectId, ref: 'User' }, owner: { type: Schema.Types.ObjectId, ref: 'User' },
distance: { type: Number, default: 0 }, distance: { type: Number, default: 0 },
public: { type: Boolean, default: true }, is_public: { type: Boolean, default: false },
created_at: { type: Date, default: Date.now() }, created_at: { type: Date, default: Date.now() },
updated_at: { type: Date, default: Date.now() }, updated_at: { type: Date, default: Date.now() },
logo: { type: String, default: 'DEFAULT' }, logo: { type: String, default: 'DEFAULT' },

View file

@ -24,7 +24,7 @@ module.exports = async (req, res) => {
if (!author || !user || (user._id !== author)) { if (!author || !user || (user._id !== author)) {
criteria = { criteria = {
...criteria, ...criteria,
public: true, is_public: true,
}; };
} }

View file

@ -141,6 +141,7 @@ const run = async () => {
title: '', title: '',
version: 1, version: 1,
distance: calcPolyDistance(route), distance: calcPolyDistance(route),
is_public: false,
}; };
})); }));
})); }));

View file

@ -11,6 +11,7 @@ import classnames from 'classnames';
type Props = { type Props = {
address: String, // initial? address: String, // initial?
title: String, // initial? title: String, // initial?
is_public: Boolean,
save_error: String, save_error: String,
save_finished: Boolean, save_finished: Boolean,
@ -25,7 +26,7 @@ type Props = {
type State = { type State = {
address: String, address: String,
title: String, title: String,
public: Boolean, is_public: Boolean,
}; };
export class SaveDialog extends React.Component<Props, State> { export class SaveDialog extends React.Component<Props, State> {
@ -35,7 +36,7 @@ export class SaveDialog extends React.Component<Props, State> {
this.state = { this.state = {
address: props.address || '', address: props.address || '',
title: props.title || '', title: props.title || '',
is_public: props.public || false, is_public: props.is_public || false,
}; };
} }
@ -54,11 +55,11 @@ export class SaveDialog extends React.Component<Props, State> {
cancelSaving = () => this.props.setMode(MODES.NONE); cancelSaving = () => this.props.setMode(MODES.NONE);
sendSaveRequest = (e, force = false) => { sendSaveRequest = (e, force = false) => {
const { title } = this.state; const { title, is_public } = this.state;
const address = this.getAddress(); const address = this.getAddress();
this.props.sendSaveRequest({ this.props.sendSaveRequest({
title, address, force, title, address, force, is_public
}); });
}; };

View file

@ -15,7 +15,7 @@ import {
setDistance, setDistance,
setLogo, setLogo,
setMode, setMode,
setProvider, setProvider, setPublic,
setRouterPoints, setRouterPoints,
setTitle, setTitle,
} from '$redux/user/actions'; } from '$redux/user/actions';
@ -86,15 +86,6 @@ export class Editor {
[MODES.ROUTER]: this.router.pushWaypointOnClick, [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('mouseup', this.onClick);
map.addEventListener('dragstart', () => lockMapClicks(true)); map.addEventListener('dragstart', () => lockMapClicks(true));
map.addEventListener('dragstop', () => lockMapClicks(false)); map.addEventListener('dragstop', () => lockMapClicks(false));
@ -114,6 +105,7 @@ export class Editor {
setActiveSticker = value => store.dispatch(setActiveSticker(value)); setActiveSticker = value => store.dispatch(setActiveSticker(value));
setTitle = value => store.dispatch(setTitle(value)); setTitle = value => store.dispatch(setTitle(value));
setAddress = value => store.dispatch(setAddress(value)); setAddress = value => store.dispatch(setAddress(value));
setPublic = value => store.dispatch(setPublic(value));
resetSaveDialog = () => store.dispatch(resetSaveDialog()); resetSaveDialog = () => store.dispatch(resetSaveDialog());
@ -228,7 +220,7 @@ export class Editor {
}; };
setData = ({ 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 || ''); this.setTitle(title || '');
const { id } = this.getUser(); 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.setLogo((logo && LOGOS[DEFAULT_LOGO] && logo) || DEFAULT_LOGO);
this.setProvider((provider && PROVIDERS[provider] && provider) || DEFAULT_PROVIDER); this.setProvider((provider && PROVIDERS[provider] && provider) || DEFAULT_PROVIDER);
if (owner) this.owner = owner; if (owner) this.owner = owner;

View file

@ -13,6 +13,7 @@ export const setActiveSticker = activeSticker => ({ type: ACTIONS.SET_ACTIVE_STI
export const setLogo = logo => ({ type: ACTIONS.SET_LOGO, logo }); export const setLogo = logo => ({ type: ACTIONS.SET_LOGO, logo });
export const setTitle = title => ({ type: ACTIONS.SET_TITLE, title }); export const setTitle = title => ({ type: ACTIONS.SET_TITLE, title });
export const setAddress = address => ({ type: ACTIONS.SET_ADDRESS, address }); 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 startEditing = () => ({ type: ACTIONS.START_EDITING });
export const stopEditing = () => ({ type: ACTIONS.STOP_EDITING }); export const stopEditing = () => ({ type: ACTIONS.STOP_EDITING });

View file

@ -13,6 +13,7 @@ export const ACTIONS = ({
SET_LOGO: 'SET_LOGO', SET_LOGO: 'SET_LOGO',
SET_TITLE: 'SET_TITLE', SET_TITLE: 'SET_TITLE',
SET_ADDRESS: 'SET_ADDRESS', SET_ADDRESS: 'SET_ADDRESS',
SET_PUBLIC: 'SET_PUBLIC',
START_EDITING: 'START_EDITING', START_EDITING: 'START_EDITING',
STOP_EDITING: 'STOP_EDITING', STOP_EDITING: 'STOP_EDITING',

View file

@ -152,6 +152,11 @@ const searchSetLoading = (state, { loading = false }) => ({
} }
}); });
const setPublic = (state, { is_public = false }) => ({
...state,
is_public,
});
const HANDLERS = ({ const HANDLERS = ({
[ACTIONS.SET_USER]: setUser, [ACTIONS.SET_USER]: setUser,
[ACTIONS.SET_EDITING]: setEditing, [ACTIONS.SET_EDITING]: setEditing,
@ -185,6 +190,7 @@ const HANDLERS = ({
[ACTIONS.SEARCH_SET_TAB]: searchSetTab, [ACTIONS.SEARCH_SET_TAB]: searchSetTab,
[ACTIONS.SEARCH_PUT_ROUTES]: searchPutRoutes, [ACTIONS.SEARCH_PUT_ROUTES]: searchPutRoutes,
[ACTIONS.SEARCH_SET_LOADING]: searchSetLoading, [ACTIONS.SEARCH_SET_LOADING]: searchSetLoading,
[ACTIONS.SET_PUBLIC]: setPublic,
}: { [key: String]: Function }); }: { [key: String]: Function });
export const INITIAL_STATE = { export const INITIAL_STATE = {
@ -201,6 +207,7 @@ export const INITIAL_STATE = {
address: '', address: '',
changed: false, changed: false,
provider: DEFAULT_PROVIDER, provider: DEFAULT_PROVIDER,
is_public: false,
save_error: '', save_error: '',
save_finished: false, save_finished: false,

View file

@ -257,7 +257,7 @@ function* clearSaga({ type }) {
yield put(setMode(MODES.NONE)); 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)); if (editor.isEmpty) return yield put(setSaveError(TIPS.SAVE_EMPTY));
const { route, stickers, provider } = editor.dumpData(); const { route, stickers, provider } = editor.dumpData();
@ -266,7 +266,7 @@ function* sendSaveRequestSaga({ title, address, force }) {
const { result, timeout, cancel } = yield race({ const { result, timeout, cancel } = yield race({
result: postMap({ 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), timeout: delay(10000),
cancel: take(ACTIONS.RESET_SAVE_DIALOG), 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 })); return yield put(setSaveSuccess({ address: result.address, save_error: TIPS.SAVE_SUCCESS, title }));
} }
function* refreshUserData() { // function* refreshUserData() {
const user = yield select(getUser); // const user = yield select(getUser);
const data = yield call(checkUserToken, user); // const data = yield call(checkUserToken, user);
//
return yield put(setUser(data)); // return yield put(setUser(data));
} // }
function* getRenderData() { function* getRenderData() {
yield put(setRenderer({ info: 'Загрузка тайлов', progress: 0.1 })); yield put(setRenderer({ info: 'Загрузка тайлов', progress: 0.1 }));

View file

@ -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)); }).then(result => (result && result.data && result.data.success && result.data.user)).catch(() => (false));
export const getRouteList = ({ export const getRouteList = ({
title, distance, author, starred title, distance, author, starred, id, token,
}) => axios.get(API.GET_ROUTE_LIST, { }) => axios.get(API.GET_ROUTE_LIST, {
params: { params: {
title, distance, author, starred title, distance, author, starred, id, token,
} }
}).then(result => (result && result.data && result.data.success && result.data)) }).then(result => (result && result.data && result.data.success && result.data))
.catch(() => ({ list: [], min: 0, max: 0 })); .catch(() => ({ list: [], min: 0, max: 0 }));