feat: optional types

This commit is contained in:
DIYgod 2024-05-14 13:09:57 +08:00
parent 2d30d7100b
commit 95718d6324
No known key found for this signature in database
4 changed files with 22 additions and 18 deletions

View File

@ -6,32 +6,34 @@ export function FollowSummary({
feed,
docs,
}: {
feed: Partial<FeedResponse>
feed: FeedResponse
docs?: string
}) {
return (
<div className="select-text text-sm space-y-1">
<div className="select-text text-sm space-y-1 max-w-[462px]">
<a href={feed.siteUrl} target="_blank" className="flex items-center">
{(() => {
if (feed.image) {
return <Image src={feed.image} className="w-8 h-8 mr-2" />
return <Image src={feed.image} className="w-8 h-8 mr-2 shrink-0" />
} else if (feed.siteUrl) {
return <SiteIcon url={feed.siteUrl} className="w-8 h-8" />
return <SiteIcon url={feed.siteUrl} className="w-8 h-8 shrink-0" />
} else if (docs) {
return <SiteIcon url="https://rsshub.app" className="w-8 h-8" />
return (
<SiteIcon url="https://rsshub.app" className="w-8 h-8 shrink-0" />
)
} else {
return null
}
})()}
<div className="leading-tight font-semibold text-base">
<div className="leading-tight font-semibold text-base truncate">
{feed.title}
<div className="font-normal truncate text-xs text-zinc-500">
{feed.description}
</div>
</div>
</a>
<div className="text-zinc-500 flex items-center gap-1">
<i className="i-mingcute-right-line" />
<div className="text-zinc-500 flex items-center gap-1 truncate">
<i className="i-mingcute-right-line shrink-0" />
{feed.url || docs}
</div>
</div>

View File

@ -63,7 +63,7 @@ export function FollowForm({ type }: { type: string }) {
mutationFn: async (keyword: string) => {
const { data } = await apiFetch<{
data: {
feed: Partial<FeedResponse>
feed: FeedResponse
docs?: string
entries?: Partial<EntriesResponse>
isSubscribed?: boolean

View File

@ -5,13 +5,15 @@ export function SiteIcon({
url,
className,
}: {
url: string
url?: string
className?: string
}) {
let host
let src
let fallback
if (!url) return null
try {
host = new URL(url).host
const pureDomain = parse(host).domainWithoutSuffix

View File

@ -9,14 +9,14 @@ export type ActivedList = {
export type FeedResponse = {
id: string
url: string
title: string
description: string
siteUrl: string
image: string
title?: string
description?: string
siteUrl?: string
image?: string
checkedAt: string
nextCheckAt: string
lastModifiedHeader: string
etagHeader: string
lastModifiedHeader?: string
etagHeader?: string
ttl: number
}
@ -24,8 +24,8 @@ export type SubscriptionResponse = {
userId: string
feedId: string
view: number
category: string
title: string
category?: string
title?: string
unread?: number
feeds: FeedResponse
}[]