Skip to content
Merged
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
2 changes: 0 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1631,8 +1631,6 @@ function MainApp() {

useTabActivationGuard({
activeTab,
activeWorkspace,
isPhone,
isTablet,
setActiveTab,
});
Expand Down
34 changes: 34 additions & 0 deletions src/features/app/hooks/useTabActivationGuard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @vitest-environment jsdom
import { renderHook } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { useTabActivationGuard } from "./useTabActivationGuard";

describe("useTabActivationGuard", () => {
it("does not force home tab on phone when no workspace is selected", () => {
const setActiveTab = vi.fn();

renderHook(() =>
useTabActivationGuard({
activeTab: "git",
isTablet: false,
setActiveTab,
}),
);

expect(setActiveTab).not.toHaveBeenCalled();
});

it("redirects tablet home tab selection to codex", () => {
const setActiveTab = vi.fn();

renderHook(() =>
useTabActivationGuard({
activeTab: "home",
isTablet: true,
setActiveTab,
}),
);

expect(setActiveTab).toHaveBeenCalledWith("codex");
});
});
14 changes: 0 additions & 14 deletions src/features/app/hooks/useTabActivationGuard.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
import { useEffect } from "react";
import type { WorkspaceInfo } from "../../../types";

type AppTab = "home" | "projects" | "codex" | "git" | "log";

type UseTabActivationGuardOptions = {
activeTab: AppTab;
activeWorkspace: WorkspaceInfo | null;
isPhone: boolean;
isTablet: boolean;
setActiveTab: (tab: AppTab) => void;
};

export function useTabActivationGuard({
activeTab,
activeWorkspace,
isPhone,
isTablet,
setActiveTab,
}: UseTabActivationGuardOptions) {
useEffect(() => {
if (!isPhone) {
return;
}
if (!activeWorkspace && activeTab !== "home" && activeTab !== "projects") {
setActiveTab("home");
}
}, [activeTab, activeWorkspace, isPhone, setActiveTab]);

useEffect(() => {
if (!isTablet) {
return;
Expand Down