Showing "Autosave enabled" toast (#173)
* showing Autosave enabled toast * fixed variable names * fixed constant name typo
This commit is contained in:
parent
8ce36cd997
commit
83b077450a
5 changed files with 43 additions and 8 deletions
|
@ -98,3 +98,6 @@ export const RESET_PASSWORD_RESET = 'RESET_PASSWORD_RESET';
|
||||||
export const INVALID_RESET_PASSWORD_TOKEN = 'INVALID_RESET_PASSWORD_TOKEN';
|
export const INVALID_RESET_PASSWORD_TOKEN = 'INVALID_RESET_PASSWORD_TOKEN';
|
||||||
// eventually, handle errors more specifically and better
|
// eventually, handle errors more specifically and better
|
||||||
export const ERROR = 'ERROR';
|
export const ERROR = 'ERROR';
|
||||||
|
|
||||||
|
export const JUST_OPENED_PROJECT = 'JUST_OPENED_PROJECT';
|
||||||
|
export const RESET_JUST_OPENED_PROJECT = 'RESET_JUST_OPENED_PROJECT';
|
||||||
|
|
|
@ -195,3 +195,15 @@ export function resetInfiniteLoops() {
|
||||||
type: ActionTypes.RESET_INFINITE_LOOPS
|
type: ActionTypes.RESET_INFINITE_LOOPS
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function justOpenedProject() {
|
||||||
|
return {
|
||||||
|
type: ActionTypes.JUST_OPENED_PROJECT,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resetJustOpenedProject() {
|
||||||
|
return {
|
||||||
|
type: ActionTypes.RESET_JUST_OPENED_PROJECT
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -5,12 +5,13 @@ import JSZip from 'jszip';
|
||||||
import JSZipUtils from 'jszip-utils';
|
import JSZipUtils from 'jszip-utils';
|
||||||
import { saveAs } from 'file-saver';
|
import { saveAs } from 'file-saver';
|
||||||
import { showToast, setToastText } from './toast';
|
import { showToast, setToastText } from './toast';
|
||||||
import { setUnsavedChanges } from './ide';
|
import { setUnsavedChanges, justOpenedProject, resetJustOpenedProject } from './ide';
|
||||||
|
|
||||||
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
|
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
|
||||||
|
|
||||||
export function getProject(id) {
|
export function getProject(id) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
|
dispatch(justOpenedProject());
|
||||||
axios.get(`${ROOT_URL}/projects/${id}`, { withCredentials: true })
|
axios.get(`${ROOT_URL}/projects/${id}`, { withCredentials: true })
|
||||||
.then(response => {
|
.then(response => {
|
||||||
// browserHistory.push(`/projects/${id}`);
|
// browserHistory.push(`/projects/${id}`);
|
||||||
|
@ -52,8 +53,15 @@ export function saveProject(autosave = false) {
|
||||||
type: ActionTypes.PROJECT_SAVE_SUCCESS
|
type: ActionTypes.PROJECT_SAVE_SUCCESS
|
||||||
});
|
});
|
||||||
if (!autosave) {
|
if (!autosave) {
|
||||||
dispatch(showToast());
|
if (state.ide.justOpenedProject && state.preferences.autosave) {
|
||||||
dispatch(setToastText('Project saved.'));
|
dispatch(showToast(5500));
|
||||||
|
dispatch(setToastText('Project saved.'));
|
||||||
|
setTimeout(() => dispatch(setToastText('Autosave enabled.')), 1500);
|
||||||
|
dispatch(resetJustOpenedProject());
|
||||||
|
} else {
|
||||||
|
dispatch(showToast(1500));
|
||||||
|
dispatch(setToastText('Project saved.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((response) => dispatch({
|
.catch((response) => dispatch({
|
||||||
|
@ -73,8 +81,15 @@ export function saveProject(autosave = false) {
|
||||||
files: response.data.files
|
files: response.data.files
|
||||||
});
|
});
|
||||||
if (!autosave) {
|
if (!autosave) {
|
||||||
dispatch(showToast());
|
if (state.preferences.autosave) {
|
||||||
dispatch(setToastText('Project saved.'));
|
dispatch(showToast(5500));
|
||||||
|
dispatch(setToastText('Project saved.'));
|
||||||
|
setTimeout(() => dispatch(setToastText('Autosave enabled.')), 1500);
|
||||||
|
dispatch(resetJustOpenedProject());
|
||||||
|
} else {
|
||||||
|
dispatch(showToast(1500));
|
||||||
|
dispatch(setToastText('Project saved.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(response => dispatch({
|
.catch(response => dispatch({
|
||||||
|
|
|
@ -6,12 +6,12 @@ export function hideToast() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showToast() {
|
export function showToast(time) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ActionTypes.SHOW_TOAST
|
type: ActionTypes.SHOW_TOAST
|
||||||
});
|
});
|
||||||
setTimeout(() => dispatch(hideToast()), 1500);
|
setTimeout(() => dispatch(hideToast()), time);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,8 @@ const initialState = {
|
||||||
unsavedChanges: false,
|
unsavedChanges: false,
|
||||||
infiniteLoop: false,
|
infiniteLoop: false,
|
||||||
previewIsRefreshing: false,
|
previewIsRefreshing: false,
|
||||||
infiniteLoopMessage: ''
|
infiniteLoopMessage: '',
|
||||||
|
projectJustOpened: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const ide = (state = initialState, action) => {
|
const ide = (state = initialState, action) => {
|
||||||
|
@ -79,6 +80,10 @@ const ide = (state = initialState, action) => {
|
||||||
return Object.assign({}, state, { previewIsRefreshing: true });
|
return Object.assign({}, state, { previewIsRefreshing: true });
|
||||||
case ActionTypes.END_SKETCH_REFRESH:
|
case ActionTypes.END_SKETCH_REFRESH:
|
||||||
return Object.assign({}, state, { previewIsRefreshing: false });
|
return Object.assign({}, state, { previewIsRefreshing: false });
|
||||||
|
case ActionTypes.JUST_OPENED_PROJECT:
|
||||||
|
return Object.assign({}, state, { justOpenedProject: true });
|
||||||
|
case ActionTypes.RESET_JUST_OPENED_PROJECT:
|
||||||
|
return Object.assign({}, state, { justOpenedProject: false });
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue