@@ -7,7 +7,15 @@ import {
77 type StaticScreenProps ,
88} from "@react-navigation/native" ;
99import { SymbolView } from "../../components/AppSymbol" ;
10+ import {
11+ buildChatProjectCreateCommand ,
12+ canCreateProjectInEnvironment ,
13+ findChatProject ,
14+ } from "@t3tools/client-runtime/operations/projects" ;
1015import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell" ;
16+ import { CommandId , ProjectId } from "@t3tools/contracts" ;
17+ import * as Cause from "effect/Cause" ;
18+ import { AsyncResult } from "effect/unstable/reactivity" ;
1119import { useEffect , useRef } from "react" ;
1220import { ActivityIndicator , Alert , Platform , Pressable , View } from "react-native" ;
1321import { useSafeAreaInsets } from "react-native-safe-area-context" ;
@@ -18,7 +26,11 @@ import { MaterialButton } from "../../components/MaterialButton";
1826import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView" ;
1927import { AppText as Text } from "../../components/AppText" ;
2028import { ProjectFavicon } from "../../components/ProjectFavicon" ;
21- import { useProjects } from "../../state/entities" ;
29+ import { uuidv4 } from "../../lib/uuid" ;
30+ import { useProjects , useServerConfigs , waitForProject } from "../../state/entities" ;
31+ import { projectEnvironment } from "../../state/projects" ;
32+ import { useAtomCommand } from "../../state/use-atom-command" ;
33+ import { useRemoteConnectionStatus } from "../../state/use-remote-environment-registry" ;
2234import type { WorkspaceState } from "../../state/workspaceModel" ;
2335import { useWorkspaceState } from "../../state/workspace" ;
2436import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout" ;
@@ -115,6 +127,26 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
115127 project . id === incomingShare . destination ?. projectId ,
116128 ) ?? null )
117129 : null ;
130+ const serverConfigs = useServerConfigs ( ) ;
131+ const { connectedEnvironments } = useRemoteConnectionStatus ( ) ;
132+ const createProject = useAtomCommand ( projectEnvironment . create , { reportFailure : false } ) ;
133+ // "Just chat" needs a connected environment whose server offers a chat
134+ // folder. Prefer the environment the picker is already scoped to.
135+ const chatEnvironment =
136+ connectedEnvironments . find (
137+ ( environment ) =>
138+ environment . environmentId === selectedEnvironmentId &&
139+ canCreateProjectInEnvironment ( environment . connectionState ) ,
140+ ) ??
141+ connectedEnvironments . find ( ( environment ) =>
142+ canCreateProjectInEnvironment ( environment . connectionState ) ,
143+ ) ??
144+ null ;
145+ const chatWorkspaceRoot = chatEnvironment
146+ ? ( serverConfigs . get ( chatEnvironment . environmentId ) ?. chatWorkspaceRoot ?? null )
147+ : null ;
148+ const canJustChat =
149+ chatEnvironment !== null && chatWorkspaceRoot !== null && reservedDestinationProject === null ;
118150
119151 async function selectProject ( project : EnvironmentProject ) : Promise < void > {
120152 if ( incomingShare ?. destination && ! reservedDestinationProject ) {
@@ -148,6 +180,43 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
148180 ) ;
149181 }
150182
183+ async function startChat ( ) : Promise < void > {
184+ if ( ! chatEnvironment || chatWorkspaceRoot === null ) return ;
185+ const environmentId = chatEnvironment . environmentId ;
186+ const existing = findChatProject ( { projects, environmentId, chatWorkspaceRoot } ) ;
187+ if ( existing ) {
188+ await selectProject ( existing ) ;
189+ return ;
190+ }
191+ const projectId = ProjectId . make ( uuidv4 ( ) ) ;
192+ const result = await createProject ( {
193+ environmentId,
194+ input : buildChatProjectCreateCommand ( {
195+ commandId : CommandId . make ( uuidv4 ( ) ) ,
196+ projectId,
197+ chatWorkspaceRoot,
198+ createdAt : new Date ( ) . toISOString ( ) ,
199+ } ) ,
200+ } ) ;
201+ if ( AsyncResult . isFailure ( result ) ) {
202+ const error = Cause . squash ( result . cause ) ;
203+ Alert . alert (
204+ "Could not start chat" ,
205+ error instanceof Error ? error . message : "The chat folder could not be created." ,
206+ ) ;
207+ return ;
208+ }
209+ const project = await waitForProject ( { environmentId, projectId } ) ;
210+ if ( project === null ) {
211+ Alert . alert (
212+ "Could not start chat" ,
213+ "The chat folder was created but has not reached this device yet. Pick Chats from the project list once it appears." ,
214+ ) ;
215+ return ;
216+ }
217+ await selectProject ( project ) ;
218+ }
219+
151220 useEffect ( ( ) => {
152221 const destination = incomingShare ?. destination ;
153222 if ( ! destination ) {
@@ -263,15 +332,24 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
263332 { projectEmptyState . detail }
264333 </ Text >
265334 { Platform . OS === "android" ? (
266- < MaterialButton
267- label = { catalogState . hasReadyEnvironment ? "Add new project" : "Add environment" }
268- tone = "primary"
269- onPress = { ( ) =>
270- catalogState . hasReadyEnvironment
271- ? navigation . dispatch ( StackActions . push ( "AddProject" ) )
272- : navigation . navigate ( "ConnectionsNew" )
273- }
274- />
335+ < >
336+ < MaterialButton
337+ label = { catalogState . hasReadyEnvironment ? "Add new project" : "Add environment" }
338+ tone = "primary"
339+ onPress = { ( ) =>
340+ catalogState . hasReadyEnvironment
341+ ? navigation . dispatch ( StackActions . push ( "AddProject" ) )
342+ : navigation . navigate ( "ConnectionsNew" )
343+ }
344+ />
345+ { canJustChat ? (
346+ < MaterialButton
347+ label = "Just chat"
348+ tone = "secondary"
349+ onPress = { ( ) => void startChat ( ) }
350+ />
351+ ) : null }
352+ </ >
275353 ) : ! catalogState . hasReadyEnvironment ? (
276354 < Pressable
277355 className = "mt-1 rounded-full bg-primary px-4 py-2.5 active:opacity-70"
@@ -282,14 +360,24 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
282360 </ Text >
283361 </ Pressable >
284362 ) : (
285- < Pressable
286- className = "mt-1 rounded-full bg-primary px-4 py-2.5 active:opacity-70"
287- onPress = { ( ) => navigation . dispatch ( StackActions . push ( "AddProject" ) ) }
288- >
289- < Text className = "text-sm font-t3-bold text-primary-foreground" >
290- Add new project
291- </ Text >
292- </ Pressable >
363+ < >
364+ < Pressable
365+ className = "mt-1 rounded-full bg-primary px-4 py-2.5 active:opacity-70"
366+ onPress = { ( ) => navigation . dispatch ( StackActions . push ( "AddProject" ) ) }
367+ >
368+ < Text className = "text-sm font-t3-bold text-primary-foreground" >
369+ Add new project
370+ </ Text >
371+ </ Pressable >
372+ { canJustChat ? (
373+ < Pressable
374+ className = "rounded-full bg-subtle px-4 py-2.5 active:opacity-70"
375+ onPress = { ( ) => void startChat ( ) }
376+ >
377+ < Text className = "text-sm font-t3-bold text-foreground" > Just chat</ Text >
378+ </ Pressable >
379+ ) : null }
380+ </ >
293381 ) }
294382 </ View >
295383 ) : (
@@ -378,6 +466,55 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
378466 } ) }
379467 </ View >
380468 ) }
469+ { canJustChat && projectScopes . length > 0 ? (
470+ Platform . OS === "android" ? (
471+ < View collapsable = { false } className = "overflow-hidden rounded-[28px] bg-card" >
472+ < MaterialListRow
473+ title = "Just chat"
474+ subtitle = "Start a task without a repository"
475+ onPress = { ( ) => void startChat ( ) }
476+ leading = {
477+ < SymbolView
478+ name = "bubble.left"
479+ size = { 22 }
480+ tintColorClassName = "accent-icon-muted"
481+ type = "monochrome"
482+ />
483+ }
484+ />
485+ </ View >
486+ ) : (
487+ < View collapsable = { false } className = "overflow-hidden rounded-[24px] bg-card" >
488+ < Pressable
489+ accessibilityRole = "button"
490+ accessibilityLabel = "Just chat"
491+ onPress = { ( ) => void startChat ( ) }
492+ className = "flex-row items-center gap-3 bg-card px-4 py-3.5"
493+ >
494+ < View className = "h-7 w-7 items-center justify-center" >
495+ < SymbolView
496+ name = "bubble.left"
497+ size = { 18 }
498+ tintColorClassName = "accent-icon-muted"
499+ type = "monochrome"
500+ />
501+ </ View >
502+ < View className = "min-w-0 flex-1" >
503+ < Text className = "text-base font-t3-bold leading-snug" > Just chat</ Text >
504+ < Text className = "text-xs leading-snug text-foreground-muted" numberOfLines = { 1 } >
505+ Start a task without a repository
506+ </ Text >
507+ </ View >
508+ < SymbolView
509+ name = "chevron.right"
510+ size = { 14 }
511+ tintColorClassName = "accent-chevron"
512+ type = "monochrome"
513+ />
514+ </ Pressable >
515+ </ View >
516+ )
517+ ) : null }
381518 </ ScrollView >
382519 </ MaterialScreenContent >
383520 </ View >
0 commit comments