114 lines
No EOL
3.7 KiB
JavaScript
114 lines
No EOL
3.7 KiB
JavaScript
import SyncController from "../../Controllers/SyncController";
|
|
// Database
|
|
import { Setting, Directory, SendBrochure } from '../../../Database';
|
|
|
|
const initialState = {
|
|
isSetup: false,
|
|
locale: 'fr',
|
|
currentUser: {},
|
|
logged: false,
|
|
directories: {},
|
|
syncVersion: 0,
|
|
currentOpenedDoc: {},
|
|
ShowIsActive: 0,
|
|
};
|
|
|
|
const reducer = (state = initialState, action) => {
|
|
let saved;
|
|
switch (action.type) {
|
|
case 'INIT_APP':
|
|
saved = Setting.get('isSetup');
|
|
return {
|
|
...state,
|
|
isSetup: saved === undefined ? false : saved.value === "true" ? true : false
|
|
};
|
|
case 'SET_ISSETUP':
|
|
Setting.upsert({ key: 'isSetup', value: "true" });
|
|
saved = Setting.get('isSetup');
|
|
return {
|
|
...state,
|
|
isSetup: saved === undefined ? false : saved.value === "true" ? true : false
|
|
};
|
|
case 'INIT':
|
|
let directories = Directory.getAll(
|
|
state.currentUser.role,
|
|
state.currentUser.authorizedFolders,
|
|
true,
|
|
state.locale
|
|
);
|
|
let ShowIsActive = Setting.get('ShowIsActive');
|
|
return {
|
|
...state,
|
|
directories: directories,
|
|
ShowIsActive: ShowIsActive === undefined ? false : ShowIsActive.value,
|
|
};
|
|
case 'SET_CURRENT_USER':
|
|
let user = Setting.get('isLogged').value
|
|
return {
|
|
...state,
|
|
currentUser: JSON.parse(user),
|
|
};
|
|
case 'SET_LOGGED':
|
|
if (action.data === false) {
|
|
Setting.delete('isLogged');
|
|
}
|
|
return {
|
|
...state,
|
|
logged: action.data,
|
|
};
|
|
// case 'UPDATE_LOCALE':
|
|
// let nxt;
|
|
// if (action.data === undefined) {
|
|
// const availableLocales = ['fr', 'en', 'de'];
|
|
// if (availableLocales.indexOf(i18n.locale) === availableLocales.length - 1) {
|
|
// nxt = availableLocales[0];
|
|
// } else {
|
|
// nxt = availableLocales[availableLocales.indexOf(i18n.locale) + 1];
|
|
// }
|
|
// } else {
|
|
// nxt = action.data;
|
|
// }
|
|
// i18n.locale = nxt;
|
|
// Setting.upsert({ key: 'locale', value: nxt });
|
|
// let docsL = Document.getAll(Directory.getAll(
|
|
// state.currentUser.role,
|
|
// state.currentUser.authorizedFolders,
|
|
// false,
|
|
// nxt
|
|
// ));
|
|
// return {
|
|
// ...state,
|
|
// locale: nxt,
|
|
// directories: Directory.getAll(
|
|
// state.currentUser.role,
|
|
// state.currentUser.authorizedFolders,
|
|
// true,
|
|
// nxt
|
|
// ),
|
|
// documents: docsL.filter(item => item.lang === nxt),
|
|
// };
|
|
case 'SET_CURRENT_OPENED_DOC':
|
|
return {
|
|
...state,
|
|
currentOpenedDoc: action.data
|
|
};
|
|
case 'UPDATE_VERSION':
|
|
return {
|
|
...state,
|
|
syncVersion: action.data,
|
|
};
|
|
case 'UPDATE_SHOW_IS_ACTIVE':
|
|
SyncController.updateShowIsActive(action.data);
|
|
return {
|
|
...state,
|
|
ShowIsActive: action.data,
|
|
};
|
|
case 'SEND_BROCHURE':
|
|
SendBrochure.add(action.data);
|
|
return state;
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default reducer; |