From 39f58232d7affc36123355853996fe7b08e78cc1 Mon Sep 17 00:00:00 2001 From: Lukas Moertl Date: Fri, 1 Dec 2023 16:05:25 +0100 Subject: [PATCH] linting & format --- nuxt.config.ts | 1 + package.json | 8 ++++-- pnpm-lock.yaml | 7 +++++ .../DataDisplayKeywordInContext.vue | 2 +- .../DataDisplay/DataDisplayMediaSource.vue | 1 + .../DataDisplay/KWICDetailDialog.vue | 3 ++- src/composables/useKeywordInContextSearch.ts | 5 ++-- src/composables/useMediaSourceSearch.ts | 4 +++ src/composables/useRegionsSearch.ts | 15 ++++++----- src/composables/useWordFormsSearch.ts | 1 + src/pages/corpsum.vue | 15 ++++++----- src/plugins/highcharts.client.ts | 1 + src/plugins/jsonViewer.ts | 2 ++ src/stores/searchSettings.ts | 27 +++++++++++-------- src/types/freqsResponse.d.ts | 3 ++- src/types/query.d.ts | 7 +++++ 16 files changed, 70 insertions(+), 32 deletions(-) diff --git a/nuxt.config.ts b/nuxt.config.ts index e7cf11e..5ebe173 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -33,6 +33,7 @@ export default defineNuxtConfig({ componentIslands: true, }, pinia: { + // @ts-ignore autoImports: ["defineStore", "acceptHMRUpdate"], }, piniaPersistedstate: { diff --git a/package.json b/package.json index e8b515d..a6ad99f 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "types:check": "vue-tsc --noEmit", "validate": "run-p format:check lint:check types:check", "full-validate": "run-p format:check lint:check types:check test test:e2e", - "validate-without-tests": "run-p format:check lint:check types:check" + "validate-without-tests": "run-p format:fix lint:check types:check" }, "dependencies": { "@acdh-oeaw/lib": "^0.1.4", @@ -60,6 +60,7 @@ "@pinia-plugin-persistedstate/nuxt": "^1.2.0", "@playwright/test": "^1.36.1", "@tailwindcss/typography": "^0.5.9", + "@types/html-to-text": "^9.0.4", "@types/node": "^20.7.0", "autoprefixer": "^10.4.14", "eslint": "^8.45.0", @@ -102,7 +103,10 @@ "@acdh-oeaw/eslint-config-vue", "@acdh-oeaw/eslint-config-nuxt", "plugin:eslint-plugin-tailwindcss/recommended" - ] + ], + "rules": { + "@typescript-eslint/ban-ts-comment": "off" + } }, "lint-staged": { "*.@(vue)": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index acbeca4..adc221b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -76,6 +76,9 @@ devDependencies: '@tailwindcss/typography': specifier: ^0.5.9 version: 0.5.10(tailwindcss@3.3.5) + '@types/html-to-text': + specifier: ^9.0.4 + version: 9.0.4 '@types/node': specifier: ^20.7.0 version: 20.8.8 @@ -2268,6 +2271,10 @@ packages: '@types/unist': 3.0.1 dev: false + /@types/html-to-text@9.0.4: + resolution: {integrity: sha512-pUY3cKH/Nm2yYrEmDlPR1mR7yszjGx4DrwPjQ702C4/D5CwHuZTgZdIdwPkRbcuhs7BAh2L5rg3CL5cbRiGTCQ==} + dev: true + /@types/http-proxy@1.17.13: resolution: {integrity: sha512-GkhdWcMNiR5QSQRYnJ+/oXzu0+7JJEPC8vkWXK351BkhjraZF+1W13CUYARUvX9+NqIU2n6YHA4iwywsc/M6Sw==} dependencies: diff --git a/src/components/DataDisplay/DataDisplayKeywordInContext.vue b/src/components/DataDisplay/DataDisplayKeywordInContext.vue index 4811614..e5133f8 100644 --- a/src/components/DataDisplay/DataDisplayKeywordInContext.vue +++ b/src/components/DataDisplay/DataDisplayKeywordInContext.vue @@ -20,7 +20,7 @@ const headers = ref([ { title: "open", key: "open", type: "string" }, ]); -function open(item) { +function open(item: KeywordInContext) { console.log("open", { item }); selectedKWIC.value = item; } diff --git a/src/components/DataDisplay/DataDisplayMediaSource.vue b/src/components/DataDisplay/DataDisplayMediaSource.vue index fb052ca..9cd9b1b 100644 --- a/src/components/DataDisplay/DataDisplayMediaSource.vue +++ b/src/components/DataDisplay/DataDisplayMediaSource.vue @@ -19,6 +19,7 @@ const series = computed(() => { name: query.finalQuery, data: categories.value .map((category) => query.data.mediaSources.find(({ media }) => category === media)) + // @ts-ignore .map((a) => (a ? a[mode.value] : 0)), }; }); diff --git a/src/components/DataDisplay/KWICDetailDialog.vue b/src/components/DataDisplay/KWICDetailDialog.vue index fe7bbb2..1ff5d4d 100644 --- a/src/components/DataDisplay/KWICDetailDialog.vue +++ b/src/components/DataDisplay/KWICDetailDialog.vue @@ -19,6 +19,7 @@ const loading = ref(false); const details: Ref = ref(null); async function getDetails() { + if (!props.kwic) return; loading.value = true; details.value = null; const { data: _details } = await authenticatedFetch(STRUCTCTX_URL, { @@ -28,7 +29,7 @@ async function getDetails() { }); loading.value = false; - details.value = _details.value; + details.value = _details.value as StructCtxDocumentResponse; } watch(active, async () => { diff --git a/src/composables/useKeywordInContextSearch.ts b/src/composables/useKeywordInContextSearch.ts index 67bd422..8d8b168 100644 --- a/src/composables/useKeywordInContextSearch.ts +++ b/src/composables/useKeywordInContextSearch.ts @@ -24,7 +24,8 @@ export function useKeywordInContextSearch() { }); const keywordInContext = data.value as KeywordInContextData; // console.log('keywordInContext', { keywordInContext: keywordInContext.value }); - // eslint-disable-next-line require-atomic-updates + // eslint-disable + // @ts-ignore query.data.keywordInContext = keywordInContext.Lines.map( ({ Tbl_refs, Left, Kwic, toknum, Right }) => ({ // this mapping is directly taken from the ancient code @@ -40,7 +41,7 @@ export function useKeywordInContextSearch() { toknum, }), ); - + // eslint-enable query.loading.keywordInContext = false; // eslint-disable-line require-atomic-updates }; diff --git a/src/composables/useMediaSourceSearch.ts b/src/composables/useMediaSourceSearch.ts index 7f4efad..6e66f7e 100644 --- a/src/composables/useMediaSourceSearch.ts +++ b/src/composables/useMediaSourceSearch.ts @@ -21,6 +21,7 @@ export function useMediaSourceSearch() { const { selectedCorpus } = storeToRefs(corpora); const { data: mediaSources } = await authenticatedFetch(FREQUENCIES_MULTI_LEVEL_URL, { params: { + // @ts-ignore ...corpora.corporaForSearchKeys.value, format: "json", fmaxitems: 5000, @@ -46,12 +47,15 @@ export function useMediaSourceSearch() { console.log({ mediaSourceData, blocks: mediaSourceData.Blocks, + // @ts-ignore items: mediaSourceData.Blocks[0].Items, }); + // @ts-ignore const WordformData = mediaSourceData.Blocks[0].Items; WordformData.forEach(({ frq, Word, fpm }) => { query.data.mediaSources.push({ + // @ts-ignore media: Word[0].n, // todo absolute is here actually also a frequency absolute: frq, diff --git a/src/composables/useRegionsSearch.ts b/src/composables/useRegionsSearch.ts index 84bf3aa..61231d1 100644 --- a/src/composables/useRegionsSearch.ts +++ b/src/composables/useRegionsSearch.ts @@ -14,6 +14,7 @@ export function useRegionsSearch() { /* eslint-disable */ const { data: regionsData } = await authenticatedFetch(FREQUENCIES_MULTI_LEVEL_URL, { params: { + // @ts-ignore ...corpora.corporaForSearchKeys.value, format: "json", fmaxitems: 5000, @@ -35,13 +36,13 @@ export function useRegionsSearch() { return console.error("error on fetching freqml regions"); } const freqmlRegionData = regionsData.value as unknown as FreqMLRegionResponse; - query.data.regionalFrequencies = freqmlRegionData.Blocks[0].Items.map( - (regionalData: FreqMLRegion) => ({ - region: regionalData.Word[0].n, - absolute: escapeZeroSafe(regionalData.frq), - relative: escapeZeroSafe(regionalData.fpm), - }), - ); + query.data.regionalFrequencies = ( + freqmlRegionData.Blocks[0] ?? { Items: [] as Array } + ).Items.map((regionalData: FreqMLRegion) => ({ + region: regionalData.Word[0]?.n as unknown as Region, + absolute: escapeZeroSafe(regionalData.frq), + relative: escapeZeroSafe(regionalData.fpm), + })); query.loading.regionalFrequencies = false; }; diff --git a/src/composables/useWordFormsSearch.ts b/src/composables/useWordFormsSearch.ts index 46fb6e5..fecb157 100644 --- a/src/composables/useWordFormsSearch.ts +++ b/src/composables/useWordFormsSearch.ts @@ -14,6 +14,7 @@ export function useWordFormsSearch() { /* eslint-disable */ const { data: freqtWords } = await authenticatedFetch(FREQUENCIES_MULTI_LEVEL_URL, { params: { + // @ts-ignore ...corpora.corporaForSearchKeys.value, default_attr: "lemma", diff --git a/src/pages/corpsum.vue b/src/pages/corpsum.vue index 080e726..e019751 100644 --- a/src/pages/corpsum.vue +++ b/src/pages/corpsum.vue @@ -8,12 +8,13 @@ import DataDisplayWordFormFrequencies from "../components/DataDisplay/DataDispla import { useQuery } from "../stores/query"; import { useSearchSettingsStore } from "../stores/searchSettings"; -const searchSettings = useSearchSettingsStore(); -const { selectedSearches } = storeToRefs(searchSettings); definePageMeta({ title: "Corpsum.meta.title", }); +const searchSettings = useSearchSettingsStore(); +const { selectedSearches } = storeToRefs(searchSettings); + const t = useTranslations("Corpsum"); // const titles = [ @@ -47,23 +48,23 @@ const elementsPerRow = computed(() => { diff --git a/src/plugins/highcharts.client.ts b/src/plugins/highcharts.client.ts index 102e6d7..3addfb5 100644 --- a/src/plugins/highcharts.client.ts +++ b/src/plugins/highcharts.client.ts @@ -7,5 +7,6 @@ import HighchartsVue from "highcharts-vue"; export default defineNuxtPlugin((nuxtApp) => { MapsModule(Highcharts); + // @ts-ignore nuxtApp.vueApp.use(HighchartsVue, { tagName: "HighCharts" }); }); diff --git a/src/plugins/jsonViewer.ts b/src/plugins/jsonViewer.ts index 5409830..ada02b9 100644 --- a/src/plugins/jsonViewer.ts +++ b/src/plugins/jsonViewer.ts @@ -1,5 +1,7 @@ import "vue-json-viewer/style.css"; +// esilint-ignore-next-line +// @ts-ignore import JsonViewer from "vue-json-viewer/ssr"; export default defineNuxtPlugin((nuxtApp) => { diff --git a/src/stores/searchSettings.ts b/src/stores/searchSettings.ts index c4fb15c..b6b0895 100644 --- a/src/stores/searchSettings.ts +++ b/src/stores/searchSettings.ts @@ -1,13 +1,6 @@ import { acceptHMRUpdate, defineStore, storeToRefs } from "pinia"; import { type Ref, ref, watch } from "vue"; -type SearchFunctionKey = - | "keywordInContext" - | "mediaSources" - | "regionalFrequencies" - | "wordFormFrequencies" - | "yearlyFrequencies"; - export const useSearchSettingsStore = defineStore( "searchSettings", () => { @@ -16,6 +9,7 @@ export const useSearchSettingsStore = defineStore( const { getMediaSourceFrequencies } = useMediaSourceSearch(); const { getRegionsFrequencies } = useRegionsSearch(); const { getKeywordInContext } = useKeywordInContextSearch(); + const possibleSearchKeys: Ref> = ref([ { value: "yearlyFrequencies", title: "Yearly Frequencies" }, { value: "wordFormFrequencies", title: "Word Form Frequencies" }, @@ -36,7 +30,7 @@ export const useSearchSettingsStore = defineStore( mediaSources: getMediaSourceFrequencies, }; - const selectedSearches = ref([ + const selectedSearches: Ref> = ref([ // "keywordInContext", // "regionalFrequencies", // "wordFormFrequencies", @@ -47,8 +41,14 @@ export const useSearchSettingsStore = defineStore( async function doSearches(query: CorpusQuery) { // console.log({ selsearchVal: selectedSearches.value }); - // eslint-disable-next-line - return await Promise.all(selectedSearches.value.map((a) => searchFunctions[a](query))); + return await Promise.all( + selectedSearches.value.map( + (a: SearchFunctionKey) => + (searchFunctions[a] as unknown as (query: CorpusQuery) => Promise)( + query, + ) as unknown as Promise, + ), + ); } const queriesStore = useQuery(); @@ -74,7 +74,12 @@ export const useSearchSettingsStore = defineStore( await Promise.all(functionsToRun); }); - return { possibleSearchKeys, searchFunctions, selectedSearches, doSearches }; + return { + possibleSearchKeys, + searchFunctions, + selectedSearches, + doSearches, + }; }, { persist: true }, ); diff --git a/src/types/freqsResponse.d.ts b/src/types/freqsResponse.d.ts index 7263db8..27e6485 100644 --- a/src/types/freqsResponse.d.ts +++ b/src/types/freqsResponse.d.ts @@ -1,4 +1,4 @@ -export interface FreqsResponseData { +interface FreqsResponseData { Blocks: Array; wllimit: number; request: Request; @@ -36,6 +36,7 @@ interface Item { fbar: number; pfilter_list: Array; frq: number; + fpm: number; nfilter: string; norel: number; } diff --git a/src/types/query.d.ts b/src/types/query.d.ts index 7d66af3..88546bd 100644 --- a/src/types/query.d.ts +++ b/src/types/query.d.ts @@ -2,6 +2,13 @@ type CorpusQueryType = "custom" | "lc" | "lc*" | "lemma" | "word"; type Region = "agesamt" | "amitte" | "aost" | "asuedost" | "awest" | "spezifisch"; +type SearchFunctionKey = + | "keywordInContext" + | "mediaSources" + | "regionalFrequencies" + | "wordFormFrequencies" + | "yearlyFrequencies"; + interface KeywordInContext { date: string; source: string;