diff --git a/apps/mobile/index.ts b/apps/mobile/index.ts index 738722323725..9367ade408e9 100644 --- a/apps/mobile/index.ts +++ b/apps/mobile/index.ts @@ -9,8 +9,6 @@ import { LogBox } from "react-native"; import { featureFlags } from "react-native-screens"; import App from "./src/App"; -// Kin: dev-only inbox log, gated on EXPO_PUBLIC_KIN_DEV_LOG=1. -import "./src/features/chats/state/kinDevLogEntry"; // Enables iOS FormSheet sizing for nested native stacks in non-fitToContents sheets. featureFlags.experiment.synchronousScreenUpdatesEnabled = true; diff --git a/apps/mobile/src/App.tsx b/apps/mobile/src/App.tsx index 544092d744db..ffbdfd8dc419 100644 --- a/apps/mobile/src/App.tsx +++ b/apps/mobile/src/App.tsx @@ -32,6 +32,7 @@ import { pruneIncomingShareImports, startIncomingShareInbox, } from "./features/sharing/IncomingShareProvider"; +import { installKinNotifications } from "./features/chats/notifications/installKinNotifications"; import { installAgentNotificationNavigation, setAgentNotificationPathname, @@ -193,6 +194,7 @@ const appServiceDisposers = [ installThreadOutboxDelivery(), installComposerAttachmentUploads(), startIncomingShareInbox(), + installKinNotifications(linkToAppPath), installAgentNotificationNavigation(linkToAppPath), installAppShortcuts(linkToAppPath), installAppUpdateChecks(), diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx index ef79ef182cc5..8f10e048f5b3 100644 --- a/apps/mobile/src/Stack.tsx +++ b/apps/mobile/src/Stack.tsx @@ -58,6 +58,7 @@ import { DevicePreviewRouteScreen } from "./features/devices/DevicePreviewRouteS import { BrowserPreviewRouteScreen } from "./features/browser/BrowserPreviewRouteScreen"; import { GitBranchesSheet } from "./features/threads/git/GitBranchesSheet"; import { GitCommitSheet } from "./features/threads/git/GitCommitSheet"; +import { KIN_SCREENS } from "./features/chats/routes"; import { GitConfirmSheet } from "./features/threads/git/GitConfirmSheet"; import { GitOverviewSheet } from "./features/threads/git/GitOverviewSheet"; import { ThreadPullRequestsSheet } from "./features/threads/ThreadPullRequestsSheet"; @@ -698,6 +699,7 @@ const RootStackConfig = createWorkspaceStackNavigator({ options: sheetRoute({ detent: 0.55, maxDetent: 0.7, androidFit: true }), }), ...SETTINGS_SCREENS, + ...KIN_SCREENS, SettingsLegal: createNativeStackScreen({ screen: SettingsLegalRouteScreen, linking: "settings/legal", diff --git a/apps/mobile/src/features/chats/KinChatScreen.tsx b/apps/mobile/src/features/chats/KinChatScreen.tsx new file mode 100644 index 000000000000..e7276cf94cda --- /dev/null +++ b/apps/mobile/src/features/chats/KinChatScreen.tsx @@ -0,0 +1,33 @@ +import { useNavigation, type StaticScreenProps } from "@react-navigation/native"; +import { View } from "react-native"; + +import { AppBar } from "../../components/ui/AppBar"; +import { EmptyState } from "../../components/ui/EmptyState"; +import { ScreenContent } from "../../components/ui/ScreenContent"; +import { KinChatPushWatch } from "./notifications/KinChatPushWatch"; + +type KinChatParams = { + readonly environmentId: string; + readonly orgId: string; + readonly chatId: string; +}; + +/** Placeholder until MOB-4's feed, so the chat list, Waiting on you and links can open a chat. */ +export function KinChatScreen({ route }: StaticScreenProps) { + const navigation = useNavigation(); + return ( + + + navigation.goBack()} /> + + + + + + + ); +} diff --git a/apps/mobile/src/features/chats/KinChatsScreen.tsx b/apps/mobile/src/features/chats/KinChatsScreen.tsx new file mode 100644 index 000000000000..62c7e53e894d --- /dev/null +++ b/apps/mobile/src/features/chats/KinChatsScreen.tsx @@ -0,0 +1,66 @@ +import { useNavigation } from "@react-navigation/native"; + +import { EmptyState } from "../../components/ui/EmptyState"; +import { ListRow } from "../../components/ui/ListRow"; +import { ListSection } from "../../components/ui/ListSection"; +import { KinInboxPage } from "./components/KinScreenState"; +import { selectKinInboxView } from "./state/kinInboxModel"; +import { kinChatTitle, kinDirectory } from "./state/kinScreenState"; +import { useKinInbox } from "./state/useKinInbox"; + +/** Placeholder chat list until MOB-3: Waiting on you and plain rows. */ +export function KinChatsScreen() { + const navigation = useNavigation(); + const { host, state, retry } = useKinInbox(); + const { agentNames } = kinDirectory(host); + return ( + + {(ready) => { + const view = selectKinInboxView(ready.inbox.value); + if (view.rows.length === 0) { + return ( + + ); + } + return ( + <> + {view.waitingCount > 0 ? ( + + navigation.navigate("KinWaiting")} + /> + + ) : null} + + {view.rows.map((row) => { + const title = kinChatTitle(row.chat, agentNames); + return ( + 0 ? { detail: `${row.chat.unread} unread` } : {})} + onPress={() => + navigation.navigate("KinChat", { + environmentId: ready.environmentId, + orgId: row.chat.orgId, + chatId: row.chat.chatId, + }) + } + /> + ); + })} + + + ); + }} + + ); +} diff --git a/apps/mobile/src/features/chats/KinHomeEntry.tsx b/apps/mobile/src/features/chats/KinHomeEntry.tsx new file mode 100644 index 000000000000..8bc00e6876cd --- /dev/null +++ b/apps/mobile/src/features/chats/KinHomeEntry.tsx @@ -0,0 +1,94 @@ +import { useNavigation } from "@react-navigation/native"; +import { use } from "react"; +import { View } from "react-native"; + +import { SymbolView } from "../../components/ui/AppSymbol"; +import { AppText as Text } from "../../components/ui/AppText"; +import { usePaneRole } from "../../components/ui/Pane"; +import { RowPressable } from "../../components/ui/RowPressable"; +import { cn } from "../../lib/cn"; +import { NativePrimaryColumnContext } from "../../native/v5-workspace-context"; +import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider"; +import { + getThreadListV2RowAppearance, + THREAD_LIST_V2_ROW_CONTENT_CLASS_NAME, + THREAD_LIST_V2_ROW_DIVIDERS, +} from "../threads/thread-list-v2-row-appearance"; + +import { selectKinInboxView } from "./state/kinInboxModel"; +import { kinHomeLabel, kinHomeSubtitle } from "./state/kinScreenState"; +import { useKinInbox } from "./state/useKinInbox"; + +/** Home's Kin row, first in the thread list. Renders nothing unless an environment hosts Kin. */ +export function KinHomeEntry() { + const navigation = useNavigation(); + const sidebarPane = usePaneRole() === "sidebar" && use(NativePrimaryColumnContext) !== null; + const appearance = getThreadListV2RowAppearance( + useAppearancePreferences().themeVariables, + sidebarPane, + false, + ); + const { host, state } = useKinInbox(); + if (host._tag !== "host") return null; + + const view = state._tag === "ready" ? selectKinInboxView(state.inbox.value) : null; + const waitingCount = view?.waitingCount ?? 0; + const unreadCount = view?.unreadCount ?? 0; + const subtitle = kinHomeSubtitle(state, view); + + const content = ( + + + + Kin + {subtitle === null ? null : ( + 0 + ? "font-t3-bold text-primary" + : appearance.tertiaryForegroundClassName, + )} + > + {subtitle} + + )} + + {unreadCount > 0 ? ( + + {unreadCount} + + ) : null} + + ); + + return ( + + navigation.navigate("KinChats")} + style={appearance.cardStyle} + > + {sidebarPane ? ( + content + ) : ( + + {content} + {THREAD_LIST_V2_ROW_DIVIDERS ? : null} + + )} + + + ); +} diff --git a/apps/mobile/src/features/chats/KinWaitingScreen.tsx b/apps/mobile/src/features/chats/KinWaitingScreen.tsx new file mode 100644 index 000000000000..c1fdc3a39dab --- /dev/null +++ b/apps/mobile/src/features/chats/KinWaitingScreen.tsx @@ -0,0 +1,55 @@ +import { useNavigation } from "@react-navigation/native"; + +import { EmptyState } from "../../components/ui/EmptyState"; +import { ListRow } from "../../components/ui/ListRow"; +import { ListSection } from "../../components/ui/ListSection"; +import { KinInboxPage } from "./components/KinScreenState"; +import { selectKinInboxView } from "./state/kinInboxModel"; +import { formatKinTime, kinDirectory, kinWaitingRowView } from "./state/kinScreenState"; +import { useKinInbox } from "./state/useKinInbox"; + +/** Placeholder Waiting on you until the native cards land: one row per item, oldest first. */ +export function KinWaitingScreen() { + const navigation = useNavigation(); + const { host, state, retry } = useKinInbox(); + const { agentNames } = kinDirectory(host); + return ( + + {(ready) => { + const view = selectKinInboxView(ready.inbox.value); + if (view.waiting.length === 0) { + return ( + + ); + } + return ( + + {view.waiting.map((item) => { + const row = kinWaitingRowView(item, ready.inbox.value.chats, agentNames); + return ( + + navigation.navigate("KinChat", { + environmentId: ready.environmentId, + orgId: item.orgId, + chatId: item.chatId, + }) + } + /> + ); + })} + + ); + }} + + ); +} diff --git a/apps/mobile/src/features/chats/components/KinScreenState.tsx b/apps/mobile/src/features/chats/components/KinScreenState.tsx new file mode 100644 index 000000000000..02de6f4d71bf --- /dev/null +++ b/apps/mobile/src/features/chats/components/KinScreenState.tsx @@ -0,0 +1,120 @@ +import { useNavigation } from "@react-navigation/native"; +import type { ReactNode } from "react"; +import { View } from "react-native"; + +import { AppActivityIndicator } from "../../../components/ui/AppActivityIndicator"; +import { AppBar } from "../../../components/ui/AppBar"; +import { Button } from "../../../components/ui/Button"; +import { EmptyState } from "../../../components/ui/EmptyState"; +import { ErrorBanner } from "../../../components/ui/ErrorBanner"; +import { Notice } from "../../../components/ui/Notice"; +import { ScreenContent } from "../../../components/ui/ScreenContent"; +import { ScreenScrollView } from "../../../components/ui/ScreenScrollView"; +import { kinInboxNotice, type KinInboxScreenState } from "../state/kinScreenState"; + +type ReadyState = Extract; + +const timeFormat = new Intl.DateTimeFormat(undefined, { hour: "numeric", minute: "2-digit" }); + +/** A Kin page: its bar, then the inbox's state, with `children` drawing the ready inbox. */ +export function KinInboxPage(props: { + readonly title: string; + readonly state: KinInboxScreenState; + readonly onRetry: () => void; + readonly children: (ready: ReadyState) => ReactNode; +}) { + const navigation = useNavigation(); + return ( + + navigation.goBack()} /> + + + + + + + ); +} + +function KinInboxStateBody(props: { + readonly state: KinInboxScreenState; + readonly onRetry: () => void; + readonly children: (ready: ReadyState) => ReactNode; +}) { + const navigation = useNavigation(); + const { state } = props; + switch (state._tag) { + case "loading": + return ( + + + + ); + case "offline": + return ( + + ); + case "noHost": + return ( + navigation.navigate("SettingsEnvironments")} + /> + ); + case "unauthorized": + return ( + + ); + case "noIdentity": + return ( + + ); + case "error": + return ( + + + +