Skip to content

Commit

Permalink
* move the type of prop postTypeID to generic TPostIDKey and rena…
Browse files Browse the repository at this point in the history
…me it to `postIDKey` @ `badges/<PostCommonMetadataIconLinks>`

* replace literal `string[]` of known post types with `postType@shared/index.ts` @ queryForm/queryParams.ts
@ components/Post

* add an option `always-multiline` for rule `vue/multiline-ternary` to sync with `@stylistic/multiline-ternary` since 9e39229 @ .eslintrc.cjs
@ fe
  • Loading branch information
n0099 committed Mar 14, 2024
1 parent 79c9887 commit 73e594a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion fe/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ const eslintPluginVue = { // as of [email protected]
'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',
'vue/multiline-ternary': ['error', 'always-multiline'],
'vue/array-element-newline': ['error', 'consistent'],
'vue/prefer-define-options': 'error',
'vue/valid-define-options': 'error',
Expand Down
13 changes: 8 additions & 5 deletions fe/src/components/Post/badges/PostCommonMetadataIconLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
target="_blank" class="badge bg-light rounded-pill link-dark">
<FontAwesomeIcon icon="link" size="lg" class="align-bottom" />
</a>
<a :data-tippy-content="`<h6>${postTypeID}${props.post[props.postTypeID]}</h6><hr />
<a :data-tippy-content="`<h6>${postIDKey}${props.post[props.postIDKey]}</h6><hr />
首次收录时间:${formatTime(props.post.createdAt)}<br />
最后更新时间:${formatTime(props.post.updatedAt ?? props.post.createdAt)}<br />
最后发现时间:${formatTime(props.post.lastSeenAt ?? props.post.updatedAt ?? props.post.createdAt)}`"
Expand All @@ -14,17 +14,20 @@
</a>
</template>
<script setup lang="ts" generic="T extends Reply | SubReply | Thread">
<script setup lang="ts" generic="
TPost extends Reply | SubReply | Thread,
TPostIDKey extends keyof TPost
& (TPost extends Thread ? 'tid' : TPost extends Reply ? 'pid' : TPost extends SubReply ? 'spid' : never)">
import type { Reply, SubReply, Thread } from '@/api/post';
import type { PostID, UnixTimestamp } from '@/shared';
import type { UnixTimestamp } from '@/shared';
import { tiebaPostLink } from '@/shared';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { DateTime } from 'luxon';
// https://github.com/vuejs/language-tools/issues/3267
const props = defineProps<{
post: T,
postTypeID: keyof T & PostID & (T extends Thread ? 'tid' : T extends Reply ? 'pid' : T extends SubReply ? 'spid' : '')
post: TPost,
postIDKey: TPostIDKey
}>();
const formatTime = (time: UnixTimestamp) => {
const dateTime = DateTime.fromSeconds(time);
Expand Down
4 changes: 2 additions & 2 deletions fe/src/components/Post/queryForm/queryParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { NamelessUnknownParam, ParamPreprocessorOrWatcher, UnknownParam } f
import useQueryForm from './useQueryForm';
import type { ForumModeratorType } from '@/api/user';
import type { DeepWritable, Fid, ObjEmpty, PostID, PostType } from '@/shared';
import { boolStrToBool } from '@/shared';
import { boolStrToBool, postType } from '@/shared';
import * as _ from 'lodash-es';

// value of [0] will be either ALL: require exactly same post types, or SUB: requiring a subset of types
Expand Down Expand Up @@ -132,7 +132,7 @@ const paramsMetadataKeyByType: { [P in 'array' | 'dateTimeRange' | 'numeric' | '
};
const paramsDefaultValue = {
fid: { value: 0, subParam: {} },
postTypes: { value: ['thread', 'reply', 'subReply'], subParam: {} },
postTypes: { value: postType, subParam: {} },
orderBy: { value: 'default', subParam: { direction: 'default' } },
threadProperties: { value: [] },
authorManagerType: { value: 'NULL' },
Expand Down
4 changes: 1 addition & 3 deletions fe/src/components/Post/renderers/RendererTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
</template>
<template #expandedRowRender="{ record: { pid, content, authorUid: replyAuthorUid } }">
<!-- eslint-disable vue/no-v-text-v-html-on-component -->
<component :is="subRepliesKeyByPid[pid] === undefined
? 'span'
: 'p'"
<component :is="subRepliesKeyByPid[pid] === undefined ? 'span' : 'p'"
v-viewer.static v-html="content" />

Check warning on line 54 in fe/src/components/Post/renderers/RendererTable.vue

View workflow job for this annotation

GitHub Actions / eslint

'v-html' directive can lead to XSS attack
<!-- eslint-enable vue/no-v-text-v-html-on-component -->
<Table v-if="subRepliesKeyByPid[pid] !== undefined"
Expand Down
2 changes: 1 addition & 1 deletion fe/src/components/Post/renderers/list/ReplyItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="float-end badge bg-light fs-6 p-1 pe-2" role="group">
<RouterLink :to="{ name: 'post/pid', params: { pid: reply.pid } }"
class="badge bg-light rounded-pill link-dark">只看此楼</RouterLink>
<PostCommonMetadataIconLinks :post="reply" postTypeID="pid" />
<PostCommonMetadataIconLinks :post="reply" postIDKey="pid" />
<BadgePostTime postType="回复贴" :parentPost="thread"
:previousPost="previousReply" :currentPost="reply" :nextPost="nextReply"
postTimeKey="postedAt" timestampType="发帖时间" class="bg-primary" />
Expand Down
2 changes: 1 addition & 1 deletion fe/src/components/Post/renderers/list/SubReplyGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</RouterLink>
<div class="float-end badge bg-light fs-6 p-1 pe-2" role="group">
<div class="d-inline" :class="{ invisible: hoveringSubReplyID !== subReply.spid }">
<PostCommonMetadataIconLinks :post="subReply" postTypeID="spid" />
<PostCommonMetadataIconLinks :post="subReply" postIDKey="spid" />
</div>
<BadgePostTime postType="楼中楼" :parentPost="reply" :currentPost="subReply"
:previousTimeOverride="getSiblingPostedAt(subReplyGroupIndex, 'previous')"
Expand Down
2 changes: 1 addition & 1 deletion fe/src/components/Post/renderers/list/ThreadItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="col-auto badge bg-light fs-6 p-1 pt-0 pe-2" role="group">
<RouterLink :to="{ name: 'post/tid', params: { tid: thread.tid } }"
class="badge bg-light rounded-pill link-dark">只看此帖</RouterLink>
<PostCommonMetadataIconLinks :post="thread" postTypeID="tid" />
<PostCommonMetadataIconLinks :post="thread" postIDKey="tid" />
<BadgePostTime postType="主题帖" :previousPost="previousThread" :currentPost="thread" :nextPost="nextThread"
postTimeKey="postedAt" timestampType="发帖时间" class="bg-success" />
</div>
Expand Down

0 comments on commit 73e594a

Please sign in to comment.