Skip to content

Commit

Permalink
* fix violation of roslyn analyzer rule RSPEC-2325 @ c#/shared
Browse files Browse the repository at this point in the history
* fix vueuse/vueuse#4216 @ utils/echarts.ts
* fix typescript-eslint/typescript-eslint#9706 @ api/index.ts
* fix violation of eslitn rule `@stylistic/indent` @ pages/posts.vue
$ git checkout 982e84b^1 src/components/post/badge/{Common,Time}.vue # to fix vuejs/language-tools#4820
@ fe
  • Loading branch information
n0099 committed Sep 19, 2024
1 parent 694976f commit 6b7ca4a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 35 deletions.
6 changes: 3 additions & 3 deletions c#/shared/src/Db/TbmDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ public class TbmDbContext<TModelCacheKeyFactory>(ILogger<TbmDbContext<TModelCach
public DbSet<ImageInReply> ImageInReplies => Set<ImageInReply>();
public DbSet<ReplyContentImage> ReplyContentImages => Set<ReplyContentImage>();

protected static void OnModelCreatingWithFid(ModelBuilder b, uint fid) =>
b.Entity<ReplyContentImage>().ToTable($"tbmc_f{fid}_reply_content_image");

[SuppressMessage("Naming", "CA1725:Parameter names should match base declaration")]
[SuppressMessage("Critical Code Smell", "S927:Parameter names should match base declaration and other partial definitions")]
[SuppressMessage("Style", "IDE0058:Expression value is never used")]
Expand Down Expand Up @@ -176,9 +179,6 @@ protected override void OnModelCreating(ModelBuilder b)
b.Entity<ReplyContentImage>().HasOne(e => e.ImageInReply).WithMany();
}

protected void OnModelCreatingWithFid(ModelBuilder b, uint fid) =>
b.Entity<ReplyContentImage>().ToTable($"tbmc_f{fid}_reply_content_image");

protected virtual void OnConfiguringNpgsql(NpgsqlDbContextOptionsBuilder builder) { }
protected virtual void OnBuildingNpgsqlDataSource(NpgsqlDataSourceBuilder builder) { }

Expand Down
6 changes: 0 additions & 6 deletions fe/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ const queryFunctionWithReCAPTCHA = async <TResponse>
export type ApiErrorClass = ApiResponseError | FetchError;
type QueryFunctions = typeof queryFunction | typeof queryFunctionWithReCAPTCHA;
const useApi = <

// https://github.com/typescript-eslint/typescript-eslint/issues/9706
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
TApi extends Api<TResponse, TQueryParam>,
TResponse = TApi['response'],
TQueryParam extends ObjUnknown = TApi['queryParam']>
Expand Down Expand Up @@ -128,9 +125,6 @@ const useApi = <
return ret;
};
const useApiWithCursor = <

