From 2f80e0935f5f4220270af1202df329f0d5c1fffd Mon Sep 17 00:00:00 2001 From: Kasper Seweryn Date: Sun, 1 May 2022 21:57:22 +0200 Subject: [PATCH] Migrate a couple of components to new v-model and cleanup linting stuff --- front/.eslintrc.js | 3 +- front/package.json | 31 +--- front/src/components/Sidebar.vue | 4 +- front/src/components/admin/SettingsGroup.vue | 9 +- .../components/admin/SignupFormBuilder.vue | 164 ++++++++---------- front/src/components/auth/SignupForm.vue | 2 +- front/src/components/common/CollapseLink.vue | 41 ++--- front/src/components/common/ContentForm.vue | 5 +- front/src/components/common/CopyInput.vue | 55 +++--- front/src/components/common/Message.vue | 2 +- front/src/components/forms/PasswordInput.vue | 106 +++++------ .../src/components/library/radios/Filter.vue | 2 +- .../manage/moderation/ReportCard.vue | 4 +- .../notifications/NotificationRow.vue | 2 +- front/src/components/semantic/Modal.vue | 1 + front/src/embed.ts | 4 +- front/src/init/directives.ts | 4 +- front/src/main.ts | 8 +- front/src/router/index.ts | 16 +- front/src/shims-vue.d.ts | 6 + front/src/store/index.ts | 9 +- front/src/types.ts | 17 ++ front/src/utils/index.ts | 15 +- .../views/admin/moderation/ReportsList.vue | 2 +- front/src/views/auth/Login.vue | 2 +- front/tsconfig.json | 31 ++-- front/tsconfig.node.json | 8 + 27 files changed, 260 insertions(+), 293 deletions(-) create mode 100644 front/src/shims-vue.d.ts create mode 100644 front/tsconfig.node.json diff --git a/front/.eslintrc.js b/front/.eslintrc.js index 0e0bcac8e..cd4b153f9 100644 --- a/front/.eslintrc.js +++ b/front/.eslintrc.js @@ -34,7 +34,8 @@ module.exports = { // and gettext for vue 2 '@typescript-eslint/ban-ts-comment': 'off', - // TODO (wvffle): Enable typescript rules later + // TODO (wvffle): Enable these rules later + 'vue/multi-word-component-names': 'off', '@typescript-eslint/no-this-alias': 'off', '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-unused-vars': 'off', diff --git a/front/package.json b/front/package.json index 1c8b753ef..b0f97b813 100644 --- a/front/package.json +++ b/front/package.json @@ -11,6 +11,7 @@ "serve": "vite preview", "test:unit": "jest", "lint": "eslint --ext .ts,.js,.vue src", + "lint:tsc": "vue-tsc --noEmit", "fix-fomantic-css": "scripts/fix-fomantic-css.sh", "i18n-compile": "scripts/i18n-compile.sh", "i18n-extract": "scripts/i18n-extract.sh", @@ -40,6 +41,7 @@ "vue-gettext": "2.1.12", "vue-plyr": "7.0.0", "vue-router": "4.0.14", + "vue-tsc": "0.34.7", "vue-upload-component": "2.8.22", "vue3-gettext": "2.2.0-alpha.1", "vue3-lazyload": "0.2.5-beta", @@ -49,9 +51,6 @@ "vuex-router-sync": "5.0.0" }, "devDependencies": { - "@babel/core": "7.17.12", - "@babel/plugin-transform-runtime": "7.17.12", - "@babel/preset-env": "7.16.11", "@types/jest": "27.4.1", "@types/jquery": "3.5.14", "@types/lodash-es": "4.17.6", @@ -62,9 +61,7 @@ "@vue/eslint-config-standard": "6.1.0", "@vue/eslint-config-typescript": "10.0.0", "@vue/test-utils": "1.3.0", - "autoprefixer": "10.4.7", - "babel-core": "7.0.0-bridge.0", - "babel-jest": "27.5.1", + "autoprefixer": "10.4.4", "chai": "4.3.6", "easygettext": "2.17.0", "eslint": "8.11.0", @@ -74,7 +71,6 @@ "eslint-plugin-node": "11.1.0", "eslint-plugin-promise": "6.0.0", "eslint-plugin-vue": "7.20.0", - "glob-all": "3.3.0", "jest-cli": "27.5.1", "moxios": "0.4.0", "sinon": "13.0.2", @@ -91,27 +87,6 @@ "resolutions": { "vue-plyr/plyr": "3.6.12" }, - "postcss": { - "plugins": { - "autoprefixer": {} - } - }, - "browserslist": [ - "IE >= 11", - "Firefox >= 52", - "ChromeAndroid >= 70", - "Chrome >= 49", - "Safari >= 9", - "Edge >= 16", - "Opera >= 57", - "OperaMini >= 57", - "Samsung >= 7", - "FirefoxAndroid >= 63", - "UCAndroid >= 11", - "iOS >= 9", - "Android >= 4", - "not dead" - ], "jest": { "moduleFileExtensions": [ "ts", diff --git a/front/src/components/Sidebar.vue b/front/src/components/Sidebar.vue index 6a7281460..4c062b928 100644 --- a/front/src/components/Sidebar.vue +++ b/front/src/components/Sidebar.vue @@ -154,8 +154,8 @@ +import SignupForm from '~/components/auth/SignupForm.vue' +import { useVModel } from '@vueuse/core' +import { computed, ref } from 'vue' +import { useGettext } from 'vue3-gettext' +import { Form } from '~/types' +import { arrayMove } from '~/utils' + +interface Props { + modelValue: Form + signupApprovalEnabled?: boolean +} + +const props = withDefaults(defineProps(), { + signupApprovalEnabled: false +}) + +const emit = defineEmits(['update:modelValue']) +const value = useVModel(props, 'modelValue', emit, { deep: true }) + +const maxFields = ref(10) +const isPreviewing = ref(false) + +const { $pgettext } = useGettext() +const labels = computed(() => ({ + delete: $pgettext('*/*/*', 'Delete'), + up: $pgettext('*/*/*', 'Move up'), + down: $pgettext('*/*/*', 'Move down') +})) + +if (!value.value?.fields) { + value.value = { + help_text: { + text: '', + content_type: 'text/markdown' + }, + fields: [] + } +} + +const addField = () => { + value.value.fields.push({ + label: $pgettext('*/*/Form-builder', 'Additional field') + ' ' + (value.value.fields.length + 1), + required: true, + input_type: 'short_text' + }) +} + +const remove = (idx: number) => { + value.value.fields.splice(idx, 1) +} + +const move = (idx: number, increment: number) => { + if (idx + increment >= value.value.fields.length) return + if (idx === 0 && increment < 0) return + arrayMove(value.value.fields, idx, idx + increment) +} + + - - diff --git a/front/src/components/auth/SignupForm.vue b/front/src/components/auth/SignupForm.vue index a59ad7d8f..9922aaf58 100644 --- a/front/src/components/auth/SignupForm.vue +++ b/front/src/components/auth/SignupForm.vue @@ -170,7 +170,7 @@ export default { defaultInvitation: { type: String, required: false, default: null }, next: { type: String, default: '/' }, buttonClasses: { type: String, default: 'success' }, - customization: { type: Object, default: null }, + customization: { type: Object, default: null }, // ts type: Form fetchDescriptionHtml: { type: Boolean, default: false }, signupApprovalEnabled: { type: Boolean, default: null, required: false } }, diff --git a/front/src/components/common/CollapseLink.vue b/front/src/components/common/CollapseLink.vue index 30d6dc326..0d39b5300 100644 --- a/front/src/components/common/CollapseLink.vue +++ b/front/src/components/common/CollapseLink.vue @@ -1,32 +1,33 @@ + + - diff --git a/front/src/components/common/ContentForm.vue b/front/src/components/common/ContentForm.vue index d02d95e0a..5cf0f44b7 100644 --- a/front/src/components/common/ContentForm.vue +++ b/front/src/components/common/ContentForm.vue @@ -124,9 +124,8 @@ export default { await this.loadPreview() } if (!v) { - this.$nextTick(() => { - this.$refs.textarea.focus() - }) + await this.$nextTick() + this.$refs.textarea.focus() } } }, diff --git a/front/src/components/common/CopyInput.vue b/front/src/components/common/CopyInput.vue index 614b81382..d14ca2875 100644 --- a/front/src/components/common/CopyInput.vue +++ b/front/src/components/common/CopyInput.vue @@ -1,3 +1,23 @@ + + - diff --git a/front/src/components/common/Message.vue b/front/src/components/common/Message.vue index d78d6d574..f81fd1a95 100644 --- a/front/src/components/common/Message.vue +++ b/front/src/components/common/Message.vue @@ -23,7 +23,7 @@ onMounted(() => { ...props.message } - // @ts-ignore + // @ts-expect-error $('body').toast(params) $('.ui.toast.visible').last().attr('role', 'alert') }) diff --git a/front/src/components/forms/PasswordInput.vue b/front/src/components/forms/PasswordInput.vue index b9dab0e4c..f78426f0e 100644 --- a/front/src/components/forms/PasswordInput.vue +++ b/front/src/components/forms/PasswordInput.vue @@ -1,12 +1,53 @@ + + - diff --git a/front/src/components/library/radios/Filter.vue b/front/src/components/library/radios/Filter.vue index ca5a7c286..16ea97766 100644 --- a/front/src/components/library/radios/Filter.vue +++ b/front/src/components/library/radios/Filter.vue @@ -68,7 +68,7 @@

diff --git a/front/src/components/manage/moderation/ReportCard.vue b/front/src/components/manage/moderation/ReportCard.vue index 15391a8ab..0bf1dd29d 100644 --- a/front/src/components/manage/moderation/ReportCard.vue +++ b/front/src/components/manage/moderation/ReportCard.vue @@ -47,8 +47,8 @@ diff --git a/front/src/components/notifications/NotificationRow.vue b/front/src/components/notifications/NotificationRow.vue index e524241ca..50e6d309d 100644 --- a/front/src/components/notifications/NotificationRow.vue +++ b/front/src/components/notifications/NotificationRow.vue @@ -20,7 +20,7 @@ v-html="notificationData.message" /> -