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 { i18n } from "@/i18n";
import icon from "@/scripts/icon";
import type { entities } from "firefish-js";
const props = withDefaults(
defineProps<{
channel: Record<string, any>;
channel: entities.Channel;
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);
async function onClick() {

View file

@ -11,7 +11,7 @@
</div>
</template>
<template #default="{ items }">
<template #default="{ items }: { items: entities.Channel[] }">
<MkChannelPreview
v-for="item in items"
:key="item.id"
@ -29,14 +29,15 @@ import MkPagination from "@/components/MkPagination.vue";
import { i18n } from "@/i18n";
import type { entities } from "firefish-js";
const props = withDefaults(
withDefaults(
defineProps<{
pagination: PagingOf<entities.Channel>;
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>

View file

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

View file

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

View file

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

View file

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

View file

@ -125,6 +125,7 @@ import { defaultStore } from "@/store";
import icon from "@/scripts/icon";
import "swiper/scss";
import "swiper/scss/virtual";
import type { Swiper as SwiperType } from "swiper/types";
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;
syncSlide(tabs.indexOf(tab.value));
}
function onSlideChange() {
tab.value = tabs[swiperRef.activeIndex];
tab.value = tabs[swiperRef!.activeIndex];
}
function syncSlide(index) {
swiperRef.slideTo(index);
function syncSlide(index: number) {
swiperRef!.slideTo(index);
}
</script>

View file

@ -218,16 +218,31 @@ export type Endpoints = {
};
// channels
"channels/create": { req: TODO; res: TODO };
"channels/featured": { req: TODO; res: TODO };
"channels/create": {
req: {
name: string;
description?: string;
bannerId: DriveFile["id"] | null;
};
res: Channel;
};
"channels/featured": { req: TODO; res: Channel[] };
"channels/follow": { req: TODO; res: TODO };
"channels/followed": { req: TODO; res: TODO };
"channels/owned": { req: TODO; res: TODO };
"channels/followed": { req: TODO; res: Channel[] };
"channels/owned": { req: TODO; res: Channel[] };
"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/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/active-users": {

View file

@ -471,8 +471,17 @@ export type FollowRequest = {
export type Channel = {
id: ID;
createdAt: DateString;
lastNotedAt: DateString | null;
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 = {