Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 48 additions & 32 deletions src/contextProviders/FeedbackContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {
createContext,
type PropsWithChildren,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
Expand Down Expand Up @@ -195,30 +197,33 @@ export function FeedbackContextProvider(props: PropsWithChildren) {
});
};

const pushSnackbar = (severity: SnackbarSeverity, input: FeedbackInput) => {
const pushSnackbar = useCallback((severity: SnackbarSeverity, input: FeedbackInput) => {
pushSnackbarItem({
id: createId(),
severity,
message: input.message,
detail: input.detail,
});
};

const showError = (input: ErrorReportInput) => {
pushError({
id: createId(),
severity: "error",
source: input.source,
userMessage: input.userMessage,
code: input.code,
technicalDetails: input.technicalDetails,
correlationId: input.correlationId,
isTransient: input.isTransient ?? true,
timestamp: new Date().toISOString(),
}, input.dedupe ?? true);
};
}, []);

const showFatal = (input: ErrorReportInput) => {
const showError = useCallback((input: ErrorReportInput) => {
pushError(
{
id: createId(),
severity: "error",
source: input.source,
userMessage: input.userMessage,
code: input.code,
technicalDetails: input.technicalDetails,
correlationId: input.correlationId,
isTransient: input.isTransient ?? true,
timestamp: new Date().toISOString(),
},
input.dedupe ?? true,
);
}, [])

const showFatal = useCallback((input: ErrorReportInput) => {
pushError({
id: createId(),
severity: "fatal",
Expand All @@ -230,16 +235,16 @@ export function FeedbackContextProvider(props: PropsWithChildren) {
isTransient: false,
timestamp: new Date().toISOString(),
}, input.dedupe ?? true);
};
}, [])

const showSuccess = (input: FeedbackInput) => pushSnackbar("success", input);
const showInfo = (input: FeedbackInput) => pushSnackbar("info", input);
const showWarning = (input: FeedbackInput) => pushSnackbar("warning", input);
const showSuccess = useCallback((input: FeedbackInput) => pushSnackbar("success", input), [])
const showInfo = useCallback((input: FeedbackInput) => pushSnackbar("info", input), [])
const showWarning = useCallback((input: FeedbackInput) => pushSnackbar("warning", input), [])

const clearFatal = () => {
const clearFatal = useCallback(() => {
setFatalError(null);
setCopyFeedback(null);
};
}, []);

const openLogDirectory = () => {
void invoke("open_log_directory");
Expand Down Expand Up @@ -347,15 +352,26 @@ export function FeedbackContextProvider(props: PropsWithChildren) {
};
}, []);

const value: FeedbackContextValue = {
showError,
showFatal,
clearFatal,
recentErrors,
showSuccess,
showInfo,
showWarning,
};
const value: FeedbackContextValue = useMemo(
() => ({
showError,
showFatal,
clearFatal,
recentErrors,
showSuccess,
showInfo,
showWarning,
}),
[
showError,
showFatal,
clearFatal,
recentErrors,
showSuccess,
showInfo,
showWarning,
],
);

const fatalTrace = fatalError ? buildTrace(fatalError) : "";

Expand Down
2 changes: 1 addition & 1 deletion src/contextProviders/OnboardingContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function OnboardingContextProvider(props: OnboardingContextProviderProps)
});
}
})();
}, [activeStep, showError]);
}, [activeStep]);

const advanceQueue = () => {
setPendingSteps((prev) => prev.slice(1));
Expand Down
3 changes: 1 addition & 2 deletions src/contextProviders/useServerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export function useServerState(options: UseServerStateOptions) {
}

if (!result.success) {
setServers((prev) => prev ?? []);
showError({
source: "frontend.servers.get-servers",
userMessage: "Failed to refresh server list.",
Expand Down Expand Up @@ -183,7 +182,7 @@ export function useServerState(options: UseServerStateOptions) {
clearTimeout(timeoutId);
}
};
}, [isServersPageActive, showError]);
}, [isServersPageActive]);

// Subscribe to real-time events
useEffect(() => {
Expand Down
Loading