truly disable check problems (#566)

This commit is contained in:
Will Chen
2025-07-03 17:51:37 -07:00
committed by GitHub
parent d0f6e40378
commit 77e39874ad
4 changed files with 38 additions and 13 deletions

View File

@@ -2,7 +2,13 @@ import { useSettings } from "@/hooks/useSettings";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch"; import { Switch } from "@/components/ui/switch";
export function AutoFixProblemsSwitch() { import { showInfo } from "@/lib/toast";
export function AutoFixProblemsSwitch({
showToast = false,
}: {
showToast?: boolean;
}) {
const { settings, updateSettings } = useSettings(); const { settings, updateSettings } = useSettings();
return ( return (
<div className="flex items-center space-x-2"> <div className="flex items-center space-x-2">
@@ -13,6 +19,9 @@ export function AutoFixProblemsSwitch() {
updateSettings({ updateSettings({
enableAutoFixProblems: !settings?.enableAutoFixProblems, enableAutoFixProblems: !settings?.enableAutoFixProblems,
}); });
if (!settings?.enableAutoFixProblems && showToast) {
showInfo("You can disable Auto-fix problems in the Settings page.");
}
}} }}
/> />
<Label htmlFor="auto-fix-problems">Auto-fix problems</Label> <Label htmlFor="auto-fix-problems">Auto-fix problems</Label>

View File

@@ -15,6 +15,8 @@ import { useStreamChat } from "@/hooks/useStreamChat";
import { useCheckProblems } from "@/hooks/useCheckProblems"; import { useCheckProblems } from "@/hooks/useCheckProblems";
import { createProblemFixPrompt } from "@/shared/problem_prompt"; import { createProblemFixPrompt } from "@/shared/problem_prompt";
import { showError } from "@/lib/toast"; import { showError } from "@/lib/toast";
import { useSettings } from "@/hooks/useSettings";
import { AutoFixProblemsSwitch } from "../AutoFixProblemsSwitch";
interface ProblemItemProps { interface ProblemItemProps {
problem: Problem; problem: Problem;
@@ -62,6 +64,7 @@ const RecheckButton = ({
variant = "outline", variant = "outline",
className = "h-7 px-3 text-xs", className = "h-7 px-3 text-xs",
}: RecheckButtonProps) => { }: RecheckButtonProps) => {
const { settings } = useSettings();
const { checkProblems, isChecking } = useCheckProblems(appId); const { checkProblems, isChecking } = useCheckProblems(appId);
const handleRecheck = async () => { const handleRecheck = async () => {
@@ -71,6 +74,21 @@ const RecheckButton = ({
} }
}; };
if (!settings?.enableAutoFixProblems) {
return (
<div className="flex flex-col items-center justify-center h-full text-center p-8">
<div className="w-16 h-16 rounded-full bg-[var(--background-darkest)] flex items-center justify-center mb-4">
<Wrench size={24} className="text-muted-foreground" />
</div>
<h3 className="text-lg font-medium mb-2">Enable Auto-Fix Problems</h3>
<p className="text-sm text-muted-foreground max-w-md mb-4">
You need to enable autofix problems to use the Problem pane.
</p>
<AutoFixProblemsSwitch showToast={true} />
</div>
);
}
return ( return (
<Button <Button
size={size} size={size}
@@ -179,14 +197,6 @@ export function _Problems() {
if (!problemReport) { if (!problemReport) {
return ( return (
<div className="flex flex-col items-center justify-center h-full text-center p-8"> <div className="flex flex-col items-center justify-center h-full text-center p-8">
<div className="w-16 h-16 rounded-full bg-[var(--background-darkest)] flex items-center justify-center mb-4">
<FileText size={24} className="text-muted-foreground" />
</div>
<h3 className="text-lg font-medium mb-2">No Problems Data</h3>
<p className="text-sm text-muted-foreground max-w-md mb-4">
No TypeScript diagnostics available for this app yet. Problems will
appear here after running type checking.
</p>
<RecheckButton appId={selectedAppId} /> <RecheckButton appId={selectedAppId} />
</div> </div>
); );

View File

@@ -1,8 +1,10 @@
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { IpcClient } from "@/ipc/ipc_client"; import { IpcClient } from "@/ipc/ipc_client";
import type { ProblemReport } from "@/ipc/ipc_types"; import type { ProblemReport } from "@/ipc/ipc_types";
import { useSettings } from "./useSettings";
export function useCheckProblems(appId: number | null) { export function useCheckProblems(appId: number | null) {
const { settings } = useSettings();
const { const {
data: problemReport, data: problemReport,
isLoading: isChecking, isLoading: isChecking,
@@ -17,7 +19,7 @@ export function useCheckProblems(appId: number | null) {
const ipcClient = IpcClient.getInstance(); const ipcClient = IpcClient.getInstance();
return ipcClient.checkProblems({ appId }); return ipcClient.checkProblems({ appId });
}, },
enabled: !!appId, enabled: !!appId && settings?.enableAutoFixProblems,
// DO NOT SHOW ERROR TOAST. // DO NOT SHOW ERROR TOAST.
}); });

View File

@@ -1,14 +1,18 @@
import { db } from "../../db"; import { db } from "../../db";
import { ipcMain } from "electron";
import { apps } from "../../db/schema"; import { apps } from "../../db/schema";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { generateProblemReport } from "../processors/tsc"; import { generateProblemReport } from "../processors/tsc";
import { getDyadAppPath } from "@/paths/paths"; import { getDyadAppPath } from "@/paths/paths";
import { logger } from "./app_upgrade_handlers"; import log from "electron-log";
import { createLoggedHandler } from "./safe_handle";
const logger = log.scope("problems_handlers");
const handle = createLoggedHandler(logger);
export function registerProblemsHandlers() { export function registerProblemsHandlers() {
// Handler to check problems using autofix with empty response // Handler to check problems using autofix with empty response
ipcMain.handle("check-problems", async (event, params: { appId: number }) => { handle("check-problems", async (event, params: { appId: number }) => {
try { try {
// Get the app to find its path // Get the app to find its path
const app = await db.query.apps.findFirst({ const app = await db.query.apps.findFirst({