The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { useNavigation } from "@react-navigation/native"; |
| 2 | import { useGT } from "gt-react-native"; |
| 3 | import { useEffect } from "react"; |
| 4 | import { BackHandler, Keyboard } from "react-native"; |
| 5 | import { AppBar } from "../../../components/ui/AppBar"; |
| 6 | import { appBarMenuItemsFromActions } from "../../../components/ui/menuActionItems"; |
| 7 | import { useHardwareKeyboardCommand } from "../../keyboard/hardwareKeyboardCommands"; |
| 8 | import { WorkspaceConnectionTitle } from "../../home/WorkspaceConnectionTitle"; |
| 9 | import type { SharedSlotTab } from "./navigation-tab-order"; |
| 10 | import { SharedSlotTitle } from "./SharedSlotTitle"; |
| 11 | import { useWorkspaceTabs } from "./WorkspaceTabsContext"; |
| 12 | import type { PullRequestFilterMenu } from "../../pull-requests/PullRequestListFilters"; |
| 13 | import { openSettings } from "../../settings/settings-navigation"; |
| 14 | |
| 15 | /** Pull request and issue search share the thread list's Android header. */ |
| 16 | export function ListSearchToolbar(props: { |
| 17 | readonly tab: SharedSlotTab; |
| 18 | readonly filters?: PullRequestFilterMenu | null; |
| 19 | readonly onRequestVisibility?: () => void; |
| 20 | }) { |
| 21 | const gt = useGT(); |
| 22 | const navigation = useNavigation(); |
| 23 | const { filters, tab: section } = props; |
| 24 | const workspace = useWorkspaceTabs()!; |
| 25 | const { dispatch, getScrollOffset, recordScrollOffset, isTabActive } = workspace; |
| 26 | const { onRequestVisibility } = props; |
| 27 | const tab = workspace.state.tabs[section]; |
| 28 | const searching = tab.searchMode !== "resting"; |
| 29 | const openSearch = () => { |
| 30 | onRequestVisibility?.(); |
| 31 | dispatch({ |
| 32 | type: "scroll", |
| 33 | tab: section, |
| 34 | offset: getScrollOffset(section), |
| 35 | }); |
| 36 | dispatch({ type: "search", tab: section }); |
| 37 | return true; |
| 38 | }; |
| 39 | useHardwareKeyboardCommand("focusSearch", openSearch); |
| 40 | const closeSearch = () => { |
| 41 | Keyboard.dismiss(); |
| 42 | recordScrollOffset(section, tab.searchEntryOffset); |
| 43 | dispatch({ type: "cancel", tab: section }); |
| 44 | }; |
| 45 | // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to BackHandler while searching to close the list search on Android back |
| 46 | useEffect(() => { |
| 47 | if (!searching) return; |
| 48 | const subscription = BackHandler.addEventListener("hardwareBackPress", () => { |
| 49 | // Frozen Home screens stay mounted under a detail route or another tab, |
| 50 | // so back only applies while this list is in front. |
| 51 | const state = navigation.getState(); |
| 52 | if (!state || state.routes[state.index]?.name !== "Home" || !isTabActive(section)) |
| 53 | return false; |
| 54 | if (Keyboard.isVisible()) Keyboard.dismiss(); |
| 55 | else closeSearch(); |
| 56 | return true; |
| 57 | }); |
| 58 | return () => subscription.remove(); |
| 59 | }, [searching, closeSearch, navigation, isTabActive, section]); |
| 60 | return ( |
| 61 | <AppBar |
| 62 | title="T3 Code" |
| 63 | titleContent={ |
| 64 | <WorkspaceConnectionTitle |
| 65 | grow |
| 66 | onPress={() => openSettings(navigation, "SettingsEnvironments")} |
| 67 | brand={<SharedSlotTitle tab={section} />} |
| 68 | /> |
| 69 | } |
| 70 | search={{ |
| 71 | value: tab.query, |
| 72 | onChangeText: (query) => dispatch({ type: "query", tab: section, query }), |
| 73 | placeholder: section === "issues" ? gt("Search issues") : gt("Search pull requests"), |
| 74 | active: searching, |
| 75 | onOpen: openSearch, |
| 76 | onClose: closeSearch, |
| 77 | }} |
| 78 | menus={ |
| 79 | filters |
| 80 | ? [ |
| 81 | { |
| 82 | title: section === "issues" ? gt("Filter issues") : gt("Filter pull requests"), |
| 83 | icon: filters.customized |
| 84 | ? "line.3.horizontal.decrease.circle.fill" |
| 85 | : "line.3.horizontal.decrease.circle", |
| 86 | items: appBarMenuItemsFromActions(filters.actions, filters.onSelect), |
| 87 | }, |
| 88 | ] |
| 89 | : undefined |
| 90 | } |
| 91 | /> |
| 92 | ); |
| 93 | } |