// https://github.com/typescript-eslint/typescript-eslint/issues/9706
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
TApi extends Api<TResponse, TQueryParam>,
TResponse extends CursorPagination = TApi['response'],
TQueryParam extends ObjUnknown = TApi['queryParam']>
Expand Down
9 changes: 5 additions & 4 deletions fe/src/components/post/badge/Common.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import { faClock } from '@fortawesome/free-regular-svg-icons';
import { faArrowUpRightFromSquare, faHashtag, faLink } from '@fortawesome/free-solid-svg-icons';
import { DateTime } from 'luxon';
const props = defineProps<{
// https://github.com/vuejs/language-tools/issues/3267
const { post } = defineProps<{
post: TPost,
postIDKey: TPostIDKey,
postTypeText: PostTypeTextOf<TPost>
Expand All @@ -64,7 +65,7 @@ const formatTime = (time: UnixTimestamp) => {
};
const tippyContent = () => `
首次收录时间:${formatTime(props.post.createdAt)}<br>
最后更新时间:${formatTime(props.post.updatedAt ?? props.post.createdAt)}<br>
最后发现时间:${formatTime(props.post.lastSeenAt ?? props.post.updatedAt ?? props.post.createdAt)}`;
首次收录时间:${formatTime(post.createdAt)}<br>
最后更新时间:${formatTime(post.updatedAt ?? post.createdAt)}<br>
最后发现时间:${formatTime(post.lastSeenAt ?? post.updatedAt ?? post.createdAt)}`;
</script>
37 changes: 19 additions & 18 deletions fe/src/components/post/badge/Time.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@
<ClientOnly>
<PostBadgeTimeView
v-if="previousTime !== undefined && previousTime < currentTime"
@mouseenter="previousPost !== undefined
@mouseenter="() => previousPost !== undefined

Check failure on line 5 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (ubuntu-latest) / eslint

Prefer inline handler over inline function in v-on

Check failure on line 5 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (macos-latest) / eslint

Prefer inline handler over inline function in v-on

Check failure on line 5 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (windows-latest) / eslint

Prefer inline handler over inline function in v-on
&& highlightPostStore.set(previousPost, currentPostIDKey)"
@mouseleave="highlightPostStore.unset()"
@mouseleave="() => highlightPostStore.unset()"

Check failure on line 7 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (ubuntu-latest) / eslint

Prefer inline handler over inline function in v-on

Check failure on line 7 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (macos-latest) / eslint

Prefer inline handler over inline function in v-on

Check failure on line 7 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (windows-latest) / eslint

Prefer inline handler over inline function in v-on
:current="currentDateTime" :relativeTo="previousDateTime"
:relativeToText="`相对于上一${postType}${timestampType}`"
:postType="props.postType" :timestampType="timestampType" v-bind="$attrs">
:postType="postType" :timestampType="timestampType" v-bind="$attrs">
<!-- https://github.com/vuejs/language-tools/issues/4798 -->
<FontAwesome :icon="faChevronUp" class="me-1 align-bottom" />
</PostBadgeTimeView>
<PostBadgeTimeView
v-else-if="nextTime !== undefined && nextTime < currentTime"
@mouseenter="nextPost !== undefined
@mouseenter="() => nextPost !== undefined

Check failure on line 16 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (ubuntu-latest) / eslint

Prefer inline handler over inline function in v-on

Check failure on line 16 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (macos-latest) / eslint

Prefer inline handler over inline function in v-on

Check failure on line 16 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (windows-latest) / eslint

Prefer inline handler over inline function in v-on
&& highlightPostStore.set(nextPost, currentPostIDKey)"
@mouseleave="highlightPostStore.unset()"
@mouseleave="() => highlightPostStore.unset()"

Check failure on line 18 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (ubuntu-latest) / eslint

Prefer inline handler over inline function in v-on

Check failure on line 18 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (macos-latest) / eslint

Prefer inline handler over inline function in v-on

Check failure on line 18 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (windows-latest) / eslint

Prefer inline handler over inline function in v-on
:current="currentDateTime" :relativeTo="nextDateTime"
:relativeToText="`相对于下一${postType}${timestampType}`"
:postType="props.postType" :timestampType="timestampType" v-bind="$attrs">
:postType="postType" :timestampType="timestampType" v-bind="$attrs">
<FontAwesome :icon="faChevronDown" class="me-1 align-bottom" />
</PostBadgeTimeView>
<PostBadgeTimeView
v-else-if="parentTime !== undefined && parentTime !== currentTime"
@mouseenter="parentPost !== undefined
@mouseenter="() => parentPost !== undefined

Check failure on line 26 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (ubuntu-latest) / eslint

Prefer inline handler over inline function in v-on

Check failure on line 26 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (macos-latest) / eslint

Prefer inline handler over inline function in v-on

Check failure on line 26 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (windows-latest) / eslint

Prefer inline handler over inline function in v-on
&& parentPostIDKey !== undefined
&& highlightPostStore.set(parentPost, parentPostIDKey)"
@mouseleave="highlightPostStore.unset()"
@mouseleave="() => highlightPostStore.unset()"

Check failure on line 29 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (ubuntu-latest) / eslint

Prefer inline handler over inline function in v-on

Check failure on line 29 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (macos-latest) / eslint

Prefer inline handler over inline function in v-on

Check failure on line 29 in fe/src/components/post/badge/Time.vue

View workflow job for this annotation

GitHub Actions / runs-on (windows-latest) / eslint

Prefer inline handler over inline function in v-on
:current="currentDateTime" :relativeTo="parentDateTime"
:relativeToText="`相对于所属${postTypeText[postTypeText.indexOf(postType) - 1]}${timestampType}`"
:postType="props.postType" :timestampType="timestampType" v-bind="$attrs">
:postType="postType" :timestampType="timestampType" v-bind="$attrs">
<FontAwesome :icon="faAnglesUp" class="me-1 align-bottom" />
</PostBadgeTimeView>
</ClientOnly>
<PostBadgeTimeView
:current="currentDateTime" :postType="props.postType"
:current="currentDateTime" :postType="postType"
:timestampType="timestampType" class="text-end"
:class="{ 'post-badge-time-current-full': hydrationStore.isHydratingOrSSR }" v-bind="$attrs" />
</template>
Expand All @@ -54,7 +54,7 @@ import { faAnglesUp, faChevronDown, faChevronUp } from '@fortawesome/free-solid-
import { DateTime } from 'luxon';
defineOptions({ inheritAttrs: false });
const props = defineProps<{
const { previousPost, nextPost, currentPost, parentPost, postTimeKey } = defineProps<{
previousPost?: TPost,
nextPost?: TPost,
currentPost: TPost,
Expand All @@ -69,21 +69,22 @@ const props = defineProps<{
const highlightPostStore = useHighlightPostStore();
const hydrationStore = useHydrationStore();
useNoScript(`<style>
const noScriptStyle = `<style>
.post-badge-time-current-full {
width: auto !important;
}
</style>`);
</style>`; // https://github.com/nuxt/nuxt/issues/13848
useHead({ noscript: [{ innerHTML: noScriptStyle }] });
// https://github.com/typescript-eslint/typescript-eslint/issues/9723
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents, @typescript-eslint/no-unnecessary-type-parameters
const getPostTime = <T extends TPost | TParentPost>(post?: T) =>
post?.[props.postTimeKey as keyof T] as TPostTimeValue | undefined;
const previousTime = computed(() => getPostTime(props.previousPost));
const nextTime = computed(() => getPostTime(props.nextPost));
const parentTime = computed(() => getPostTime(props.parentPost));
post?.[postTimeKey as keyof T] as TPostTimeValue | undefined;
const previousTime = computed(() => getPostTime(previousPost));
const nextTime = computed(() => getPostTime(nextPost));
const parentTime = computed(() => getPostTime(parentPost));
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const currentTime = computed(() => getPostTime(props.currentPost)!);
const currentTime = computed(() => getPostTime(currentPost)!);
const previousDateTime = computed(() =>
undefinedOr(previousTime.value, i => DateTime.fromSeconds(i)));
Expand Down
4 changes: 2 additions & 2 deletions fe/src/pages/posts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ watch([dataUpdatedAt, errorUpdatedAt], async (updatedAt: UnixTimestamp[]) => {
const postCount = _.sum(Object.values(fetchedPage?.pages.matchQueryPostCount ?? {}));
notyShow('success', `已加载${postCount}条记录
${isQueryCached
? '使用前端本地缓存'
: `
? '使用前端本地缓存'
: `
前端耗时${_.round(renderDuration / 1000, 2)}s
${isQueriedBySSR ? '使用服务端渲染预请求' : ''}
后端+网络耗时${_.round(networkDuration / 1000, 2)}s`}`);
Expand Down
4 changes: 2 additions & 2 deletions fe/src/utils/echarts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as echarts from 'echarts/core';
import type { ColorPaletteOptionMixin } from 'echarts/types/src/util/types.d.ts';

export const useResizeableEcharts = (el: Parameters<typeof useResizeObserver>[0]) =>
useResizeObserver(el, _.debounce((entries: Parameters<Parameters<typeof useResizeObserver>[1]>[0]) => { // https://github.com/vueuse/vueuse/issues/4216
entries.forEach(entry => {
useResizeObserver(el, _.debounce((entries: ResizeObserverEntry) => {
entries.forEach(entry => {
echarts.getInstanceByDom(entry.target as HTMLElement)?.resize();
});
}, 1000));
Expand Down

0 comments on commit 6b7ca4a

Please sign in to comment.