mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 02:56:41 +07:00
save: public switch
This commit is contained in:
parent
69f23c9e48
commit
b7f2c7c382
10 changed files with 31 additions and 27 deletions
|
@ -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' },
|
||||
|
|
|
@ -24,7 +24,7 @@ module.exports = async (req, res) => {
|
|||
if (!author || !user || (user._id !== author)) {
|
||||
criteria = {
|
||||
...criteria,
|
||||
public: true,
|
||||
is_public: true,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -141,6 +141,7 @@ const run = async () => {
|
|||
title: '',
|
||||
version: 1,
|
||||
distance: calcPolyDistance(route),
|
||||
is_public: false,
|
||||
};
|
||||
}));
|
||||
}));
|
||||
|
|
|
@ -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<Props, State> {
|
||||
|
@ -35,7 +36,7 @@ export class SaveDialog extends React.Component<Props, State> {
|
|||
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<Props, State> {
|
|||
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
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 }));
|
||||
|
|
|
@ -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 }));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue