From a870c107b6309e62928dfd710f6c48bda5d84726 Mon Sep 17 00:00:00 2001 From: n0099 Date: Mon, 11 Mar 2024 00:00:10 +0800 Subject: [PATCH] + ref `initialPageCursor` to fix the very first fetching not carrying the cursor route param * fix still showing `` when fetching next page - the indicator of the current cursor route param - ref `lastFetchingRoute` since the only usage after 2ed3aa04d13cf73d4e3dcf751d336a3e93477d91 that is `scrollToPostListItemByRoute()` no longer requires using different route as of c7571bba7f4f618fd2312778c0e61fd2603c9ffd @ `` * replace param `enabled` with `options` for `useApi*()` to allow any caller to override any `Use*QueryOptions` @ index.ts - interface `CursorPaginationQueryParam` due to 2ed3aa04d13cf73d4e3dcf751d336a3e93477d91 @ index.d.ts @ api * fix typing definations now exported under files with extension `.d.ts` as of `echart@5.5.0` since 3b65bba4f3e58721ee7bb4d9901e9803439e7ad5 @ `shared/echarts.ts` & `` * fix `eslint-disable-next-line` not working since 8ec64b05a0276fccae614106cf8f8bfd22a81a59 @ `` * fix violation of rule `unicorn/no-abusive-eslint-disable` @ gtag.js & stats.js * fix violation of rule `vue/no-dupe-keys` @ `components/User/` * add an option `type-literal` for rule `vue/define-emits-declaration` @ .eslintrc.cjs @ fe --- fe/.eslintrc.cjs | 2 +- fe/src/api/index.d.ts | 5 ++--- fe/src/api/index.ts | 19 ++++++++++++------- .../Post/renderers/RendererTable.vue | 3 ++- fe/src/components/User/QueryForm.vue | 6 +++--- fe/src/gtag.js | 4 ++-- fe/src/shared/echarts.ts | 3 ++- fe/src/stats.js | 5 ++++- fe/src/views/BilibiliVote.vue | 6 ++++-- fe/src/views/Post.vue | 13 ++++++------- 10 files changed, 38 insertions(+), 28 deletions(-) diff --git a/fe/.eslintrc.cjs b/fe/.eslintrc.cjs index f79f9323..be5c5f9c 100644 --- a/fe/.eslintrc.cjs +++ b/fe/.eslintrc.cjs @@ -507,7 +507,7 @@ const eslintPluginVue = { // as of eslint-plugin-vue@9.19.2 }], 'vue/match-component-import-name': 'error', 'vue/define-props-declaration': 'error', - 'vue/define-emits-declaration': 'error', + 'vue/define-emits-declaration': ['error', 'type-literal'], 'vue/no-required-prop-with-default': 'error', 'vue/v-on-handler-style': ['error', 'inline-function'], 'vue/multiline-ternary': 'error', diff --git a/fe/src/api/index.d.ts b/fe/src/api/index.d.ts index 63fb52cc..62b31c10 100644 --- a/fe/src/api/index.d.ts +++ b/fe/src/api/index.d.ts @@ -44,7 +44,6 @@ export type ApiStatsForumPostCount = Api<{ }>; export type Cursor = string; -interface CursorPaginationQueryParam { cursor?: Cursor } interface CursorPagination { pages: { currentCursor: Cursor, @@ -55,7 +54,7 @@ interface CursorPagination { export type ApiUsers = Api< CursorPagination & { users: User[] }, - CursorPaginationQueryParam & SelectUserParams & { gender?: UserGenderQueryParam } + SelectUserParams & { gender?: UserGenderQueryParam } >; export type JsonString = string; @@ -72,4 +71,4 @@ export type ApiPosts = Api }>, users: User[] -}, CursorPaginationQueryParam & { query: JsonString }>; +}, { query: JsonString }>; diff --git a/fe/src/api/index.ts b/fe/src/api/index.ts index 5b6c355c..0492315f 100644 --- a/fe/src/api/index.ts +++ b/fe/src/api/index.ts @@ -1,6 +1,6 @@ import type { Api, ApiError, ApiForums, ApiPosts, ApiStatsForumPostCount, ApiStatus, ApiUsers, Cursor, CursorPagination } from '@/api/index.d'; -import type { MaybeRefOrGetter, Ref } from 'vue'; -import type { InfiniteData, QueryKey } from '@tanstack/vue-query'; +import type { Ref } from 'vue'; +import type { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseQueryOptions } from '@tanstack/vue-query'; import { useInfiniteQuery, useQuery } from '@tanstack/vue-query'; import nprogress from 'nprogress'; import { stringify } from 'qs'; @@ -86,18 +86,23 @@ const useApi = < TResponse = TApi['response'], TQueryParam = TApi['queryParam']> (endpoint: string, queryFn: QueryFunctions) => - (queryParam?: Ref, enabled?: MaybeRefOrGetter) => + (queryParam?: Ref, options?: Partial>) => useQuery({ queryKey: [endpoint, queryParam], queryFn: async () => queryFn(`/${endpoint}`, queryParam?.value), - enabled + ...options }); const useApiWithCursor = < TApi extends Api, TResponse = TApi['response'] & CursorPagination, TQueryParam = TApi['queryParam']> (endpoint: string, queryFn: QueryFunctions) => - (queryParam?: Ref, enabled?: MaybeRefOrGetter) => + (queryParam?: Ref, options?: Partial, + TResponse & CursorPagination, + QueryKey, Cursor + >>) => useInfiniteQuery< TResponse & CursorPagination, ApiErrorClass, InfiniteData, @@ -108,9 +113,9 @@ const useApiWithCursor = < `/${endpoint}`, { ...queryParam?.value as TQueryParam, cursor: pageParam === '' ? undefined : pageParam } ), - initialPageParam: '', getNextPageParam: lastPage => lastPage.pages.nextCursor, - enabled + initialPageParam: '', + ...options }); export const useApiForums = () => useApi('forums', queryFunction)(); diff --git a/fe/src/components/Post/renderers/RendererTable.vue b/fe/src/components/Post/renderers/RendererTable.vue index 6a18dd4e..504b1c39 100644 --- a/fe/src/components/Post/renderers/RendererTable.vue +++ b/fe/src/components/Post/renderers/RendererTable.vue @@ -49,11 +49,12 @@