Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(onboarding): spin only the timeline button that was clicked

Anshgrover233c1ae8914fbc
diff --git a/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.test.tsx b/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.test.tsx
index 935136047..e4a9d4f14 100644
--- a/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.test.tsx
+++ b/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.test.tsx
@@ -194,6 +194,37 @@ describe("TimelineChoice", () => {
await waitFor(() => expect(handleNextSlide).toHaveBeenCalledTimes(1));
});
+ // Regression: a single `saving` boolean lit the spinner in both buttons, so
+ // the panel looked like it was applying both choices at once.
+ it("spins only the button that was clicked", async () => {
+ mocks.settings.deviceTier = "high";
+ let releaseWrite!: () => void;
+ mocks.updateSettings.mockImplementation(
+ () => new Promise<void>((resolve) => (releaseWrite = resolve)),
+ );
+ render(<TimelineChoice handleNextSlide={vi.fn()} />);
+
+ const onButton = screen.getByRole("button", { name: /timeline on/i });
+ const offButton = screen.getByRole("button", { name: /keep it off/i });
+
+ await act(async () => {
+ fireEvent.click(offButton);
+ });
+
+ // write still pending: exactly one spinner, and it is inside "keep it off"
+ const spinners = document.querySelectorAll(".animate-spin");
+ expect(spinners).toHaveLength(1);
+ expect(offButton).toContainElement(spinners[0] as HTMLElement);
+ expect(onButton).not.toContainElement(spinners[0] as HTMLElement);
+ // both stay disabled while a choice is in flight
+ expect(onButton).toBeDisabled();
+ expect(offButton).toBeDisabled();
+
+ await act(async () => {
+ releaseWrite();
+ });
+ });
+
it("does not restart screenpipe during first-run onboarding", async () => {
mocks.settings.deviceTier = "high";
const handleNextSlide = vi.fn();
diff --git a/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.tsx b/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.tsx
index 3094fd295..83f77e8b3 100644
--- a/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.tsx
+++ b/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.tsx
@@ -190,7 +190,9 @@ export default function TimelineChoice({ handleNextSlide }: TimelineChoiceProps)
const mountTimeRef = useRef(Date.now());
const hasAdvanced = useRef(false);
const inFlight = useRef(false);
- const [saving, setSaving] = useState(false);
+ // Which choice is being saved, so only the clicked button spins. A plain
+ // boolean would light up both, since each button renders the same flag.
+ const [pending, setPending] = useState<boolean | null>(null);
const [error, setError] = useState<string | null>(null);
const lowTier = isLowTier(settings.deviceTier);
@@ -203,7 +205,7 @@ export default function TimelineChoice({ handleNextSlide }: TimelineChoiceProps)
// from hasAdvanced so a failed attempt stays retryable.
if (hasAdvanced.current || inFlight.current) return;
inFlight.current = true;
- setSaving(true);
+ setPending(enabled);
setError(null);
posthog.capture("onboarding_timeline_choice", {
timeline_enabled: enabled,
@@ -230,7 +232,7 @@ export default function TimelineChoice({ handleNextSlide }: TimelineChoiceProps)
posthog.capture("onboarding_timeline_choice_failed", { stage: "persist" });
setError("couldn't save that choice. check disk space and try again.");
inFlight.current = false;
- setSaving(false);
+ setPending(null);
return;
}
@@ -238,7 +240,7 @@ export default function TimelineChoice({ handleNextSlide }: TimelineChoiceProps)
posthog.capture("onboarding_timeline_choice_failed", { stage: "restart" });
setError("saved, but screenpipe didn't restart. try again to apply it.");
inFlight.current = false;
- setSaving(false);
+ setPending(null);
return;
}
@@ -353,7 +355,7 @@ export default function TimelineChoice({ handleNextSlide }: TimelineChoiceProps)
>
<button
onClick={() => choose(true)}
- disabled={saving}
+ disabled={pending !== null}
className={`flex-1 flex flex-col items-center gap-1 border py-3 font-mono text-xs uppercase tracking-widest transition-colors duration-150 disabled:opacity-60 ${
recommendEnabled
? "border-foreground bg-foreground text-background hover:bg-background hover:text-foreground"
@@ -361,7 +363,7 @@ export default function TimelineChoice({ handleNextSlide }: TimelineChoiceProps)
}`}
>
<span className="flex items-center gap-1.5">
- {saving && <Loader className="w-3 h-3 animate-spin" />}
+ {pending === true && <Loader className="w-3 h-3 animate-spin" />}
timeline on
</span>
{recommendEnabled
@@ -370,7 +372,7 @@ export default function TimelineChoice({ handleNextSlide }: TimelineChoiceProps)
</button>
<button
onClick={() => choose(false)}
- disabled={saving}
+ disabled={pending !== null}
className={`flex-1 flex flex-col items-center gap-1 border py-3 font-mono text-xs uppercase tracking-widest transition-colors duration-150 disabled:opacity-60 ${
!recommendEnabled
? "border-foreground bg-foreground text-background hover:bg-background hover:text-foreground"
@@ -378,7 +380,7 @@ export default function TimelineChoice({ handleNextSlide }: TimelineChoiceProps)
}`}
>
<span className="flex items-center gap-1.5">
- {saving && <Loader className="w-3 h-3 animate-spin" />}
+ {pending === false && <Loader className="w-3 h-3 animate-spin" />}
keep it off
</span>
{!recommendEnabled