lint common

This commit is contained in:
Matteo Pagliazzi
2019-10-09 20:08:36 +02:00
parent 0c27fb24a5
commit e0e9811ab6
330 changed files with 6885 additions and 7668 deletions
@@ -93,7 +93,7 @@ export default {
window.removeEventListener('message', this.receiveMessage);
},
computed: {
...mapState({user: 'user.data', credentials: 'credentials'}),
...mapState({ user: 'user.data', credentials: 'credentials' }),
apiToken () {
return this.credentials.API_TOKEN;
},
@@ -109,7 +109,7 @@ export default {
eventFrom.source.postMessage(creds, eventFrom.origin);
},
async addWebhook (url) {
let webhookInfo = {
const webhookInfo = {
id: uuid(),
type: 'taskActivity',
options: {
@@ -122,19 +122,19 @@ export default {
enabled: true,
};
let webhook = await this.$store.dispatch('user:addWebhook', {webhookInfo});
const webhook = await this.$store.dispatch('user:addWebhook', { webhookInfo });
this.user.webhooks.push(webhook);
this.newWebhook.url = '';
},
async saveWebhook (webhook, index) {
delete webhook._editing;
let updatedWebhook = await this.$store.dispatch('user:updateWebhook', {webhook});
const updatedWebhook = await this.$store.dispatch('user:updateWebhook', { webhook });
this.user.webhooks[index] = updatedWebhook;
},
async deleteWebhook (webhook, index) {
delete webhook._editing;
await this.$store.dispatch('user:deleteWebhook', {webhook});
await this.$store.dispatch('user:deleteWebhook', { webhook });
this.user.webhooks.splice(index, 1);
},
},
@@ -28,7 +28,7 @@ export default {
};
},
computed: {
...mapState({user: 'user.data'}),
...mapState({ user: 'user.data' }),
},
methods: {
close () {
@@ -73,7 +73,7 @@ export default {
};
},
computed: {
...mapState({user: 'user.data'}),
...mapState({ user: 'user.data' }),
},
async mounted () {
// If ?unsubFrom param is passed with valid email type,
@@ -86,7 +86,7 @@ export default {
importantAnnouncements: 'inactivityEmails',
};
const unsubFrom = this.$route.query.unsubFrom;
const { unsubFrom } = this.$route.query;
if (unsubFrom) {
await this.$store.dispatch('user:set', {
@@ -94,12 +94,12 @@ export default {
});
const emailTypeString = this.$t(MAP_PREF_TO_EMAIL_STRING[unsubFrom] || unsubFrom);
this.text(this.$t('correctlyUnsubscribedEmailType', {emailType: emailTypeString}));
this.text(this.$t('correctlyUnsubscribedEmailType', { emailType: emailTypeString }));
}
},
methods: {
set (preferenceType, notification) {
let settings = {};
const settings = {};
settings[`preferences.${preferenceType}.${notification}`] = this.user.preferences[preferenceType][notification];
this.$store.dispatch('user:set', settings);
},
@@ -37,7 +37,7 @@ export default {
};
},
computed: {
...mapState({user: 'user.data', credentials: 'credentials'}),
...mapState({ user: 'user.data', credentials: 'credentials' }),
getCodesUrl () {
if (!this.user) return '';
return '/api/v4/coupons';
@@ -53,7 +53,7 @@ export default {
// })
},
async enterCoupon () {
let code = await axios.post(`/api/v4/coupons/enter/${this.couponCode}`);
const code = await axios.post(`/api/v4/coupons/enter/${this.couponCode}`);
if (!code) return;
this.$store.state.user.data = code.data.data;
@@ -13,14 +13,14 @@ import { mapState } from '@/libs/store';
export default {
computed: {
...mapState({user: 'user.data'}),
...mapState({ user: 'user.data' }),
},
methods: {
close () {
this.$root.$emit('bv::hide::modal', 'reset');
},
async reset () {
let response = await axios.post('/api/v4/user/reset');
const response = await axios.post('/api/v4/user/reset');
// @TODO: Not sure if this is correct
this.$store.user = response.data.data.user;
this.$router.push('/');
@@ -72,7 +72,7 @@ export default {
this.restoreValues.achievements.streak = clone(this.user.achievements.streak);
},
computed: {
...mapState({user: 'user.data'}),
...mapState({ user: 'user.data' }),
},
methods: {
close () {
@@ -92,7 +92,7 @@ export default {
this.user.stats = clone(this.restoreValues.stats);
this.user.achievements.streak = clone(this.restoreValues.achievements.streak);
let settings = {
const settings = {
'stats.hp': Number(this.restoreValues.stats.hp),
'stats.exp': Number(this.restoreValues.stats.exp),
'stats.gp': Number(this.restoreValues.stats.gp),
+23 -22
View File
@@ -209,33 +209,33 @@
import hello from 'hellojs';
import moment from 'moment';
import axios from 'axios';
import { mapState } from '@/libs/store';
import debounce from 'lodash/debounce';
import { mapState } from '@/libs/store';
import restoreModal from './restoreModal';
import resetModal from './resetModal';
import deleteModal from './deleteModal';
import { SUPPORTED_SOCIAL_NETWORKS } from '@/../../common/script/constants';
import changeClass from '@/../../common/script/ops/changeClass';
import changeClass from '@/../../common/script/ops/changeClass';
import notificationsMixin from '../../mixins/notifications';
import sounds from '../../libs/sounds';
// @TODO: this needs our window.env fix
// import { availableLanguages } from '../../../server/libs/i18n';
export default {
mixins: [notificationsMixin],
components: {
restoreModal,
resetModal,
deleteModal,
},
mixins: [notificationsMixin],
data () {
let dayStartOptions = [];
const dayStartOptions = [];
for (let number = 0; number < 24; number += 1) {
let meridian = number < 12 ? 'AM' : 'PM';
let hour = number % 12;
let option = {
const meridian = number < 12 ? 'AM' : 'PM';
const hour = number % 12;
const option = {
value: number,
name: `${hour ? hour : 12}:00 ${meridian}`,
name: `${hour || 12}:00 ${meridian}`,
};
dayStartOptions.push(option);
}
@@ -248,7 +248,7 @@ export default {
dayStartOptions,
newDayStart: 0,
temporaryDisplayName: '',
usernameUpdates: {username: ''},
usernameUpdates: { username: '' },
emailUpdates: {},
passwordUpdates: {},
localAuth: {
@@ -299,14 +299,14 @@ export default {
},
timezoneOffsetToUtc () {
let offset = this.user.preferences.timezoneOffset;
let sign = offset > 0 ? '-' : '+';
const sign = offset > 0 ? '-' : '+';
offset = Math.abs(offset) / 60;
let hour = Math.floor(offset);
const hour = Math.floor(offset);
let minutesInt = (offset - hour) * 60;
let minutes = minutesInt < 10 ? `0${minutesInt}` : minutesInt;
const minutesInt = (offset - hour) * 60;
const minutes = minutesInt < 10 ? `0${minutesInt}` : minutesInt;
return `UTC${sign}${hour}:${minutes}`;
},
@@ -390,7 +390,7 @@ export default {
});
}, 500),
set (preferenceType, subtype) {
let settings = {};
const settings = {};
if (!subtype) {
settings[`preferences.${preferenceType}`] = this.user.preferences[preferenceType];
} else {
@@ -420,7 +420,7 @@ export default {
return true;
}
return find(this.SOCIAL_AUTH_NETWORKS, (network) => {
return find(this.SOCIAL_AUTH_NETWORKS, network => {
if (network.key !== networkKeyToCheck) {
if (this.user.auth.hasOwnProperty(network.key)) {
return this.user.auth[network.key].id;
@@ -429,9 +429,10 @@ export default {
});
},
calculateNextCron () {
let nextCron = moment().hours(this.newDayStart).minutes(0).seconds(0).milliseconds(0);
let nextCron = moment().hours(this.newDayStart).minutes(0).seconds(0)
.milliseconds(0);
let currentHour = moment().format('H');
const currentHour = moment().format('H');
if (currentHour >= this.newDayStart) {
nextCron = nextCron.add(1, 'day');
}
@@ -439,9 +440,9 @@ export default {
return nextCron.format(`${this.user.preferences.dateFormat.toUpperCase()} @ h:mm a`);
},
openDayStartModal () {
let nextCron = this.calculateNextCron();
const nextCron = this.calculateNextCron();
// @TODO: Add generic modal
if (!confirm(this.$t('sureChangeCustomDayStartTime', {time: nextCron}))) return;
if (!confirm(this.$t('sureChangeCustomDayStartTime', { time: nextCron }))) return;
this.saveDayStart();
// $rootScope.openModal('change-day-start', { scope: $scope });
},
@@ -470,7 +471,7 @@ export default {
}
},
async changeDisplayName (newName) {
await axios.put('/api/v4/user/', {'profile.name': newName});
await axios.put('/api/v4/user/', { 'profile.name': newName });
alert(this.$t('displayNameSuccess'));
this.user.profile.name = newName;
this.temporaryDisplayName = newName;
@@ -486,10 +487,10 @@ export default {
},
async deleteSocialAuth (network) {
await axios.delete(`/api/v4/user/auth/social/${network.key}`);
this.text(this.$t('detachedSocial', {network: network.name}));
this.text(this.$t('detachedSocial', { network: network.name }));
},
async socialAuth (network) {
let auth = await hello(network).login({scope: 'email'});
const auth = await hello(network).login({ scope: 'email' });
await this.$store.dispatch('auth:socialAuth', {
auth,
@@ -74,7 +74,7 @@
.subscribe-pay(v-if='!hasSubscription || hasCanceledSubscription')
h3 {{ $t('subscribeUsing') }}
.payments-column
button.purchase.btn.btn-primary.payment-button.payment-item(@click='showStripe({subscription:subscription.key, coupon:subscription.coupon})', :disabled='!subscription.key')
button.purchase.btn.btn-primary.payment-button.payment-item(@click='showStripe({subscription:subscription.key, coupon:subscription.coupon})', :disabled='!subscription.key')
.svg-icon.credit-card-icon(v-html="icons.creditCardIcon")
| {{ $t('card') }}
button.btn.payment-item.paypal-checkout.payment-button(@click="openPaypal(paypalPurchaseLink, 'subscription')", :disabled='!subscription.key')
@@ -118,10 +118,10 @@ import amazonButton from '@/components/payments/amazonButton';
import creditCardIcon from '@/assets/svg/credit-card-icon.svg';
export default {
mixins: [paymentsMixin, notificationsMixin],
components: {
amazonButton,
},
mixins: [paymentsMixin, notificationsMixin],
data () {
return {
loading: false,
@@ -148,15 +148,11 @@ export default {
};
},
computed: {
...mapState({user: 'user.data', credentials: 'credentials'}),
...mapState({ user: 'user.data', credentials: 'credentials' }),
subscriptionBlocksOrdered () {
let subscriptions = filter(subscriptionBlocks, (o) => {
return o.discount !== true;
});
const subscriptions = filter(subscriptionBlocks, o => o.discount !== true);
return sortBy(subscriptions, [(o) => {
return o.months;
}]);
return sortBy(subscriptions, [o => o.months]);
},
purchasedPlanIdInfo () {
if (!this.subscriptionBlocks[this.user.purchased.plan.planId]) {
@@ -180,8 +176,8 @@ export default {
},
canEditCardDetails () {
return Boolean(
!this.hasCanceledSubscription &&
this.user.purchased.plan.paymentMethod === this.paymentMethods.STRIPE
!this.hasCanceledSubscription
&& this.user.purchased.plan.paymentMethod === this.paymentMethods.STRIPE,
);
},
hasSubscription () {
@@ -189,8 +185,8 @@ export default {
},
hasCanceledSubscription () {
return (
this.hasSubscription &&
Boolean(this.user.purchased.plan.dateTerminated)
this.hasSubscription
&& Boolean(this.user.purchased.plan.dateTerminated)
);
},
hasPlan () {
@@ -213,20 +209,20 @@ export default {
};
},
gemGoldCap () {
let baseCap = 25;
let gemCapIncrement = 5;
let capIncrementThreshold = 3;
let gemCapExtra = this.user.purchased.plan.consecutive.gemCapExtra;
let blocks = subscriptionBlocks[this.subscription.key].months / capIncrementThreshold;
let flooredBlocks = Math.floor(blocks);
const baseCap = 25;
const gemCapIncrement = 5;
const capIncrementThreshold = 3;
const { gemCapExtra } = this.user.purchased.plan.consecutive;
const blocks = subscriptionBlocks[this.subscription.key].months / capIncrementThreshold;
const flooredBlocks = Math.floor(blocks);
let userTotalDropCap = baseCap + gemCapExtra + flooredBlocks * gemCapIncrement;
let maxDropCap = 50;
const userTotalDropCap = baseCap + gemCapExtra + flooredBlocks * gemCapIncrement;
const maxDropCap = 50;
return [userTotalDropCap, maxDropCap];
},
numberOfMysticHourglasses () {
let numberOfHourglasses = subscriptionBlocks[this.subscription.key].months / 3;
const numberOfHourglasses = subscriptionBlocks[this.subscription.key].months / 3;
return Math.floor(numberOfHourglasses);
},
mysticHourglass () {
@@ -236,10 +232,10 @@ export default {
},
canCancelSubscription () {
return (
this.user.purchased.plan.paymentMethod !== this.paymentMethods.GOOGLE &&
this.user.purchased.plan.paymentMethod !== this.paymentMethods.APPLE &&
!this.hasCanceledSubscription &&
!this.hasGroupPlan
this.user.purchased.plan.paymentMethod !== this.paymentMethods.GOOGLE
&& this.user.purchased.plan.paymentMethod !== this.paymentMethods.APPLE
&& !this.hasCanceledSubscription
&& !this.hasGroupPlan
);
},
},
@@ -95,127 +95,127 @@
</style>
<script>
import axios from 'axios';
import debounce from 'lodash/debounce';
import { mapState } from '@/libs/store';
import axios from 'axios';
import debounce from 'lodash/debounce';
import { mapState } from '@/libs/store';
export default {
computed: {
...mapState({
user: 'user.data',
}),
displayNameInvalid () {
if (this.temporaryDisplayName.length < 1) return false;
return !this.displayNameValid;
},
displayNameValid () {
if (this.temporaryDisplayName.length < 1) return false;
return this.displayNameIssues.length === 0;
},
usernameCannotSubmit () {
if (this.temporaryUsername.length < 1) return true;
return !this.usernameValid || !this.displayNameValid;
},
usernameInvalid () {
if (this.temporaryUsername.length < 1) return false;
return !this.usernameValid;
},
usernameValid () {
if (this.temporaryUsername.length < 1) return false;
return this.usernameIssues.length === 0;
},
export default {
computed: {
...mapState({
user: 'user.data',
}),
displayNameInvalid () {
if (this.temporaryDisplayName.length < 1) return false;
return !this.displayNameValid;
},
data () {
return {
displayNameIssues: [],
temporaryDisplayName: '',
temporaryUsername: '',
usernameIssues: [],
};
displayNameValid () {
if (this.temporaryDisplayName.length < 1) return false;
return this.displayNameIssues.length === 0;
},
methods: {
async close () {
this.$root.$emit('habitica::resync-requested');
await this.$store.dispatch('user:fetch', {forceLoad: true});
this.$root.$emit('habitica::resync-completed');
if (this.avatarIntro) {
this.$emit('usernameConfirmed');
usernameCannotSubmit () {
if (this.temporaryUsername.length < 1) return true;
return !this.usernameValid || !this.displayNameValid;
},
usernameInvalid () {
if (this.temporaryUsername.length < 1) return false;
return !this.usernameValid;
},
usernameValid () {
if (this.temporaryUsername.length < 1) return false;
return this.usernameIssues.length === 0;
},
},
data () {
return {
displayNameIssues: [],
temporaryDisplayName: '',
temporaryUsername: '',
usernameIssues: [],
};
},
methods: {
async close () {
this.$root.$emit('habitica::resync-requested');
await this.$store.dispatch('user:fetch', { forceLoad: true });
this.$root.$emit('habitica::resync-completed');
if (this.avatarIntro) {
this.$emit('usernameConfirmed');
} else {
this.$root.$emit('bv::hide::modal', 'verify-username');
this.$router.go(0);
}
},
restoreEmptyDisplayName () {
if (this.temporaryDisplayName.length < 1) {
this.temporaryDisplayName = this.user.profile.name;
}
},
restoreEmptyUsername () {
if (this.temporaryUsername.length < 1) {
this.temporaryUsername = this.user.auth.local.username;
}
},
async submitNames () {
if (this.temporaryDisplayName !== this.user.profile.name) {
await axios.put('/api/v4/user/', { 'profile.name': this.temporaryDisplayName });
}
await axios.put('/api/v4/user/auth/update-username', { username: this.temporaryUsername });
this.close();
},
validateDisplayName: debounce(function checkName (displayName) {
if (displayName.length <= 1 || displayName === this.user.profile.name) {
this.displayNameIssues = [];
return;
}
this.$store.dispatch('auth:verifyDisplayName', {
displayName,
}).then(res => {
if (res.issues !== undefined) {
this.displayNameIssues = res.issues;
} else {
this.$root.$emit('bv::hide::modal', 'verify-username');
this.$router.go(0);
}
},
restoreEmptyDisplayName () {
if (this.temporaryDisplayName.length < 1) {
this.temporaryDisplayName = this.user.profile.name;
}
},
restoreEmptyUsername () {
if (this.temporaryUsername.length < 1) {
this.temporaryUsername = this.user.auth.local.username;
}
},
async submitNames () {
if (this.temporaryDisplayName !== this.user.profile.name) {
await axios.put('/api/v4/user/', {'profile.name': this.temporaryDisplayName});
}
await axios.put('/api/v4/user/auth/update-username', {username: this.temporaryUsername});
this.close();
},
validateDisplayName: debounce(function checkName (displayName) {
if (displayName.length <= 1 || displayName === this.user.profile.name) {
this.displayNameIssues = [];
return;
}
this.$store.dispatch('auth:verifyDisplayName', {
displayName,
}).then(res => {
if (res.issues !== undefined) {
this.displayNameIssues = res.issues;
} else {
this.displayNameIssues = [];
}
});
}, 500),
validateUsername: debounce(function checkName (username) {
if (username.length <= 1 || username === this.user.auth.local.username) {
});
}, 500),
validateUsername: debounce(function checkName (username) {
if (username.length <= 1 || username === this.user.auth.local.username) {
this.usernameIssues = [];
return;
}
this.$store.dispatch('auth:verifyUsername', {
username,
}).then(res => {
if (res.issues !== undefined) {
this.usernameIssues = res.issues;
} else {
this.usernameIssues = [];
return;
}
this.$store.dispatch('auth:verifyUsername', {
username,
}).then(res => {
if (res.issues !== undefined) {
this.usernameIssues = res.issues;
} else {
this.usernameIssues = [];
}
});
}, 500),
},
mounted () {
this.temporaryDisplayName = this.user.profile.name;
this.temporaryUsername = this.user.auth.local.username;
},
props: {
avatarIntro: {
type: Boolean,
default: false,
});
}, 500),
},
watch: {
temporaryDisplayName: {
handler () {
this.validateDisplayName(this.temporaryDisplayName);
},
deep: true,
},
watch: {
temporaryDisplayName: {
handler () {
this.validateDisplayName(this.temporaryDisplayName);
},
deep: true,
},
temporaryUsername: {
handler () {
this.validateUsername(this.temporaryUsername);
},
deep: true,
temporaryUsername: {
handler () {
this.validateUsername(this.temporaryUsername);
},
deep: true,
},
};
},
mounted () {
this.temporaryDisplayName = this.user.profile.name;
this.temporaryUsername = this.user.auth.local.username;
},
props: {
avatarIntro: {
type: Boolean,
default: false,
},
},
};
</script>
@@ -66,19 +66,19 @@
</style>
<script>
import helloNametag from '@/assets/svg/hello-habitican.svg';
import usernameForm from './usernameForm';
import helloNametag from '@/assets/svg/hello-habitican.svg';
import usernameForm from './usernameForm';
export default {
components: {
usernameForm,
},
data () {
return {
icons: Object.freeze({
helloNametag,
}),
};
},
};
export default {
components: {
usernameForm,
},
data () {
return {
icons: Object.freeze({
helloNametag,
}),
};
},
};
</script>