@@ -3,6 +3,13 @@ import { EnvironmentId, ThreadId } from "@t3tools/contracts";
33import { useNavigation , type StaticScreenProps } from "@react-navigation/native" ;
44import { useState } from "react" ;
55import { View } from "react-native" ;
6+ import { AppActivityIndicator } from "../../components/AppActivityIndicator" ;
7+ import {
8+ readWorkspacePane ,
9+ rememberWorkspacePane ,
10+ resolveWorkspacePane ,
11+ type WorkspacePane ,
12+ } from "./workspacePaneMemory" ;
613import { SegmentedControl } from "../../components/SegmentedControl" ;
714import { useEnvironmentQuery } from "../../state/query" ;
815import { useEnvironmentPresentation } from "../../state/presentation" ;
@@ -24,9 +31,16 @@ type Props = StaticScreenProps<{
2431 readonly reviewWorkingTreeScope ?: "staged" | "unstaged" ;
2532} > ;
2633
27- function ThreadWorkspaceScreen ( props : Props & { readonly initialTab : "files" | "git" } ) {
34+ function ThreadWorkspaceScreen ( props : Props ) {
2835 const navigation = useNavigation ( ) ;
29- const [ tab , setTab ] = useState ( props . initialTab ) ;
36+ const paneKey = JSON . stringify ( [ props . route . params . environmentId , props . route . params . threadId ] ) ;
37+ const [ tab , setTab ] = useState < WorkspacePane | null > ( ( ) =>
38+ props . route . params . path
39+ ? "files"
40+ : props . route . params . reviewSectionId
41+ ? "git"
42+ : readWorkspacePane ( paneKey ) ,
43+ ) ;
3044 const environmentId = EnvironmentId . make ( props . route . params . environmentId ) ;
3145 const threadId = ThreadId . make ( props . route . params . threadId ) ;
3246 const { selectedThreadCwd : cwd } = useSelectedThreadWorktree ( ) ;
@@ -46,16 +60,28 @@ function ThreadWorkspaceScreen(props: Props & { readonly initialTab: "files" | "
4660 // Status counts each changed path once, including edits that cancel between
4761 // the index and working tree, and updates through the existing Git subscription.
4862 const count = status . data ?. workingTree ?. files . length ;
63+ const statusUnavailable =
64+ ! access . isPending && ( ! access . canReadFiles || cwd === null || status . error !== null ) ;
65+ const selectedTab = resolveWorkspacePane ( tab , count ?? ( statusUnavailable ? 0 : undefined ) ) ;
66+ if ( selectedTab !== null && selectedTab !== tab ) {
67+ setTab ( selectedTab ) ;
68+ rememberWorkspacePane ( paneKey , selectedTab ) ;
69+ }
70+ const selectTab = ( pane : WorkspacePane ) => {
71+ setTab ( pane ) ;
72+ rememberWorkspacePane ( paneKey , pane ) ;
73+ } ;
4974 const tabs = (
50- < View className = "border-b border-border-subtle bg-sheet px-3 py-2" >
75+ < View className = "w-full border-b border-border-subtle bg-sheet px-3 py-2" >
5176 < SegmentedControl
5277 size = "compact"
78+ className = "w-full"
5379 options = { [
54- { value : "files" as const , label : "Files" } ,
5580 { value : "git" as const , label : "Git" , ...( count === undefined ? { } : { badge : count } ) } ,
81+ { value : "files" as const , label : "Files" } ,
5682 ] }
57- selected = { tab }
58- onSelect = { setTab }
83+ selected = { selectedTab ?? "files" }
84+ onSelect = { selectTab }
5985 role = "tab"
6086 />
6187 </ View >
@@ -64,7 +90,7 @@ function ThreadWorkspaceScreen(props: Props & { readonly initialTab: "files" | "
6490 < ReviewHeader
6591 environmentId = { environmentId }
6692 threadId = { threadId }
67- title = { tab === "files " ? "Files " : "Git " }
93+ title = { selectedTab === "git " ? "Git " : "Files " }
6894 subtitle = ""
6995 androidSubtitle = ""
7096 selectedThreadCwd = { cwd }
@@ -73,7 +99,17 @@ function ThreadWorkspaceScreen(props: Props & { readonly initialTab: "files" | "
7399 onReturnToThread = { ( ) => navigation . goBack ( ) }
74100 />
75101 ) ;
76- return tab === "files" ? (
102+ if ( selectedTab === null )
103+ return (
104+ < View className = "flex-1 bg-sheet" >
105+ { workspaceHeader }
106+ { tabs }
107+ < View className = "flex-1 items-center justify-center" >
108+ < AppActivityIndicator accessibilityLabel = "Loading workspace" />
109+ </ View >
110+ </ View >
111+ ) ;
112+ return selectedTab === "files" ? (
77113 props . route . params . path ? (
78114 < ThreadFileScreen
79115 route = { { params : { ...props . route . params , path : props . route . params . path } } }
@@ -110,7 +146,6 @@ export function ThreadFilesWorkspaceScreen(props: Props) {
110146 < ThreadWorkspaceScreen
111147 key = { `${ props . route . params . environmentId } :${ props . route . params . threadId } ` }
112148 { ...props }
113- initialTab = "files"
114149 />
115150 ) ;
116151}
@@ -120,7 +155,6 @@ export function ThreadGitWorkspaceScreen(props: Props) {
120155 < ThreadWorkspaceScreen
121156 key = { `${ props . route . params . environmentId } :${ props . route . params . threadId } ` }
122157 { ...props }
123- initialTab = "git"
124158 />
125159 ) ;
126160}
@@ -132,7 +166,6 @@ export function ThreadFileWorkspaceScreen(props: Parameters<typeof ThreadFileScr
132166 < ThreadWorkspaceScreen
133167 key = { `${ props . route . params . environmentId } :${ threadId } ` }
134168 route = { { params : { ...props . route . params , threadId } } }
135- initialTab = "files"
136169 />
137170 ) ;
138171}
0 commit comments