refactor(debug-registry): streamline debug registry entries for error simulation and app upgrade notifications

This commit is contained in:
DIYgod 2025-11-06 17:14:24 +08:00
parent 5ee4817cb6
commit 264bd711e6
No known key found for this signature in database
4 changed files with 89 additions and 97 deletions

View File

@ -1,4 +1,3 @@
import { DEV } from "@follow/shared/constants"
import { cn } from "@follow/utils/utils"
import { FollowAPIError } from "@follow-app/client-sdk"
import { t } from "i18next"
@ -170,30 +169,28 @@ export const toastFetchError = (
})
}
}
if (DEV) {
DebugRegistry.add("Simulate request error", () => {
createErrorToaster(
"Simulated request error",
{},
)({
response: {
_data: JSON.stringify({
code: 1000,
message: "Simulated request error",
reason: "Simulated reason",
}),
},
} as any)
})
DebugRegistry.add("Simulate payment need upgrade error", () => {
createErrorToaster(
"Simulated payment need upgrade error",
{},
)(
new FollowAPIError("Simulated payment need upgrade error", 402, "1111", {
DebugRegistry.add("Simulate request error", () => {
createErrorToaster(
"Simulated request error",
{},
)({
response: {
_data: JSON.stringify({
code: 1000,
message: "Simulated request error",
reason: "Simulated reason",
}),
)
})
}
},
} as any)
})
DebugRegistry.add("Simulate payment need upgrade error", () => {
createErrorToaster(
"Simulated payment need upgrade error",
{},
)(
new FollowAPIError("Simulated payment need upgrade error", 402, "1111", {
reason: "Simulated reason",
}),
)
})

View File

@ -1,5 +1,5 @@
import { RootPortal } from "@follow/components/ui/portal/index.jsx"
import { DEV, IN_ELECTRON, PROD } from "@follow/shared/constants"
import { IN_ELECTRON, PROD } from "@follow/shared/constants"
import { useWhoami } from "@follow/store/user/hooks"
import { preventDefault } from "@follow/utils/dom"
import type { PropsWithChildren } from "react"
@ -233,26 +233,24 @@ const RootContainer = ({
)
}
if (DEV) {
DebugRegistry.add("New User Guide", () => {
import("~/modules/new-user-guide/guide-modal-content").then((m) => {
window.presentModal({
title: "New User Guide",
content: ({ dismiss }) => (
<m.GuideModalContent
onClose={() => {
dismiss()
}}
/>
),
DebugRegistry.add("New User Guide", () => {
import("~/modules/new-user-guide/guide-modal-content").then((m) => {
window.presentModal({
title: "New User Guide",
content: ({ dismiss }) => (
<m.GuideModalContent
onClose={() => {
dismiss()
}}
/>
),
CustomModalComponent: PlainModal,
modalContainerClassName: "flex items-center justify-center",
CustomModalComponent: PlainModal,
modalContainerClassName: "flex items-center justify-center",
canClose: false,
clickOutsideToDismiss: false,
overlay: true,
})
canClose: false,
clickOutsideToDismiss: false,
overlay: true,
})
})
}
})

View File

@ -114,58 +114,56 @@ export const EnvironmentIndicator = () => {
)
}
if (DEV) {
const sqliteOnlineWebsite = "https://sqlite-online.vercel.app"
const sqliteOnlineWebsite = "https://sqlite-online.vercel.app"
DebugRegistry.add("SQLite Online", () => {
window.presentModal({
title: "SQLite Online",
content: ({ dismiss }) => (
<div className="h-full p-16" onClick={dismiss}>
<iframe
id="sql-viewer"
src={sqliteOnlineWebsite}
className="size-full"
onLoad={() => {
const iframe = document.querySelector("#sql-viewer") as HTMLIFrameElement
if (!iframe) return
const win = iframe.contentWindow
if (!win) return
DebugRegistry.add("SQLite Online", () => {
window.presentModal({
title: "SQLite Online",
content: ({ dismiss }) => (
<div className="h-full p-16" onClick={dismiss}>
<iframe
id="sql-viewer"
src={sqliteOnlineWebsite}
className="size-full"
onLoad={() => {
const iframe = document.querySelector("#sql-viewer") as HTMLIFrameElement
if (!iframe) return
const win = iframe.contentWindow
if (!win) return
const eventHandler = (event: MessageEvent) => {
if (event.origin !== sqliteOnlineWebsite) {
console.warn("Blocked message from unauthorized origin:", event.origin)
return
}
if (event.data.type === "loadDatabaseBufferReady") {
getDBFile()
.then(async (blob) => {
const arrayBuffer = await blob.arrayBuffer()
win.postMessage(
{
type: "invokeLoadDatabaseBuffer",
buffer: arrayBuffer,
},
sqliteOnlineWebsite,
)
window.removeEventListener("message", eventHandler)
})
.catch((error) => {
console.error("Failed to load database file into SQLite Online", error)
})
}
const eventHandler = (event: MessageEvent) => {
if (event.origin !== sqliteOnlineWebsite) {
console.warn("Blocked message from unauthorized origin:", event.origin)
return
}
window.addEventListener("message", eventHandler)
}}
/>
</div>
),
if (event.data.type === "loadDatabaseBufferReady") {
getDBFile()
.then(async (blob) => {
const arrayBuffer = await blob.arrayBuffer()
CustomModalComponent: PlainModal,
})
win.postMessage(
{
type: "invokeLoadDatabaseBuffer",
buffer: arrayBuffer,
},
sqliteOnlineWebsite,
)
window.removeEventListener("message", eventHandler)
})
.catch((error) => {
console.error("Failed to load database file into SQLite Online", error)
})
}
}
window.addEventListener("message", eventHandler)
}}
/>
</div>
),
CustomModalComponent: PlainModal,
})
}
})

View File

@ -1,5 +1,4 @@
import { useOnce } from "@follow/hooks"
import { DEV } from "@follow/shared/constants"
import { nextFrame } from "@follow/utils/dom"
import { getStorageNS } from "@follow/utils/ns"
import { repository } from "@pkg"
@ -104,7 +103,7 @@ const AppNotificationContainer: FC = () => {
setTimeout(toaster)
}
DEV && DebugRegistry.add("App Upgraded Toast", toaster)
DebugRegistry.add("App Upgraded Toast", toaster)
})
return null