Skip to content

Commit

Permalink
fix: target model types errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Sep 20, 2024
1 parent 65fa3ad commit 6e150a2
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const safeUrl = (url: string, baseUrl: string) => {
export const MarkdownLink = (props: LinkProps) => {
const { view, feedId } = useEntryContentContext()

const feedSiteUrl = useFeedByIdSelector(feedId, (feed) => feed?.siteUrl)
const feedSiteUrl = useFeedByIdSelector(feedId, (feed) =>
"siteUrl" in feed ? feed.siteUrl : undefined,
)

const populatedFullHref = useMemo(() => {
const { href } = props
Expand Down
6 changes: 4 additions & 2 deletions apps/renderer/src/hooks/biz/useFeedActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const useFeedActions = ({
click: () => {
const feed = getFeedById(feedId)
if (feed) {
feed.siteUrl && window.open(feed.siteUrl, "_blank")
"siteUrl" in feed && feed.siteUrl && window.open(feed.siteUrl, "_blank")
}
},
},
Expand All @@ -132,7 +132,9 @@ export const useFeedActions = ({
label: t("sidebar.feed_actions.copy_feed_url"),
disabled: isEntryList,
shortcut: "Meta+C",
click: () => navigator.clipboard.writeText(feed.url),
click: () => {
"url" in feed && navigator.clipboard.writeText(feed.url)
},
},
{
type: "text" as const,
Expand Down
3 changes: 2 additions & 1 deletion apps/renderer/src/hooks/biz/useSubscriptionActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export const useDeleteSubscription = ({ onSuccess }: { onSuccess?: () => void })
// TODO store action
await apiClient.subscriptions.$post({
json: {
url: feed.url,
url: feed.type === "feed" ? feed.url : undefined,
listId: feed.type === "list" ? feed.id : undefined,
view: subscription.view,
category: subscription.category,
isPrivate: subscription.isPrivate,
Expand Down
3 changes: 2 additions & 1 deletion apps/renderer/src/modules/claim/feed-claim-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { LoadingCircle } from "~/components/ui/loading"
import { useCurrentModal } from "~/components/ui/modal"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "~/components/ui/tabs"
import { useAuthQuery } from "~/hooks/common"
import type { FeedModel } from "~/models"
import { Queries } from "~/queries"
import { useClaimFeedMutation } from "~/queries/feed"
import { useFeedById } from "~/store/feed"
Expand All @@ -20,7 +21,7 @@ export const FeedClaimModalContent: FC<{
feedId: string
}> = ({ feedId }) => {
const { t } = useTranslation()
const feed = useFeedById(feedId)
const feed = useFeedById(feedId) as FeedModel
const {
data: claimMessage,
isLoading,
Expand Down
4 changes: 2 additions & 2 deletions apps/renderer/src/modules/discover/feed-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { FeedViewType } from "~/lib/enum"
import { getFetchErrorMessage, toastFetchError } from "~/lib/error-parser"
import { getNewIssueUrl } from "~/lib/issues"
import { cn } from "~/lib/utils"
import type { FeedModel } from "~/models"
import { feed as feedQuery, useFeed } from "~/queries/feed"
import { subscription as subscriptionQuery } from "~/queries/subscriptions"
import { useFeedByIdOrUrl } from "~/store/feed"
Expand Down Expand Up @@ -164,7 +165,7 @@ const FeedInnerForm = ({
const subscription = useSubscriptionByFeedId(id || "")
const buttonRef = useRef<HTMLButtonElement>(null)
const isSubscribed = !!subscription
const feed = useFeedByIdOrUrl({ id, url })!
const feed = useFeedByIdOrUrl({ id, url })! as FeedModel

const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
Expand Down Expand Up @@ -199,7 +200,6 @@ const FeedInnerForm = ({
const $method = isSubscribed ? apiClient.subscriptions.$patch : apiClient.subscriptions.$post

return $method({
// @ts-expect-error
json: body,
})
},
Expand Down
3 changes: 1 addition & 2 deletions apps/renderer/src/modules/discover/import.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Input } from "~/components/ui/input"
import { apiFetch } from "~/lib/api-fetch"
import { toastFetchError } from "~/lib/error-parser"
import { cn } from "~/lib/utils"
import type { FeedResponse } from "~/models"
import { Queries } from "~/queries"

import { FollowSummary } from "../../components/feed-summary"
Expand Down Expand Up @@ -171,7 +170,7 @@ export function DiscoverImport() {
{!mutation.data?.[item.key].length && (
<div className="text-zinc-500">No items</div>
)}
{mutation.data?.[item.key].map((feed: FeedResponse) => (
{mutation.data?.[item.key].map((feed) => (
<FollowSummary className="max-w-[462px]" key={feed.id} feed={feed} />
))}
</div>
Expand Down
4 changes: 2 additions & 2 deletions apps/renderer/src/modules/entry-content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { stopPropagation } from "~/lib/dom"
import { FeedViewType } from "~/lib/enum"
import { getNewIssueUrl } from "~/lib/issues"
import { cn } from "~/lib/utils"
import type { ActiveEntryId } from "~/models"
import type { ActiveEntryId, FeedModel } from "~/models"
import {
useIsSoFWrappedElement,
useWrappedElement,
Expand Down Expand Up @@ -97,7 +97,7 @@ export const EntryContentRender: Component<{ entryId: string }> = ({ entryId, cl
const entry = useEntry(entryId)
useTitle(entry?.entries.title)

const feed = useFeedById(entry?.feedId)
const feed = useFeedById(entry?.feedId) as FeedModel

const entryHistory = useEntryReadHistory(entryId)

Expand Down
8 changes: 4 additions & 4 deletions apps/renderer/src/modules/feed-column/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const FeedItemImpl = ({ view, feedId, className, showUnreadCount = true }: FeedI
onContextMenu={(e) => {
setIsContextMenuOpen(true)
const nextItems = items.concat()
if (feed.errorAt && feed.errorMessage) {
if (feed.type === "feed" && feed.errorAt && feed.errorMessage) {
nextItems.push(
{
type: "separator",
Expand Down Expand Up @@ -109,7 +109,7 @@ const FeedItemImpl = ({ view, feedId, className, showUnreadCount = true }: FeedI
<div
className={cn(
"flex min-w-0 items-center",
feed.errorAt && "text-red-900 dark:text-red-500",
feed.type === "feed" && feed.errorAt && "text-red-900 dark:text-red-500",
)}
>
<FeedIcon fallback feed={feed} size={16} />
Expand All @@ -121,8 +121,8 @@ const FeedItemImpl = ({ view, feedId, className, showUnreadCount = true }: FeedI
>
{getPreferredTitle(feed)}
</div>
<FeedCertification feed={feed} className="text-[15px]" />
{feed.errorAt && (
{feed.type === "feed" && <FeedCertification feed={feed} className="text-[15px]" />}
{feed.type === "feed" && feed.errorAt && (
<Tooltip delayDuration={300}>
<TooltipTrigger asChild>
<i className="i-mgc-wifi-off-cute-re ml-1 shrink-0 text-base" />
Expand Down
4 changes: 2 additions & 2 deletions apps/renderer/src/modules/panel/cmdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const SearchCmdK: React.FC = () => {
feedId={entry.feedId}
entryId={entry.item.id}
id={entry.item.id}
icon={feed?.siteUrl}
icon={feed?.type === "feed" ? feed?.siteUrl : undefined}
subtitle={feed?.title}
/>
)
Expand All @@ -197,7 +197,7 @@ export const SearchCmdK: React.FC = () => {
feedId={feed.item.id!}
entryId={ROUTE_ENTRY_PENDING}
id={feed.item.id!}
icon={feed.item.siteUrl}
icon={feed.item.type === "feed" ? feed.item.siteUrl : undefined}
subtitle={useFeedUnreadStore.getState().data[feed.item.id!]?.toString()}
/>
))}
Expand Down
2 changes: 1 addition & 1 deletion apps/renderer/src/modules/profile/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useUserSubscriptionsQuery = (userId: string | undefined) => {
const groupFolder = {} as Record<string, typeof res.data>

for (const subscription of res.data || []) {
if (!subscription.category && subscription.feeds) {
if (!subscription.category && "feeds" in subscription) {
const { siteUrl } = subscription.feeds
if (!siteUrl) continue
const parsed = parse(siteUrl)
Expand Down
1 change: 1 addition & 0 deletions apps/renderer/src/modules/profile/user-profile-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ const SubscriptionItem: FC<{
const isFollowed = !!useSubscriptionStore((state) => state.data[subscription.feedId])
const { present } = useModalStack()
const isLoose = variant === "loose"
if (!("feeds" in subscription)) return null
return (
<div
className={cn("group relative", isLoose ? "border-b py-5" : "py-2")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,50 +63,53 @@ export function Component() {
<h3>{category}</h3>
</div>
<div>
{subscriptions.data?.[category].map((subscription) => (
<div key={subscription.feedId} className="group relative border-b py-5">
<a
className="flex flex-1 cursor-default"
href={`/feed/${subscription.feedId}`}
target="_blank"
>
<FeedIcon fallback feed={subscription.feeds} size={22} className="mr-3" />
<div
className={cn(
"flex w-0 flex-1 grow flex-col justify-center",
"group-hover:grow-[0.85]",
)}
>
<div className="truncate font-medium leading-none">
{subscription.feeds?.title}
</div>
{subscription.feeds?.description && (
<div className="mt-1 line-clamp-1 text-xs text-zinc-500">
{subscription.feeds.description}
{subscriptions.data?.[category].map(
(subscription) =>
"feeds" in subscription && (
<div key={subscription.feedId} className="group relative border-b py-5">
<a
className="flex flex-1 cursor-default"
href={`/feed/${subscription.feedId}`}
target="_blank"
>
<FeedIcon fallback feed={subscription.feeds} size={22} className="mr-3" />
<div
className={cn(
"flex w-0 flex-1 grow flex-col justify-center",
"group-hover:grow-[0.85]",
)}
>
<div className="truncate font-medium leading-none">
{subscription.feeds?.title}
</div>
{subscription.feeds?.description && (
<div className="mt-1 line-clamp-1 text-xs text-zinc-500">
{subscription.feeds.description}
</div>
)}
</div>
)}
</div>
</a>
<span className="center absolute inset-y-0 right-0 opacity-0 transition-opacity group-hover:opacity-100">
<Button
onClick={(e) => {
e.stopPropagation()
</a>
<span className="center absolute inset-y-0 right-0 opacity-0 transition-opacity group-hover:opacity-100">
<Button
onClick={(e) => {
e.stopPropagation()

presentFeedFormModal(subscription.feedId)
}}
>
{isMe ? (
t.common("words.edit")
) : (
<>
<FollowIcon className="mr-1 size-3" />
{APP_NAME}
</>
)}
</Button>
</span>
</div>
))}
presentFeedFormModal(subscription.feedId)
}}
>
{isMe ? (
t.common("words.edit")
) : (
<>
<FollowIcon className="mr-1 size-3" />
{APP_NAME}
</>
)}
</Button>
</span>
</div>
),
)}
</div>
</div>
))
Expand Down
2 changes: 1 addition & 1 deletion apps/renderer/src/store/feed/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useFeedByIdOrUrl = (feed: FeedQueryParams) =>
return state.feeds[feed.id]
}
if (feed.url) {
return Object.values(state.feeds).find((f) => f.url === feed.url) || null
return Object.values(state.feeds).find((f) => f.type === "feed" && f.url === feed.url) || null
}
return null
})
Expand Down
8 changes: 6 additions & 2 deletions apps/renderer/src/store/feed/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ class FeedActions {
set((state) =>
produce(state, (state) => {
for (const feed of feeds) {
if (feed.errorAt && new Date(feed.errorAt).getTime() > Date.now() - 1000 * 60 * 60 * 9) {
if (
feed.type === "feed" &&
feed.errorAt &&
new Date(feed.errorAt).getTime() > Date.now() - 1000 * 60 * 60 * 9
) {
feed.errorAt = null
}
if (feed.id) {
if (feed.owner) {
userActions.upsert(feed.owner as UserModel)
}
if (feed.tipUsers) {
if (feed.type === "feed" && feed.tipUsers) {
userActions.upsert(feed.tipUsers)
}

Expand Down
1 change: 1 addition & 0 deletions apps/renderer/src/store/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class SearchActions {
const feedsMap = new Map(feeds.map((feed) => [feed.id, feed]))

const entriesFuse = this.createFuse(entries, ["title", "content", "description", "id"])
// @ts-expect-error
const feedsFuse = this.createFuse(feeds, ["title", "description", "id", "siteUrl", "url"])
const subscriptionsFuse = this.createFuse(subscriptions, ["title", "category"])

Expand Down
4 changes: 2 additions & 2 deletions apps/renderer/src/store/subscription/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function morphResponseData(data: SubscriptionModel[]): SubscriptionFlatModel[] {
const result: SubscriptionFlatModel[] = []
for (const subscription of data) {
const cloned: SubscriptionFlatModel = { ...subscription }
if (!subscription.category && subscription.feeds) {
if (!subscription.category && "feeds" in subscription && subscription.feeds) {
const { siteUrl } = subscription.feeds
if (!siteUrl) {
cloned.defaultCategory = subscription.feedId
Expand Down Expand Up @@ -202,7 +202,7 @@ class SubscriptionActions {
if (idSet.has(id)) {
const subscription = state.data[id]
const feed = getFeedById(subscription.feedId)
if (!feed) return
if (!feed || feed.type !== "feed") return
const { siteUrl } = feed
if (!siteUrl) return
const parsed = parse(siteUrl)
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3412,9 +3412,9 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
input: {
json: {
view: number;
url: string;
title?: string | null | undefined;
category?: string | null | undefined;
url?: string | undefined;
isPrivate?: boolean | undefined;
listId?: string | undefined;
};
Expand Down

0 comments on commit 6e150a2

Please sign in to comment.