Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

fix(fullview): clear the duplicate failure message when the route changes

davbio139e9a01fecd
diff --git a/src/ui/fullview/TopNav.tsx b/src/ui/fullview/TopNav.tsx
index 5f4b8e9..c633a0c 100644
--- a/src/ui/fullview/TopNav.tsx
+++ b/src/ui/fullview/TopNav.tsx
@@ -68,10 +68,17 @@ export default function TopNav({ route }: TopNavProps) {
}));
const [exportOpen, setExportOpen] = useState(false);
const [duplicating, setDuplicating] = useState(false);
- const [duplicateFailedOnRoute, setDuplicateFailedOnRoute] = useState<string | null>(null);
const settleTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
const routeKey = route.page === 'guide' ? `guide/${route.guideId}` : `library/${route.category}`;
+ const [duplicateFailedOnRoute, setDuplicateFailedOnRoute] = useState<string | null>(null);
+ const [previousRoute, setPreviousRoute] = useState(routeKey);
+
+ if (previousRoute !== routeKey) {
+ setPreviousRoute(routeKey);
+ setDuplicateFailedOnRoute(null);
+ }
+
const duplicateFailed = duplicateFailedOnRoute === routeKey;
useEffect(() => () => clearTimeout(settleTimer.current ?? undefined), []);
diff --git a/src/ui/fullview/__tests__/topnav-duplicate.test.tsx b/src/ui/fullview/__tests__/topnav-duplicate.test.tsx
index 856fdb0..1dd3ba1 100644
--- a/src/ui/fullview/__tests__/topnav-duplicate.test.tsx
+++ b/src/ui/fullview/__tests__/topnav-duplicate.test.tsx
@@ -139,6 +139,20 @@ describe('TopNav duplicate', () => {
expect(screen.queryByRole('alert')).toBeNull();
});
+ it('does not bring the message back when you return to the guide that failed', async () => {
+ duplicateGuide.mockRejectedValue(new Error('boom'));
+ const { rerender } = render(<TopNav route={route} />);
+
+ fireEvent.click(duplicateButton());
+ await settleMicrotasks();
+ expect(screen.getByRole('alert')).toBeTruthy();
+
+ rerender(<TopNav route={{ page: 'library', category: 'all' } as const} />);
+ rerender(<TopNav route={route} />);
+
+ expect(screen.queryByRole('alert')).toBeNull();
+ });
+
it('clears the message when a later attempt succeeds', async () => {
duplicateGuide.mockRejectedValueOnce(new Error('boom'));
render(<TopNav route={route} />);