From 7095e38947bdaf1767b8c4c39123c910846446d5 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 17 May 2019 23:10:10 +0200 Subject: [PATCH 01/30] fixed post card design --- webapp/components/Category/index.vue | 2 +- webapp/components/PostCard/index.vue | 70 ++++++++++++++------------- webapp/components/Ribbon/index.vue | 48 ++++++++++++++++++ webapp/components/User/index.vue | 2 +- webapp/pages/post/_id/_slug/index.vue | 24 --------- 5 files changed, 87 insertions(+), 59 deletions(-) create mode 100644 webapp/components/Ribbon/index.vue diff --git a/webapp/components/Category/index.vue b/webapp/components/Category/index.vue index af602d4d0..028d8c4a4 100644 --- a/webapp/components/Category/index.vue +++ b/webapp/components/Category/index.vue @@ -13,7 +13,7 @@ export default { name: 'HcCategory', props: { icon: { type: String, required: true }, - name: { type: String, required: true } + name: { type: String, default: '' } } } diff --git a/webapp/components/PostCard/index.vue b/webapp/components/PostCard/index.vue index acddba5d6..aeb761fe1 100644 --- a/webapp/components/PostCard/index.vue +++ b/webapp/components/PostCard/index.vue @@ -1,65 +1,64 @@ diff --git a/webapp/pages/post/_id.vue b/webapp/pages/post/_id.vue index d8fc5d4f9..ab6ec0687 100644 --- a/webapp/pages/post/_id.vue +++ b/webapp/pages/post/_id.vue @@ -41,7 +41,7 @@ const options = { } `, path: 'post', - message: 'This post could not be found' + message: 'This post could not be found', } const persistentLinks = PersistentLinks(options) @@ -57,8 +57,8 @@ export default { children: [ { name: this.$t('common.comment', null, 2), - path: `/post/${id}/${slug}#comments` - } + path: `/post/${id}/${slug}#comments`, + }, // TODO implement /* { name: this.$t('common.letsTalk'), @@ -69,20 +69,20 @@ export default { name: this.$t('common.versus'), path: `/post/${id}/${slug}#versus` } */ - ] + ], }, { name: this.$t('common.moreInfo'), - path: `/post/${id}/${slug}/more-info` - } + path: `/post/${id}/${slug}/more-info`, + }, // TODO implement /* { name: this.$t('common.takeAction'), path: `/post/${id}/${slug}/take-action` } */ ] - } - } + }, + }, } diff --git a/webapp/pages/post/_id/_slug/index.vue b/webapp/pages/post/_id/_slug/index.vue index ad04f8421..b0718f893 100644 --- a/webapp/pages/post/_id/_slug/index.vue +++ b/webapp/pages/post/_id/_slug/index.vue @@ -94,7 +94,7 @@ import HcCommentList from '~/components/comments/CommentList' export default { transition: { name: 'slide-up', - mode: 'out-in' + mode: 'out-in', }, components: { HcTag, @@ -103,31 +103,31 @@ export default { HcShoutButton, ContentMenu, HcCommentForm, - HcCommentList + HcCommentList, }, head() { return { - title: this.title + title: this.title, } }, data() { return { post: null, ready: false, - title: 'loading' + title: 'loading', } }, watch: { Post(post) { this.post = post[0] || {} this.title = this.post.title - } + }, }, async asyncData(context) { const { params, error, - app: { apolloProvider, $i18n } + app: { apolloProvider, $i18n }, } = context const client = apolloProvider.defaultClient const query = gql(` @@ -206,7 +206,7 @@ export default { `) const variables = { slug: params.slug } const { - data: { Post } + data: { Post }, } = await client.query({ query, variables }) if (Post.length <= 0) { // TODO: custom 404 error page with translations @@ -216,7 +216,7 @@ export default { const [post] = Post return { post, - title: post.title + title: post.title, } }, mounted() { @@ -229,8 +229,8 @@ export default { methods: { isAuthor(id) { return this.$store.getters['auth/user'].id === id - } - } + }, + }, } diff --git a/webapp/pages/post/_id/_slug/more-info.vue b/webapp/pages/post/_id/_slug/more-info.vue index ae03fe658..e18ab8f57 100644 --- a/webapp/pages/post/_id/_slug/more-info.vue +++ b/webapp/pages/post/_id/_slug/more-info.vue @@ -62,16 +62,16 @@ import HcEmpty from '~/components/Empty.vue' export default { transition: { name: 'slide-up', - mode: 'out-in' + mode: 'out-in', }, components: { HcPostCard, - HcEmpty + HcEmpty, }, computed: { post() { return this.Post ? this.Post[0] || {} : {} - } + }, }, apollo: { Post: { @@ -128,11 +128,11 @@ export default { }, variables() { return { - slug: this.$route.params.slug + slug: this.$route.params.slug, } - } - } - } + }, + }, + }, } diff --git a/webapp/pages/post/_id/_slug/take-action.vue b/webapp/pages/post/_id/_slug/take-action.vue index 35cbe30fc..1dfb75208 100644 --- a/webapp/pages/post/_id/_slug/take-action.vue +++ b/webapp/pages/post/_id/_slug/take-action.vue @@ -12,7 +12,7 @@ import HcEmpty from '~/components/Empty.vue' export default { components: { - HcEmpty - } + HcEmpty, + }, } diff --git a/webapp/pages/post/create.vue b/webapp/pages/post/create.vue index fd8b493d3..a110965db 100644 --- a/webapp/pages/post/create.vue +++ b/webapp/pages/post/create.vue @@ -13,12 +13,11 @@ diff --git a/webapp/pages/post/edit/_id.vue b/webapp/pages/post/edit/_id.vue index cb61e2b40..2420a85b9 100644 --- a/webapp/pages/post/edit/_id.vue +++ b/webapp/pages/post/edit/_id.vue @@ -18,7 +18,7 @@ import HcContributionForm from '~/components/ContributionForm' export default { components: { - HcContributionForm + HcContributionForm, }, computed: { user() { @@ -29,14 +29,14 @@ export default { }, contribution() { return this.Post ? this.Post[0] : {} - } + }, }, watch: { contribution() { if (this.author.id !== this.user.id) { throw new Error(`You can't edit that!`) } - } + }, }, apollo: { Post: { @@ -71,11 +71,11 @@ export default { }, variables() { return { - id: this.$route.params.id || 'p1' + id: this.$route.params.id || 'p1', } }, - fetchPolicy: 'cache-and-network' - } - } + fetchPolicy: 'cache-and-network', + }, + }, } diff --git a/webapp/pages/profile/_id.vue b/webapp/pages/profile/_id.vue index 4d436146c..992e5efce 100644 --- a/webapp/pages/profile/_id.vue +++ b/webapp/pages/profile/_id.vue @@ -24,11 +24,11 @@ const options = { } `, message: 'This user could not be found', - path: 'profile' + path: 'profile', } const persistentLinks = PersistentLinks(options) export default { - mixins: [persistentLinks] + mixins: [persistentLinks], } diff --git a/webapp/pages/profile/_id/_slug.vue b/webapp/pages/profile/_id/_slug.vue index 266a3f9c6..3dfb2c751 100644 --- a/webapp/pages/profile/_id/_slug.vue +++ b/webapp/pages/profile/_id/_slug.vue @@ -337,18 +337,18 @@ export default { HcBadges, HcLoadMore, HcEmpty, - ContentMenu + ContentMenu, }, transition: { name: 'slide-up', - mode: 'out-in' + mode: 'out-in', }, data() { return { User: [], voted: false, page: 1, - pageSize: 6 + pageSize: 6, } }, computed: { @@ -367,8 +367,7 @@ export default { }, hasMore() { return ( - this.user.contributions && - this.user.contributions.length < this.user.contributionsCount + this.user.contributions && this.user.contributions.length < this.user.contributionsCount ) }, activePosts() { @@ -381,9 +380,7 @@ export default { const { socialMedia = [] } = this.user return socialMedia.map(socialMedia => { const { url } = socialMedia - const matches = url.match( - /^(?:https?:\/\/)?(?:[^@\n])?(?:www\.)?([^:\/\n?]+)/g - ) + const matches = url.match(/^(?:https?:\/\/)?(?:[^@\n])?(?:www\.)?([^:/\n?]+)/g) const [domain] = matches || [] const favicon = domain ? `${domain}/favicon.ico` : null const username = url.split('/').pop() @@ -393,14 +390,14 @@ export default { userName() { const { name } = this.user || {} return name || this.$t('profile.userAnonym') - } + }, }, watch: { User(val) { if (!val || !val.length) { throw new Error('User not found!') } - } + }, }, methods: { uniq(items, field = 'id') { @@ -418,20 +415,20 @@ export default { variables: { slug: this.$route.params.slug, first: this.pageSize, - offset: this.offset + offset: this.offset, }, // Transform the previous result with new data updateQuery: (previousResult, { fetchMoreResult }) => { let output = { User: this.User } output.User[0].contributions = [ ...previousResult.User[0].contributions, - ...fetchMoreResult.User[0].contributions + ...fetchMoreResult.User[0].contributions, ] return output }, - fetchPolicy: 'cache-and-network' + fetchPolicy: 'cache-and-network', }) - } + }, }, apollo: { User: { @@ -442,12 +439,12 @@ export default { return { slug: this.$route.params.slug, first: this.pageSize, - offset: 0 + offset: 0, } }, - fetchPolicy: 'cache-and-network' - } - } + fetchPolicy: 'cache-and-network', + }, + }, } diff --git a/webapp/pages/settings.vue b/webapp/pages/settings.vue index 68b7c6d31..48eab45ff 100644 --- a/webapp/pages/settings.vue +++ b/webapp/pages/settings.vue @@ -29,16 +29,16 @@ export default { return [ { name: this.$t('settings.data.name'), - path: `/settings` + path: `/settings`, }, { name: this.$t('settings.security.name'), - path: `/settings/security` + path: `/settings/security`, }, { name: this.$t('settings.social-media.name'), - path: `/settings/my-social-media` - } + path: `/settings/my-social-media`, + }, // TODO implement /* { name: this.$t('settings.invites.name'), @@ -66,7 +66,7 @@ export default { }, } */ ] - } - } + }, + }, } diff --git a/webapp/pages/settings/data-download.vue b/webapp/pages/settings/data-download.vue index 4bb70de24..5c9e5a24a 100644 --- a/webapp/pages/settings/data-download.vue +++ b/webapp/pages/settings/data-download.vue @@ -12,7 +12,7 @@ import HcEmpty from '~/components/Empty.vue' export default { components: { - HcEmpty - } + HcEmpty, + }, } diff --git a/webapp/pages/settings/delete-account.vue b/webapp/pages/settings/delete-account.vue index 77e8b542b..5f488fed1 100644 --- a/webapp/pages/settings/delete-account.vue +++ b/webapp/pages/settings/delete-account.vue @@ -12,7 +12,7 @@ import HcEmpty from '~/components/Empty.vue' export default { components: { - HcEmpty - } + HcEmpty, + }, } diff --git a/webapp/pages/settings/index.spec.js b/webapp/pages/settings/index.spec.js index 8ee68172e..f0eff0641 100644 --- a/webapp/pages/settings/index.spec.js +++ b/webapp/pages/settings/index.spec.js @@ -1,6 +1,5 @@ import { mount, createLocalVue } from '@vue/test-utils' import index from './index.vue' -import Vue from 'vue' import Vuex from 'vuex' import Styleguide from '@human-connection/styleguide' @@ -10,7 +9,6 @@ localVue.use(Vuex) localVue.use(Styleguide) describe('index.vue', () => { - let Wrapper let store let mocks let getters @@ -28,27 +26,27 @@ describe('index.vue', () => { id: 'u1', name: 'Peter', locationName: 'Berlin', - about: 'Smth' - } - } - }) + about: 'Smth', + }, + }, + }), }, $toast: { error: jest.fn(), - success: jest.fn() - } + success: jest.fn(), + }, } getters = { 'auth/user': () => { return {} - } + }, } }) describe('mount', () => { const Wrapper = () => { store = new Vuex.Store({ - getters + getters, }) return mount(index, { store, mocks, localVue }) } diff --git a/webapp/pages/settings/index.vue b/webapp/pages/settings/index.vue index a3b2298c3..18e251bbc 100644 --- a/webapp/pages/settings/index.vue +++ b/webapp/pages/settings/index.vue @@ -51,11 +51,11 @@ import gql from 'graphql-tag' import { mapGetters, mapMutations } from 'vuex' import { CancelToken } from 'axios' -import find from 'lodash/find' let timeout const mapboxToken = process.env.MAPBOX_TOKEN +/* const query = gql` query getUser($id: ID) { User(id: $id) { @@ -66,15 +66,11 @@ const query = gql` } } ` +*/ const mutation = gql` mutation($id: ID!, $name: String, $locationName: String, $about: String) { - UpdateUser( - id: $id - name: $name - locationName: $locationName - about: $about - ) { + UpdateUser(id: $id, name: $name, locationName: $locationName, about: $about) { id name locationName @@ -90,12 +86,12 @@ export default { cities: [], loadingData: false, loadingGeo: false, - formData: {} + formData: {}, } }, computed: { ...mapGetters({ - currentUser: 'auth/user' + currentUser: 'auth/user', }), form: { get: function() { @@ -104,12 +100,12 @@ export default { }, set: function(formData) { this.formData = formData - } - } + }, + }, }, methods: { ...mapMutations({ - setCurrentUser: 'auth/SET_USER' + setCurrentUser: 'auth/SET_USER', }), async submit() { this.loadingData = true @@ -117,13 +113,13 @@ export default { let { locationName } = this.formData locationName = locationName && (locationName['label'] || locationName) try { - const { data } = await this.$apollo.mutate({ + await this.$apollo.mutate({ mutation, variables: { id: this.currentUser.id, name, locationName, - about + about, }, update: (store, { data: { UpdateUser } }) => { const { name, locationName, about } = UpdateUser @@ -131,9 +127,9 @@ export default { ...this.currentUser, name, locationName, - about + about, }) - } + }, }) this.$toast.success(this.$t('settings.data.success')) } catch (err) { @@ -147,12 +143,7 @@ export default { timeout = setTimeout(() => this.requestGeoData(value), 500) }, processCityResults(res) { - if ( - !res || - !res.data || - !res.data.features || - !res.data.features.length - ) { + if (!res || !res.data || !res.data.features || !res.data.features.length) { return [] } let output = [] @@ -160,7 +151,7 @@ export default { output.push({ label: item.place_name, value: item.place_name, - id: item.id + id: item.id, }) }) @@ -188,8 +179,8 @@ export default { .get( `https://api.mapbox.com/geocoding/v5/mapbox.places/${place}.json?access_token=${mapboxToken}&types=region,place,country&language=${lang}`, { - cancelToken: this.axiosSource.token - } + cancelToken: this.axiosSource.token, + }, ) .then(res => { this.cities = this.processCityResults(res) @@ -197,7 +188,7 @@ export default { .finally(() => { this.loadingGeo = false }) - } - } + }, + }, } diff --git a/webapp/pages/settings/invites.vue b/webapp/pages/settings/invites.vue index 7ef6f66fc..947d0b333 100644 --- a/webapp/pages/settings/invites.vue +++ b/webapp/pages/settings/invites.vue @@ -12,7 +12,7 @@ import HcEmpty from '~/components/Empty.vue' export default { components: { - HcEmpty - } + HcEmpty, + }, } diff --git a/webapp/pages/settings/languages.vue b/webapp/pages/settings/languages.vue index 52367f85b..7879d6425 100644 --- a/webapp/pages/settings/languages.vue +++ b/webapp/pages/settings/languages.vue @@ -12,7 +12,7 @@ import HcEmpty from '~/components/Empty.vue' export default { components: { - HcEmpty - } + HcEmpty, + }, } diff --git a/webapp/pages/settings/my-organizations.vue b/webapp/pages/settings/my-organizations.vue index 2b38f71aa..f651cbc61 100644 --- a/webapp/pages/settings/my-organizations.vue +++ b/webapp/pages/settings/my-organizations.vue @@ -12,7 +12,7 @@ import HcEmpty from '~/components/Empty.vue' export default { components: { - HcEmpty - } + HcEmpty, + }, } diff --git a/webapp/pages/settings/my-social-media.spec.js b/webapp/pages/settings/my-social-media.spec.js index 559ba87d2..34793e066 100644 --- a/webapp/pages/settings/my-social-media.spec.js +++ b/webapp/pages/settings/my-social-media.spec.js @@ -1,6 +1,5 @@ import { mount, createLocalVue } from '@vue/test-utils' import MySocialMedia from './my-social-media.vue' -import Vue from 'vue' import Vuex from 'vuex' import Styleguide from '@human-connection/styleguide' @@ -11,7 +10,6 @@ localVue.use(Styleguide) describe('my-social-media.vue', () => { let wrapper - let Wrapper let store let mocks let getters @@ -27,25 +25,25 @@ describe('my-social-media.vue', () => { .fn() .mockRejectedValue({ message: 'Ouch!' }) .mockResolvedValueOnce({ - data: { CreateSocialMeda: { id: 's1', url: socialMediaUrl } } - }) + data: { CreateSocialMeda: { id: 's1', url: socialMediaUrl } }, + }), }, $toast: { error: jest.fn(), - success: jest.fn() - } + success: jest.fn(), + }, } getters = { 'auth/user': () => { return {} - } + }, } }) describe('mount', () => { const Wrapper = () => { store = new Vuex.Store({ - getters + getters, }) return mount(MySocialMedia, { store, mocks, localVue }) } @@ -60,9 +58,9 @@ describe('my-social-media.vue', () => { getters = { 'auth/user': () => { return { - socialMedia: [{ id: 's1', url: socialMediaUrl }] + socialMedia: [{ id: 's1', url: socialMediaUrl }], } - } + }, } }) @@ -80,20 +78,20 @@ describe('my-social-media.vue', () => { .fn() .mockRejectedValue({ message: 'Ouch!' }) .mockResolvedValueOnce({ - data: { DeleteSocialMeda: { id: 's1', url: socialMediaUrl } } - }) + data: { DeleteSocialMeda: { id: 's1', url: socialMediaUrl } }, + }), }, $toast: { error: jest.fn(), - success: jest.fn() - } + success: jest.fn(), + }, } getters = { 'auth/user': () => { return { - socialMedia: [{ id: 's1', url: socialMediaUrl }] + socialMedia: [{ id: 's1', url: socialMediaUrl }], } - } + }, } }) diff --git a/webapp/pages/settings/my-social-media.vue b/webapp/pages/settings/my-social-media.vue index 95a61bdd8..745e2f776 100644 --- a/webapp/pages/settings/my-social-media.vue +++ b/webapp/pages/settings/my-social-media.vue @@ -22,7 +22,8 @@ /> {{ link.url }} -    |    +    + |    { const { id, url } = socialMedia - const matches = url.match( - /^(?:https?:\/\/)?(?:[^@\n])?(?:www\.)?([^:\/\n?]+)/g - ) + const matches = url.match(/^(?:https?:\/\/)?(?:[^@\n])?(?:www\.)?([^:/\n?]+)/g) const [domain] = matches || [] const favicon = domain ? `${domain}/favicon.ico` : null return { id, url, favicon } }) - } + }, }, methods: { ...mapMutations({ - setCurrentUser: 'auth/SET_USER' + setCurrentUser: 'auth/SET_USER', }), handleAddSocialMedia() { this.$apollo @@ -105,22 +104,19 @@ export default { } `, variables: { - url: this.value + url: this.value, }, update: (store, { data }) => { - const socialMedia = [ - ...this.currentUser.socialMedia, - data.CreateSocialMedia - ] + const socialMedia = [...this.currentUser.socialMedia, data.CreateSocialMedia] this.setCurrentUser({ ...this.currentUser, - socialMedia + socialMedia, }) - } + }, }) .then(() => { - this.$toast.success(this.$t('settings.social-media.successAdd')), - (this.value = '') + this.$toast.success(this.$t('settings.social-media.successAdd')) + this.value = '' }) .catch(error => { this.$toast.error(error.message) @@ -138,17 +134,17 @@ export default { } `, variables: { - id: link.id + id: link.id, }, update: (store, { data }) => { const socialMedia = this.currentUser.socialMedia.filter( - element => element.id !== link.id + element => element.id !== link.id, ) this.setCurrentUser({ ...this.currentUser, - socialMedia + socialMedia, }) - } + }, }) .then(() => { this.$toast.success(this.$t('settings.social-media.successDelete')) @@ -156,8 +152,8 @@ export default { .catch(error => { this.$toast.error(error.message) }) - } - } + }, + }, } diff --git a/webapp/pages/settings/security.vue b/webapp/pages/settings/security.vue index ac95ff26e..e1c8ca0e0 100644 --- a/webapp/pages/settings/security.vue +++ b/webapp/pages/settings/security.vue @@ -5,12 +5,11 @@ diff --git a/webapp/plugins/apollo-config.js b/webapp/plugins/apollo-config.js index f65700ab4..83ec452e3 100644 --- a/webapp/plugins/apollo-config.js +++ b/webapp/plugins/apollo-config.js @@ -3,11 +3,11 @@ export default ({ app }) => { return { httpEndpoint: process.server ? backendUrl : '/api', httpLinkOptions: { - credentials: 'same-origin' + credentials: 'same-origin', }, credentials: true, tokenName: 'human-connection-token', persisting: false, - websocketsOnly: false + websocketsOnly: false, } } diff --git a/webapp/plugins/i18n.js b/webapp/plugins/i18n.js index 836ba220f..b568ca39e 100644 --- a/webapp/plugins/i18n.js +++ b/webapp/plugins/i18n.js @@ -1,7 +1,6 @@ import Vue from 'vue' -import Vuex from 'vuex' import vuexI18n from 'vuex-i18n/dist/vuex-i18n.umd.js' -import { debounce, isEmpty, find } from 'lodash' +import { isEmpty, find } from 'lodash' /** * TODO: Refactor and simplify browser detection @@ -48,11 +47,9 @@ export default ({ app, req, cookie, store }) => { onTranslationNotFound: function(locale, key) { if (debug) { /* eslint-disable-next-line no-console */ - console.warn( - `vuex-i18n :: Key '${key}' not found for locale '${locale}'` - ) + console.warn(`vuex-i18n :: Key '${key}' not found for locale '${locale}'`) } - } + }, }) // register the fallback locales @@ -80,9 +77,7 @@ export default ({ app, req, cookie, store }) => { } const availableLocales = process.env.locales.filter(lang => !!lang.enabled) - const locale = find(availableLocales, ['code', userLocale]) - ? userLocale - : 'en' + const locale = find(availableLocales, ['code', userLocale]) ? userLocale : 'en' if (locale !== 'en') { Vue.i18n.add(locale, require(`~/locales/${locale}.json`)) diff --git a/webapp/plugins/izi-toast.js b/webapp/plugins/izi-toast.js index 5900898ac..8bb41c961 100644 --- a/webapp/plugins/izi-toast.js +++ b/webapp/plugins/izi-toast.js @@ -8,6 +8,6 @@ export default ({ app }) => { position: 'bottomRight', transitionIn: 'bounceInLeft', layout: 2, - theme: 'dark' + theme: 'dark', }) } diff --git a/webapp/plugins/keep-alive.js b/webapp/plugins/keep-alive.js index 93a8a1767..91d7ed1f0 100644 --- a/webapp/plugins/keep-alive.js +++ b/webapp/plugins/keep-alive.js @@ -24,7 +24,7 @@ if (!process.server) { if (this.$metaInfo && !keepAlivePages.includes(lastRoute)) { this.$destroy() } - } + }, }) } Vue.use(keepAliveHook) diff --git a/webapp/plugins/v-tooltip.js b/webapp/plugins/v-tooltip.js index a018ec5f3..77d0ac1b8 100644 --- a/webapp/plugins/v-tooltip.js +++ b/webapp/plugins/v-tooltip.js @@ -4,13 +4,13 @@ import VTooltip from 'v-tooltip' Vue.use(VTooltip, { defaultDelay: { show: 500, - hide: 50 + hide: 50, }, defaultOffset: 2, defaultPopperOptions: { - removeOnDestroy: true + removeOnDestroy: true, }, popover: { // defaultArrowClass: 'm-dropdown__arrow' - } + }, }) diff --git a/webapp/plugins/vue-directives.js b/webapp/plugins/vue-directives.js index 618bbd4e2..f54c02167 100644 --- a/webapp/plugins/vue-directives.js +++ b/webapp/plugins/vue-directives.js @@ -10,7 +10,7 @@ export default ({ app }) => { el.focus() } }) - } + }, }) Vue.directive('router-link', { @@ -28,6 +28,6 @@ export default ({ app }) => { if (binding.clickEventListener) { el.removeEventListener('click', binding.clickEventListener) } - } + }, }) } diff --git a/webapp/plugins/vue-filters.js b/webapp/plugins/vue-filters.js index bf59a7dba..aad978d72 100644 --- a/webapp/plugins/vue-filters.js +++ b/webapp/plugins/vue-filters.js @@ -2,7 +2,6 @@ import Vue from 'vue' import { enUS, de, nl, fr, es } from 'date-fns/locale' import format from 'date-fns/format' -import formatRelative from 'date-fns/formatRelative' import addSeconds from 'date-fns/addSeconds' import accounting from 'accounting' @@ -14,7 +13,7 @@ export default ({ app = {} }) => { fr: fr, es: es, pt: es, - pl: de + pl: de, } const getLocalizedFormat = () => { let locale = app.$i18n.locale() @@ -25,22 +24,16 @@ export default ({ app = {} }) => { date: (value, fmt = 'dd. MMM yyyy') => { if (!value) return '' return format(new Date(value), fmt, { - locale: getLocalizedFormat() + locale: getLocalizedFormat(), }) }, dateTime: (value, fmt = 'dd. MMM yyyy HH:mm') => { if (!value) return '' return format(new Date(value), fmt, { - locale: getLocalizedFormat() + locale: getLocalizedFormat(), }) }, - number: ( - value, - precision = 2, - thousands = '.', - decimals = ',', - fallback = null - ) => { + number: (value, precision = 2, thousands = '.', decimals = ',', fallback = null) => { if (isNaN(value) && fallback) { return fallback } @@ -99,7 +92,7 @@ export default ({ app = {} }) => { } return excerpt - } + }, }) // add all methods as filters on each vue component diff --git a/webapp/server/index.js b/webapp/server/index.js index 66738790e..d06bb1f6d 100644 --- a/webapp/server/index.js +++ b/webapp/server/index.js @@ -30,7 +30,7 @@ async function start() { app.listen(port, host) consola.ready({ message: `Server listening on http://${host}:${port}`, - badge: true + badge: true, }) } start() diff --git a/webapp/store/auth.js b/webapp/store/auth.js index ca1b453ba..87de84d9a 100644 --- a/webapp/store/auth.js +++ b/webapp/store/auth.js @@ -1,11 +1,10 @@ import gql from 'graphql-tag' -import jwt from 'jsonwebtoken' export const state = () => { return { user: null, token: null, - pending: false + pending: false, } } @@ -18,7 +17,7 @@ export const mutations = { }, SET_PENDING(state, pending) { state.pending = pending - } + }, } export const getters = { @@ -35,17 +34,14 @@ export const getters = { return !!state.user && state.user.role === 'admin' }, isModerator(state) { - return ( - !!state.user && - (state.user.role === 'admin' || state.user.role === 'moderator') - ) + return !!state.user && (state.user.role === 'admin' || state.user.role === 'moderator') }, user(state) { return state.user || {} }, token(state) { return state.token - } + }, } export const actions = { @@ -71,7 +67,7 @@ export const actions = { async fetchCurrentUser({ commit, dispatch }) { const client = this.app.apolloProvider.defaultClient const { - data: { currentUser } + data: { currentUser }, } = await client.query({ query: gql(`{ currentUser { @@ -105,7 +101,7 @@ export const actions = { } } } - }`) + }`), }) if (!currentUser) return dispatch('logout') commit('SET_USER', currentUser) @@ -117,14 +113,14 @@ export const actions = { try { const client = this.app.apolloProvider.defaultClient const { - data: { login } + data: { login }, } = await client.mutate({ mutation: gql(` mutation($email: String!, $password: String!) { login(email: $email, password: $password) } `), - variables: { email, password } + variables: { email, password }, }) await this.app.$apolloHelpers.onLogin(login) commit('SET_TOKEN', login) @@ -142,12 +138,9 @@ export const actions = { return this.app.$apolloHelpers.onLogout() }, - register( - { dispatch, commit }, - { email, password, inviteCode, invitedByUserId } - ) {}, + register({ dispatch, commit }, { email, password, inviteCode, invitedByUserId }) {}, async patch({ state, commit, dispatch }, data) {}, resendVerifySignup({ state, dispatch }) {}, resetPassword({ state }, data) {}, - setNewPassword({ state }, data) {} + setNewPassword({ state }, data) {}, } diff --git a/webapp/store/auth.test.js b/webapp/store/auth.test.js index 9b6a33195..e45fec693 100644 --- a/webapp/store/auth.test.js +++ b/webapp/store/auth.test.js @@ -1,4 +1,4 @@ -import { getters, mutations, actions } from './auth.js' +import { getters, actions } from './auth.js' let state let commit @@ -12,14 +12,15 @@ const currentUser = { slug: 'jenny-rostock', email: 'user@example.org', avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/mutu_krish/128.jpg', - role: 'user' + role: 'user', } const successfulLoginResponse = { data: { login: token } } const successfulCurrentUserResponse = { data: { currentUser } } +/* const incorrectPasswordResponse = { data: { - login: null + login: null, }, errors: [ { @@ -27,13 +28,14 @@ const incorrectPasswordResponse = { locations: [ { line: 2, - column: 3 - } + column: 3, + }, ], - path: ['login'] - } - ] + path: ['login'], + }, + ], } +*/ beforeEach(() => { commit = jest.fn() @@ -59,9 +61,9 @@ describe('actions', () => { const module = { app: { $apolloHelpers: { - getToken: () => token - } - } + getToken: () => token, + }, + }, } action = actions.init.bind(module) return action({ commit, dispatch }) @@ -91,9 +93,7 @@ describe('actions', () => { it('saves the JWT Bearer token', async () => { await theAction() - expect(commit.mock.calls).toEqual( - expect.arrayContaining([['SET_TOKEN', token]]) - ) + expect(commit.mock.calls).toEqual(expect.arrayContaining([['SET_TOKEN', token]])) }) }) }) @@ -105,12 +105,10 @@ describe('actions', () => { app: { apolloProvider: { defaultClient: { - query: jest.fn(() => - Promise.resolve(successfulCurrentUserResponse) - ) - } - } - } + query: jest.fn(() => Promise.resolve(successfulCurrentUserResponse)), + }, + }, + }, } action = actions.fetchCurrentUser.bind(module) await action({ commit }) @@ -126,12 +124,11 @@ describe('actions', () => { name: 'Jenny Rostock', slug: 'jenny-rostock', email: 'user@example.org', - avatar: - 'https://s3.amazonaws.com/uifaces/faces/twitter/mutu_krish/128.jpg', - role: 'user' - } - ] - ]) + avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/mutu_krish/128.jpg', + role: 'user', + }, + ], + ]), ) }) }) @@ -144,19 +141,16 @@ describe('actions', () => { app: { apolloProvider: { defaultClient: { - mutate: jest.fn(() => Promise.resolve(successfulLoginResponse)) - } + mutate: jest.fn(() => Promise.resolve(successfulLoginResponse)), + }, }, $apolloHelpers: { - onLogin: jest.fn(() => Promise.resolve()) - } - } + onLogin: jest.fn(() => Promise.resolve()), + }, + }, } action = actions.login.bind(module) - await action( - { commit, dispatch }, - { email: 'user@example.org', password: '1234' } - ) + await action({ commit, dispatch }, { email: 'user@example.org', password: '1234' }) }) afterEach(() => { @@ -164,9 +158,7 @@ describe('actions', () => { }) it('saves the JWT Bearer token', () => { - expect(commit.mock.calls).toEqual( - expect.arrayContaining([['SET_TOKEN', token]]) - ) + expect(commit.mock.calls).toEqual(expect.arrayContaining([['SET_TOKEN', token]])) }) it('fetches the user', () => { @@ -175,10 +167,7 @@ describe('actions', () => { it('saves pending flags in order', () => { expect(commit.mock.calls).toEqual( - expect.arrayContaining([ - ['SET_PENDING', true], - ['SET_PENDING', false] - ]) + expect.arrayContaining([['SET_PENDING', true], ['SET_PENDING', false]]), ) }) }) @@ -188,13 +177,13 @@ describe('actions', () => { let mutate beforeEach(() => { - mutate = jest.fn(() => Promise.reject('This error is expected.')) + mutate = jest.fn(() => Promise.reject('This error is expected.')) // eslint-disable-line prefer-promise-reject-errors onLogin = jest.fn(() => Promise.resolve()) const module = { app: { apolloProvider: { defaultClient: { mutate } }, - $apolloHelpers: { onLogin } - } + $apolloHelpers: { onLogin }, + }, } action = actions.login.bind(module) }) @@ -205,7 +194,7 @@ describe('actions', () => { it('populates error messages', async () => { expect( - action({ commit }, { email: 'user@example.org', password: 'wrong' }) + action({ commit }, { email: 'user@example.org', password: 'wrong' }), ).rejects.toThrowError('This error is expected.') expect(mutate).toHaveBeenCalled() expect(onLogin).not.toHaveBeenCalled() @@ -213,16 +202,10 @@ describe('actions', () => { it('saves pending flags in order', async () => { try { - await action( - { commit }, - { email: 'user@example.org', password: 'wrong' } - ) + await action({ commit }, { email: 'user@example.org', password: 'wrong' }) } catch (err) {} // ignore expect(commit.mock.calls).toEqual( - expect.arrayContaining([ - ['SET_PENDING', true], - ['SET_PENDING', false] - ]) + expect.arrayContaining([['SET_PENDING', true], ['SET_PENDING', false]]), ) }) }) diff --git a/webapp/store/index.js b/webapp/store/index.js index 91be021a5..8bc4ed563 100644 --- a/webapp/store/index.js +++ b/webapp/store/index.js @@ -5,5 +5,5 @@ export const mutations = {} export const actions = { async nuxtServerInit({ dispatch }) { await dispatch('auth/init') - } + }, } diff --git a/webapp/store/modal.js b/webapp/store/modal.js index f7bc1ad8e..72617f592 100644 --- a/webapp/store/modal.js +++ b/webapp/store/modal.js @@ -1,7 +1,7 @@ export const state = () => { return { open: null, - data: {} + data: {}, } } @@ -9,7 +9,7 @@ export const mutations = { SET_OPEN(state, ctx) { state.open = ctx.name || null state.data = ctx.data || {} - } + }, } export const getters = { @@ -18,5 +18,5 @@ export const getters = { }, data(state) { return state.data - } + }, } diff --git a/webapp/store/notifications.js b/webapp/store/notifications.js index cfb41e333..8e9b333b4 100644 --- a/webapp/store/notifications.js +++ b/webapp/store/notifications.js @@ -3,7 +3,7 @@ import gql from 'graphql-tag' export const state = () => { return { notifications: null, - pending: false + pending: false, } } @@ -19,13 +19,13 @@ export const mutations = { const toBeUpdated = notifications.find(n => { return n.id === notification.id }) - toBeUpdated = { ...toBeUpdated, ...notification } - } + state.notifications = { ...toBeUpdated, ...notification } + }, } export const getters = { notifications(state) { return !!state.notifications - } + }, } export const actions = { @@ -36,7 +36,7 @@ export const actions = { let notifications try { const { - data: { currentUser } + data: { currentUser }, } = await client.query({ query: gql(`{ currentUser { @@ -59,10 +59,9 @@ export const actions = { } } } - }`) + }`), }) notifications = currentUser.notifications - console.log(notifications) commit('SET_NOTIFICATIONS', notifications) } finally { commit('SET_PENDING', false) @@ -82,8 +81,8 @@ export const actions = { `) const variables = { id: notificationId, read: true } const { - data: { UpdateNotification } + data: { UpdateNotification }, } = await client.mutate({ mutation, variables }) commit('UPDATE_NOTIFICATIONS', UpdateNotification) - } + }, } diff --git a/webapp/store/search.js b/webapp/store/search.js index 0f9c00440..4aeb5030d 100644 --- a/webapp/store/search.js +++ b/webapp/store/search.js @@ -5,7 +5,7 @@ export const state = () => { return { quickResults: [], quickPending: false, - quickValue: '' + quickValue: '', } } @@ -19,7 +19,7 @@ export const mutations = { }, SET_QUICK_VALUE(state, value) { state.quickValue = value - } + }, } export const getters = { @@ -31,7 +31,7 @@ export const getters = { }, quickValue(state) { return state.quickValue - } + }, } export const actions = { @@ -64,8 +64,8 @@ export const actions = { } `), variables: { - filter: value.replace(/\s/g, '~ ') + '~' - } + filter: value.replace(/\s/g, '~ ') + '~', + }, }) .then(res => { commit('SET_QUICK_RESULTS', res.data.findPosts || []) @@ -82,5 +82,5 @@ export const actions = { commit('SET_QUICK_PENDING', false) commit('SET_QUICK_RESULTS', []) commit('SET_QUICK_VALUE', '') - } + }, } From ce3d16c146c161c20db9cfbb51b8ec3fbcabecb3 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 23 May 2019 20:02:56 +0200 Subject: [PATCH 30/30] fixed test error caused by manual lint error fixing --- webapp/components/Comment.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/components/Comment.spec.js b/webapp/components/Comment.spec.js index 6b5339ec2..ebb9b8bf8 100644 --- a/webapp/components/Comment.spec.js +++ b/webapp/components/Comment.spec.js @@ -65,6 +65,7 @@ describe('Comment.vue', () => { }) it('translates a placeholder', () => { + /* const wrapper = */ Wrapper() const calls = mocks.$t.mock.calls const expected = [['comment.content.unavailable-placeholder']] expect(calls).toEqual(expect.arrayContaining(expected))