fix type errors of channel

This commit is contained in:
Lhcfl 2024-04-10 22:25:11 +08:00
parent f7f7959ba6
commit 17a945b8b1
9 changed files with 56 additions and 26 deletions

View File

@ -27,10 +27,11 @@ import { ref } from "vue";
import * as os from "@/os"; import * as os from "@/os";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
import type { entities } from "firefish-js";
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
channel: Record<string, any>; channel: entities.Channel;
full?: boolean; full?: boolean;
}>(), }>(),
{ {
@ -38,7 +39,7 @@ const props = withDefaults(
}, },
); );
const isFollowing = ref<boolean>(props.channel.isFollowing); const isFollowing = ref<boolean>(props.channel.isFollowing ?? false);
const wait = ref(false); const wait = ref(false);
async function onClick() { async function onClick() {

View File

@ -11,7 +11,7 @@
</div> </div>
</template> </template>
<template #default="{ items }"> <template #default="{ items }: { items: entities.Channel[] }">
<MkChannelPreview <MkChannelPreview
v-for="item in items" v-for="item in items"
:key="item.id" :key="item.id"
@ -29,14 +29,15 @@ import MkPagination from "@/components/MkPagination.vue";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import type { entities } from "firefish-js"; import type { entities } from "firefish-js";
const props = withDefaults( withDefaults(
defineProps<{ defineProps<{
pagination: PagingOf<entities.Channel>; pagination: PagingOf<entities.Channel>;
noGap?: boolean; noGap?: boolean;
extractor?: (item: any) => any; // TODO: this function is not used and may can be removed
extractor?: (item: entities.Channel) => entities.Channel;
}>(), }>(),
{ {
extractor: (item) => item, extractor: (item: entities.Channel) => item,
}, },
); );
</script> </script>

View File

@ -54,9 +54,10 @@
import { computed } from "vue"; import { computed } from "vue";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
import type { entities } from "firefish-js";
const props = defineProps<{ const props = defineProps<{
channel: Record<string, any>; channel: entities.Channel;
}>(); }>();
const bannerStyle = computed(() => { const bannerStyle = computed(() => {

View File

@ -354,7 +354,7 @@ const props = withDefaults(
defineProps<{ defineProps<{
reply?: entities.Note; reply?: entities.Note;
renote?: entities.Note; renote?: entities.Note;
channel?: any; // TODO channel?: entities.Channel;
mention?: entities.User; mention?: entities.User;
specified?: entities.User; specified?: entities.User;
initialText?: string; initialText?: string;

View File

@ -28,7 +28,7 @@ import MkPostForm from "@/components/MkPostForm.vue";
const props = defineProps<{ const props = defineProps<{
reply?: entities.Note; reply?: entities.Note;
renote?: entities.Note; renote?: entities.Note;
channel?: any; // TODO channel?: entities.Channel;
mention?: entities.User; mention?: entities.User;
specified?: entities.User; specified?: entities.User;
initialText?: string; initialText?: string;

View File

@ -33,7 +33,7 @@
:style="{ :style="{
backgroundImage: channel.bannerUrl backgroundImage: channel.bannerUrl
? `url(${channel.bannerUrl})` ? `url(${channel.bannerUrl})`
: null, : undefined,
}" }"
class="banner" class="banner"
> >
@ -88,8 +88,6 @@
class="_gap" class="_gap"
src="channel" src="channel"
:channel="channelId" :channel="channelId"
@before="before"
@after="after"
/> />
</div> </div>
</MkSpacer> </MkSpacer>
@ -107,6 +105,7 @@ import { me } from "@/me";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
import type { entities } from "firefish-js";
const router = useRouter(); const router = useRouter();
@ -114,7 +113,11 @@ const props = defineProps<{
channelId: string; channelId: string;
}>(); }>();
const channel = ref(null); const channel = ref<entities.Channel>(
await os.api("channels/show", {
channelId: props.channelId,
}),
);
const showBanner = ref(true); const showBanner = ref(true);
watch( watch(
@ -124,7 +127,6 @@ watch(
channelId: props.channelId, channelId: props.channelId,
}); });
}, },
{ immediate: true },
); );
function edit() { function edit() {

View File

@ -125,6 +125,7 @@ import { defaultStore } from "@/store";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
import "swiper/scss"; import "swiper/scss";
import "swiper/scss/virtual"; import "swiper/scss/virtual";
import type { Swiper as SwiperType } from "swiper/types";
const router = useRouter(); const router = useRouter();
@ -216,18 +217,18 @@ definePageMetadata(
})), })),
); );
let swiperRef = null; let swiperRef: SwiperType | null = null;
function setSwiperRef(swiper) { function setSwiperRef(swiper: SwiperType) {
swiperRef = swiper; swiperRef = swiper;
syncSlide(tabs.indexOf(tab.value)); syncSlide(tabs.indexOf(tab.value));
} }
function onSlideChange() { function onSlideChange() {
tab.value = tabs[swiperRef.activeIndex]; tab.value = tabs[swiperRef!.activeIndex];
} }
function syncSlide(index) { function syncSlide(index: number) {
swiperRef.slideTo(index); swiperRef!.slideTo(index);
} }
</script> </script>

View File

@ -218,16 +218,31 @@ export type Endpoints = {
}; };
// channels // channels
"channels/create": { req: TODO; res: TODO }; "channels/create": {
"channels/featured": { req: TODO; res: TODO }; req: {
name: string;
description?: string;
bannerId: DriveFile["id"] | null;
};
res: Channel;
};
"channels/featured": { req: TODO; res: Channel[] };
"channels/follow": { req: TODO; res: TODO }; "channels/follow": { req: TODO; res: TODO };
"channels/followed": { req: TODO; res: TODO }; "channels/followed": { req: TODO; res: Channel[] };
"channels/owned": { req: TODO; res: TODO }; "channels/owned": { req: TODO; res: Channel[] };
"channels/pin-note": { req: TODO; res: TODO }; "channels/pin-note": { req: TODO; res: TODO };
"channels/show": { req: TODO; res: TODO }; "channels/show": { req: TODO; res: Channel };
"channels/timeline": { req: TODO; res: Note[] }; "channels/timeline": { req: TODO; res: Note[] };
"channels/unfollow": { req: TODO; res: TODO }; "channels/unfollow": { req: TODO; res: TODO };
"channels/update": { req: TODO; res: TODO }; "channels/update": {
req: {
channelId: Channel["id"];
name: string;
description?: string;
bannerId: DriveFile["id"] | null;
};
res: Channel;
};
// charts // charts
"charts/active-users": { "charts/active-users": {

View File

@ -471,8 +471,17 @@ export type FollowRequest = {
export type Channel = { export type Channel = {
id: ID; id: ID;
createdAt: DateString;
lastNotedAt: DateString | null;
name: string; name: string;
// TODO description: string | null;
bannerId: DriveFile["id"];
bannerUrl: string | null;
notesCount: number;
usersCount: number;
isFollowing?: boolean;
userId: User["id"] | null;
hasUnreadNote?: boolean;
}; };
export type Following = { export type Following = {