From f5c3b76f4a8f7cd951875c2e49905411429ed547 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Wed, 18 Aug 2021 17:06:37 +0530 Subject: revert: reverting back from 'dayjs' to 'momentjs' --- src/stores/AppStore.js | 62 ++++++++++++++++++++++------------------------ src/stores/UserStore.js | 66 ++++++++++++++++++------------------------------- 2 files changed, 54 insertions(+), 74 deletions(-) (limited to 'src/stores') diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 71213774d..9c8cce679 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -8,7 +8,7 @@ import { process as remoteProcess, } from '@electron/remote'; import { action, computed, observable } from 'mobx'; -import dayjs from 'dayjs'; +import moment from 'moment'; import AutoLaunch from 'auto-launch'; import ms from 'ms'; import { URL } from 'url'; @@ -48,8 +48,7 @@ const autoLauncher = new AutoLaunch({ path: executablePath, }); -const CATALINA_NOTIFICATION_HACK_KEY = - '_temp_askedForCatalinaNotificationPermissions'; +const CATALINA_NOTIFICATION_HACK_KEY = '_temp_askedForCatalinaNotificationPermissions'; export default class AppStore extends Store { updateStatusTypes = { @@ -75,7 +74,7 @@ export default class AppStore extends Store { @observable authRequestFailed = false; - @observable timeSuspensionStart = dayjs(); + @observable timeSuspensionStart = moment(); @observable timeOfflineStart; @@ -229,7 +228,7 @@ export default class AppStore extends Store { powerMonitor.on('suspend', () => { debug('System suspended starting timer'); - this.timeSuspensionStart = dayjs(); + this.timeSuspensionStart = moment(); }); powerMonitor.on('resume', () => { @@ -237,8 +236,8 @@ export default class AppStore extends Store { this.actions.service.resetLastPollTimer(); if ( - this.timeSuspensionStart.add(10, 'm').isBefore(dayjs()) && - this.stores.settings.app.get('reloadAfterResume') + this.timeSuspensionStart.add(10, 'm').isBefore(moment()) + && this.stores.settings.app.get('reloadAfterResume') ) { debug('Reloading services, user info and features'); @@ -284,15 +283,15 @@ export default class AppStore extends Store { ferdi: { version: ferdiVersion, electron: electronVersion, - installedRecipes: this.stores.recipes.all.map(recipe => ({ + installedRecipes: this.stores.recipes.all.map((recipe) => ({ id: recipe.id, version: recipe.version, })), - devRecipes: this.stores.recipePreviews.dev.map(recipe => ({ + devRecipes: this.stores.recipePreviews.dev.map((recipe) => ({ id: recipe.id, version: recipe.version, })), - services: this.stores.services.all.map(service => ({ + services: this.stores.services.all.map((service) => ({ id: service.id, recipe: service.recipe.id, isAttached: service.isAttached, @@ -303,7 +302,7 @@ export default class AppStore extends Store { isDarkModeEnabled: service.isDarkModeEnabled, })), messages: this.stores.globalError.messages, - workspaces: this.stores.workspaces.workspaces.map(workspace => ({ + workspaces: this.stores.workspaces.workspaces.map((workspace) => ({ id: workspace.id, services: workspace.services, })), @@ -316,7 +315,9 @@ export default class AppStore extends Store { } // Actions - @action _notify({ title, options, notificationId, serviceId = null }) { + @action _notify({ + title, options, notificationId, serviceId = null, + }) { if (this.stores.settings.all.app.isAppMuted) return; // TODO: is there a simple way to use blobs for notifications without storing them on disk? @@ -358,8 +359,8 @@ export default class AppStore extends Store { if (indicator === 0 && unreadIndirectMessageCount !== 0) { indicator = '•'; } else if ( - unreadDirectMessageCount === 0 && - unreadIndirectMessageCount === 0 + unreadDirectMessageCount === 0 + && unreadIndirectMessageCount === 0 ) { indicator = 0; } else { @@ -440,25 +441,22 @@ export default class AppStore extends Store { const clearAppCache = this.clearAppCacheRequest.execute(); const allServiceIds = await getServiceIdsFromPartitions(); const allOrphanedServiceIds = allServiceIds.filter( - id => - !this.stores.services.all.find( - s => id.replace('service-', '') === s.id, - ), + (id) => !this.stores.services.all.find( + (s) => id.replace('service-', '') === s.id, + ), ); try { await Promise.all( - allOrphanedServiceIds.map(id => removeServicePartitionDirectory(id)), + allOrphanedServiceIds.map((id) => removeServicePartitionDirectory(id)), ); } catch (ex) { console.log('Error while deleting service partition directory - ', ex); } await Promise.all( - this.stores.services.all.map(s => - this.actions.service.clearCache({ - serviceId: s.id, - }), - ), + this.stores.services.all.map((s) => this.actions.service.clearCache({ + serviceId: s.id, + })), ); await clearAppCache._promise; @@ -473,9 +471,9 @@ export default class AppStore extends Store { // Reactions _offlineCheck() { if (!this.isOnline) { - this.timeOfflineStart = dayjs(); + this.timeOfflineStart = moment(); } else { - const deltaTime = dayjs().diff(this.timeOfflineStart); + const deltaTime = moment().diff(this.timeOfflineStart); if (deltaTime > ms('30m')) { this.actions.service.reloadAll(); @@ -490,16 +488,16 @@ export default class AppStore extends Store { } if ( - locale && - Object.prototype.hasOwnProperty.call(locales, locale) && - locale !== this.locale + locale + && Object.prototype.hasOwnProperty.call(locales, locale) + && locale !== this.locale ) { this.locale = locale; } else if (!locale) { this.locale = this._getDefaultLocale(); } - dayjs.locale(this.locale); + moment.locale(this.locale); debug(`Set locale to "${this.locale}"`); } @@ -571,8 +569,8 @@ export default class AppStore extends Store { debug('Do not disturb mode is', dnd); // ipcRenderer.on('autoUpdate', (event, data) => { if ( - dnd !== this.stores.settings.all.app.isAppMuted && - !this.isSystemMuteOverridden + dnd !== this.stores.settings.all.app.isAppMuted + && !this.isSystemMuteOverridden ) { this.actions.app.muteApp({ isMuted: dnd, diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js index 066638613..2e009893a 100644 --- a/src/stores/UserStore.js +++ b/src/stores/UserStore.js @@ -1,5 +1,5 @@ import { observable, computed, action } from 'mobx'; -import dayjs from 'dayjs'; +import moment from 'moment'; import jwt from 'jsonwebtoken'; import localStorage from 'mobx-localstorage'; import { session } from '@electron/remote'; @@ -46,10 +46,7 @@ export default class UserStore extends Store { @observable updateUserInfoRequest = new Request(this.api.user, 'updateInfo'); - @observable getLegacyServicesRequest = new CachedRequest( - this.api.user, - 'getLegacyServices', - ); + @observable getLegacyServicesRequest = new CachedRequest(this.api.user, 'getLegacyServices'); @observable deleteAccountRequest = new CachedRequest(this.api.user, 'delete'); @@ -84,17 +81,13 @@ export default class UserStore extends Store { // Register action handlers this.actions.user.login.listen(this._login.bind(this)); - this.actions.user.retrievePassword.listen( - this._retrievePassword.bind(this), - ); + this.actions.user.retrievePassword.listen(this._retrievePassword.bind(this)); this.actions.user.logout.listen(this._logout.bind(this)); this.actions.user.signup.listen(this._signup.bind(this)); this.actions.user.invite.listen(this._invite.bind(this)); this.actions.user.update.listen(this._update.bind(this)); this.actions.user.resetStatus.listen(this._resetStatus.bind(this)); - this.actions.user.importLegacyServices.listen( - this._importLegacyServices.bind(this), - ); + this.actions.user.importLegacyServices.listen(this._importLegacyServices.bind(this)); this.actions.user.delete.listen(this._delete.bind(this)); // Reactions @@ -151,7 +144,7 @@ export default class UserStore extends Store { if (!this.authToken) return false; const { tokenExpiry } = this._parseToken(this.authToken); - return this.authToken !== null && dayjs(tokenExpiry).isBefore(dayjs()); + return this.authToken !== null && moment(tokenExpiry).isBefore(moment()); } @computed get data() { @@ -183,14 +176,7 @@ export default class UserStore extends Store { } @action async _signup({ - firstname, - lastname, - email, - password, - accountType, - company, - plan, - currency, + firstname, lastname, email, password, accountType, company, plan, currency, }) { const authToken = await this.signupRequest.execute({ firstname, @@ -219,7 +205,7 @@ export default class UserStore extends Store { } @action async _invite({ invites }) { - const data = invites.filter(invite => invite.email !== ''); + const data = invites.filter((invite) => invite.email !== ''); const response = await this.inviteRequest.execute(data)._promise; @@ -234,8 +220,7 @@ export default class UserStore extends Store { @action async _update({ userData }) { if (!this.isLoggedIn) return; - const response = await this.updateUserInfoRequest.execute(userData) - ._promise; + const response = await this.updateUserInfoRequest.execute(userData)._promise; this.getUserInfoRequest.patch(() => response.data); this.actionStatus = response.status || []; @@ -265,20 +250,15 @@ export default class UserStore extends Store { this.isImportLegacyServicesExecuting = true; // Reduces recipe duplicates - const recipes = services - .filter( - (obj, pos, arr) => - arr.map(mapObj => mapObj.recipe.id).indexOf(obj.recipe.id) === pos, - ) - .map(s => s.recipe.id); + const recipes = services.filter((obj, pos, arr) => arr.map((mapObj) => mapObj.recipe.id).indexOf(obj.recipe.id) === pos).map((s) => s.recipe.id); // Install recipes - for (const recipe of recipes) { + for (const recipe of recipes) { // eslint-disable-line no-unused-vars // eslint-disable-next-line await this.stores.recipes._install({ recipeId: recipe }); } - for (const service of services) { + for (const service of services) { // eslint-disable-line no-unused-vars this.actions.service.createFromLegacyService({ data: service, }); @@ -301,7 +281,8 @@ export default class UserStore extends Store { const { router } = this.stores; const currentRoute = window.location.hash; - if (!this.isLoggedIn && currentRoute.includes('token=')) { + if (!this.isLoggedIn + && currentRoute.includes('token=')) { router.push(this.WELCOME_ROUTE); const token = currentRoute.split('=')[1]; @@ -312,16 +293,17 @@ export default class UserStore extends Store { this._tokenLogin(token); }, 1000); } - } else if (!this.isLoggedIn && !currentRoute.includes(this.BASE_ROUTE)) { + } else if (!this.isLoggedIn + && !currentRoute.includes(this.BASE_ROUTE)) { router.push(this.WELCOME_ROUTE); - } else if (this.isLoggedIn && currentRoute === this.LOGOUT_ROUTE) { + } else if (this.isLoggedIn + && currentRoute === this.LOGOUT_ROUTE) { this.actions.user.logout(); router.push(this.LOGIN_ROUTE); - } else if ( - this.isLoggedIn && - currentRoute.includes(this.BASE_ROUTE) && - (this.hasCompletedSignup || this.hasCompletedSignup === null) - ) { + } else if (this.isLoggedIn + && currentRoute.includes(this.BASE_ROUTE) + && (this.hasCompletedSignup + || this.hasCompletedSignup === null)) { if (!isDevMode) { this.stores.router.push('/'); } @@ -354,11 +336,11 @@ export default class UserStore extends Store { try { const decoded = jwt.decode(authToken); - return { + return ({ id: decoded.userId, - tokenExpiry: dayjs.unix(decoded.exp).toISOString(), + tokenExpiry: moment.unix(decoded.exp).toISOString(), authToken, - }; + }); } catch (err) { this._logout(); return false; -- cgit v1.2.3-70-g09d2