Skip to content

Commit

Permalink
fix: add rsshub discover error boundary
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Oct 31, 2024
1 parent b1c5d84 commit 665c009
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 15 deletions.
31 changes: 31 additions & 0 deletions apps/renderer/src/components/errors/RSSHubError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { FC } from "react"

import { attachOpenInEditor } from "~/lib/dev"

import type { AppErrorFallbackProps } from "../common/AppErrorBoundary"
import { FeedbackIssue } from "../common/ErrorElement"
import { parseError } from "./helper"

const RSSHubErrorFallback: FC<AppErrorFallbackProps> = (props) => {
const { message, stack } = parseError(props.error)

return (
<div className="flex flex-col items-center justify-center">
<div className="m-auto max-w-prose text-center">
<p className="center my-3 gap-2 font-bold">
<i className="i-mgc-bug-cute-re text-red-500" />
RSSHub has a temporary problem, please contact the our team.
</p>
<div className="text-lg">{message}</div>
{import.meta.env.DEV && stack ? (
<pre className="mt-4 max-h-48 cursor-text overflow-auto whitespace-pre-line rounded-md bg-red-50 p-4 text-left font-mono text-sm text-red-600">
{attachOpenInEditor(stack)}
</pre>
) : null}

<FeedbackIssue message={message!} stack={stack} />
</div>
</div>
)
}
export default RSSHubErrorFallback
2 changes: 2 additions & 0 deletions apps/renderer/src/components/errors/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export enum ErrorComponentType {
// Feed
FeedFoundCanBeFollow = "FeedFoundCanBeFollow",
FeedNotFound = "FeedNotFound",
// Section
RSSHubDiscoverError = "RSSHubDiscoverError",
}
1 change: 1 addition & 0 deletions apps/renderer/src/components/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const ErrorFallbackMap = {
() => import("./FeedFoundCanBeFollowErrorFallback"),
),
[ErrorComponentType.FeedNotFound]: lazy(() => import("./FeedNotFound")),
[ErrorComponentType.RSSHubDiscoverError]: lazy(() => import("./RSSHubError")),
}

export const getErrorFallback = (type: ErrorComponentType) => ErrorFallbackMap[type]
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function GuideModalContent({ onClose }: { onClose: () => void }) {
{
title: t.app("new_user_guide.step.shortcuts.title"),
content: (
<div className="w-[400px] space-y-2">
<div className="space-y-2">
<p>{t.app("new_user_guide.step.shortcuts.description1")}</p>
<p>
<Trans
Expand Down
6 changes: 6 additions & 0 deletions apps/renderer/src/modules/new-user-guide/steps/behavior.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,22 @@ export function BehaviorGuide() {
wrapperClassName="border rounded-lg p-3 has-[:checked]:bg-theme-accent has-[:checked]:text-white transition-colors"
label={t("new_user_guide.step.behavior.unread_question.option1")}
value="radical"
className="hidden"
labelClassName="pl-0"
/>
<Radio
wrapperClassName="border rounded-lg p-3 has-[:checked]:bg-theme-accent has-[:checked]:text-white transition-colors"
label={t("new_user_guide.step.behavior.unread_question.option2")}
value="balanced"
className="hidden"
labelClassName="pl-0"
/>
<Radio
wrapperClassName="border rounded-lg p-3 has-[:checked]:bg-theme-accent has-[:checked]:text-white transition-colors"
label={t("new_user_guide.step.behavior.unread_question.option3")}
value="conservative"
className="hidden"
labelClassName="pl-0"
/>
</RadioGroup>
</div>
Expand Down
14 changes: 9 additions & 5 deletions apps/renderer/src/modules/new-user-guide/steps/rsshub.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"

import { AppErrorBoundary } from "~/components/common/AppErrorBoundary"
import { ErrorComponentType } from "~/components/errors/enum"
import { useAuthQuery } from "~/hooks/common"
import { Recommendations } from "~/modules/discover/recommendations"
import { Queries } from "~/queries"
Expand Down Expand Up @@ -27,10 +29,12 @@ export function RSSHubGuide() {
}

return (
<ScrollArea.ScrollArea viewportClassName="h-[450px]">
<div className="space-y-3">
<Recommendations hideTitle className="grid-cols-4" />
</div>
</ScrollArea.ScrollArea>
<AppErrorBoundary errorType={ErrorComponentType.RSSHubDiscoverError}>
<ScrollArea.ScrollArea viewportClassName="h-[450px]">
<div className="space-y-3">
<Recommendations hideTitle className="grid-cols-4" />
</div>
</ScrollArea.ScrollArea>
</AppErrorBoundary>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { useTranslation } from "react-i18next"
import { useSearchParams } from "react-router-dom"

import { useUserRole } from "~/atoms/user"
import { AppErrorBoundary } from "~/components/common/AppErrorBoundary"
import { ErrorComponentType } from "~/components/errors/enum"
import { useActivationModal } from "~/modules/activation"
import { DiscoverForm } from "~/modules/discover/form"
import { DiscoverImport } from "~/modules/discover/import"
Expand Down Expand Up @@ -114,7 +116,9 @@ export function Component() {
</TabsContent>
))}
</Tabs>
<Recommendations />
<AppErrorBoundary errorType={ErrorComponentType.RSSHubDiscoverError}>
<Recommendations />
</AppErrorBoundary>
</div>
)
}
Expand Down
14 changes: 6 additions & 8 deletions packages/components/src/ui/radio-group/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export const Radio: FC<
React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & {
label: ReactNode
wrapperClassName?: string
labelClassName?: string
}
> = (props) => {
const { id, label, className, wrapperClassName, value, onChange, ...rest } = props
const { id, label, className, wrapperClassName, labelClassName, value, onChange, ...rest } = props
const { onChange: ctxOnChange } = useRadioContext() || {}
const fallbackId = useId()

Expand All @@ -22,7 +23,7 @@ export const Radio: FC<
onChange?.(e)
})
return (
<div className={cn("flex items-center", wrapperClassName)}>
<label className={cn("flex items-center", wrapperClassName)} htmlFor={id ?? fallbackId}>
<input
{...rest}
type="radio"
Expand All @@ -36,12 +37,9 @@ export const Radio: FC<
onChange={handleChange}
/>

<label
className={cn(rest.disabled ? "text-theme-disabled" : "", "pl-2")}
htmlFor={id ?? fallbackId}
>
<span className={cn(rest.disabled ? "text-theme-disabled" : "", "pl-2", labelClassName)}>
{label}
</label>
</div>
</span>
</label>
)
}

0 comments on commit 665c009

Please sign in to comment.