fix(ui): purge empty phantom sessions on startup (#9651)
Signed-off-by: Varun Nuthalapati <nuthalapativarun@gmail.com> Co-authored-by: Douwe M Osinga <douwe@sidewalklabs.com>
This commit is contained in:
@@ -34,6 +34,11 @@ vi.mock('./utils/costDatabase', () => ({
|
||||
initializeCostDatabase: vi.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
|
||||
vi.mock('./acp/sessions', () => ({
|
||||
acpListSessions: vi.fn().mockResolvedValue({ sessions: [], nextCursor: null }),
|
||||
acpDeleteSession: vi.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
|
||||
vi.mock('./sessions', () => ({
|
||||
fetchSessionDetails: vi
|
||||
.fn()
|
||||
|
||||
+17
-3
@@ -18,6 +18,7 @@ import AnnouncementModal from './components/AnnouncementModal';
|
||||
import TelemetryConsentPrompt from './components/TelemetryConsentPrompt';
|
||||
import OnboardingGuard from './components/onboarding/OnboardingGuard';
|
||||
import { createSession } from './sessions';
|
||||
import { acpListSessions, acpDeleteSession } from './acp/sessions';
|
||||
|
||||
import { ChatType } from './types/chat';
|
||||
import Hub from './components/Hub';
|
||||
@@ -396,7 +397,20 @@ export function AppInner() {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const handleOpenSessionShare = async (_event: IpcRendererEvent, ...args: unknown[]) => {
|
||||
acpListSessions()
|
||||
.then(({ sessions }) => {
|
||||
const phantom = sessions.filter(
|
||||
(s) => s.messageCount === 0 && !s.userSetName && !s.hasRecipe
|
||||
);
|
||||
for (const s of phantom) {
|
||||
acpDeleteSession(s.id).catch(() => {});
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const handleOpenSharedSession = async (_event: IpcRendererEvent, ...args: unknown[]) => {
|
||||
const link = args[0] as string;
|
||||
window.electron.logInfo('Opening session share link');
|
||||
|
||||
@@ -430,9 +444,9 @@ export function AppInner() {
|
||||
}
|
||||
}
|
||||
};
|
||||
window.electron.on('open-shared-session', handleOpenSessionShare);
|
||||
window.electron.on('open-shared-session', handleOpenSharedSession);
|
||||
return () => {
|
||||
window.electron.off('open-shared-session', handleOpenSessionShare);
|
||||
window.electron.off('open-shared-session', handleOpenSharedSession);
|
||||
};
|
||||
}, [navigate]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user