@@ -29,7 +29,7 @@ import { useAuthStore } from "@renderer/features/auth/stores/authStore";
2929import { useTRPC } from "@renderer/trpc/client" ;
3030import { useNavigationStore } from "@stores/navigationStore" ;
3131import { useQuery } from "@tanstack/react-query" ;
32- import { useCallback , useEffect , useRef , useState } from "react" ;
32+ import { useCallback , useEffect , useMemo , useRef , useState } from "react" ;
3333import { useHotkeys } from "react-hotkeys-hook" ;
3434import { usePreviewConfig } from "../hooks/usePreviewConfig" ;
3535import { useTaskCreation } from "../hooks/useTaskCreation" ;
@@ -59,6 +59,8 @@ export function TaskInput({
5959 setLastUsedWorkspaceMode,
6060 lastUsedAdapter,
6161 setLastUsedAdapter,
62+ lastUsedCloudRepository,
63+ setLastUsedCloudRepository,
6264 allowBypassPermissions,
6365 setLastUsedEnvironment,
6466 getLastUsedEnvironment,
@@ -103,13 +105,18 @@ export function TaskInput({
103105 const { githubIntegration, repositories, isLoadingRepos } =
104106 useRepositoryIntegration ( ) ;
105107 const [ selectedRepository , setSelectedRepository ] = useState < string | null > (
106- null ,
108+ ( ) => lastUsedCloudRepository ?. toLowerCase ( ) ?? null ,
107109 ) ;
110+ const selectedCloudRepository = useMemo ( ( ) => {
111+ if ( ! selectedRepository ) return null ;
112+ const lower = selectedRepository . toLowerCase ( ) ;
113+ return repositories . includes ( lower ) ? lower : null ;
114+ } , [ selectedRepository , repositories ] ) ;
108115 const { currentBranch, branchLoading, defaultBranch } =
109116 useGitQueries ( selectedDirectory ) ;
110117
111118 const { data : cloudBranchData , isPending : cloudBranchesLoading } =
112- useGithubBranches ( githubIntegration ?. id , selectedRepository ) ;
119+ useGithubBranches ( githubIntegration ?. id , selectedCloudRepository ) ;
113120 const cloudBranches = cloudBranchData ?. branches ;
114121 const cloudDefaultBranch = cloudBranchData ?. defaultBranch ?? null ;
115122
@@ -149,6 +156,15 @@ export function TaskInput({
149156 }
150157 } , [ selectedDirectory , newBranchName , gitActions ] ) ;
151158
159+ const handleRepositorySelect = useCallback (
160+ ( repo : string ) => {
161+ const normalizedRepo = repo . toLowerCase ( ) ;
162+ setSelectedRepository ( normalizedRepo ) ;
163+ setLastUsedCloudRepository ( normalizedRepo ) ;
164+ } ,
165+ [ setLastUsedCloudRepository ] ,
166+ ) ;
167+
152168 const {
153169 modeOption,
154170 modelOption,
@@ -159,6 +175,37 @@ export function TaskInput({
159175
160176 const { folders } = useFolders ( ) ;
161177
178+ useEffect ( ( ) => {
179+ if ( selectedRepository || ! lastUsedCloudRepository ) {
180+ return ;
181+ }
182+
183+ setSelectedRepository ( lastUsedCloudRepository . toLowerCase ( ) ) ;
184+ } , [ lastUsedCloudRepository , selectedRepository ] ) ;
185+
186+ useEffect ( ( ) => {
187+ if (
188+ isLoadingRepos ||
189+ ! githubIntegration ||
190+ ! selectedRepository ||
191+ selectedCloudRepository
192+ ) {
193+ return ;
194+ }
195+
196+ setSelectedRepository ( null ) ;
197+ if ( lastUsedCloudRepository === selectedRepository ) {
198+ setLastUsedCloudRepository ( null ) ;
199+ }
200+ } , [
201+ githubIntegration ,
202+ isLoadingRepos ,
203+ lastUsedCloudRepository ,
204+ selectedCloudRepository ,
205+ selectedRepository ,
206+ setLastUsedCloudRepository ,
207+ ] ) ;
208+
162209 useEffect ( ( ) => {
163210 if ( view . folderId ) {
164211 const folder = folders . find ( ( f ) => f . id === view . folderId ) ;
@@ -169,7 +216,7 @@ export function TaskInput({
169216 } , [ view . folderId , folders ] ) ;
170217
171218 const effectiveRepoPath =
172- workspaceMode === "cloud" ? selectedRepository : selectedDirectory ;
219+ workspaceMode === "cloud" ? selectedCloudRepository : selectedDirectory ;
173220
174221 const setSelectedEnvironment = useCallback (
175222 ( envId : string | null ) => {
@@ -183,6 +230,7 @@ export function TaskInput({
183230
184231 useEffect ( ( ) => {
185232 setSelectedBranch ( null ) ;
233+
186234 if ( effectiveRepoPath ) {
187235 setSelectedEnvironmentRaw ( getLastUsedEnvironment ( effectiveRepoPath ) ) ;
188236 } else {
@@ -212,7 +260,7 @@ export function TaskInput({
212260 const { isCreatingTask, canSubmit, handleSubmit } = useTaskCreation ( {
213261 editorRef,
214262 selectedDirectory,
215- selectedRepository,
263+ selectedRepository : selectedCloudRepository ,
216264 githubIntegrationId : githubIntegration ?. id ,
217265 workspaceMode : effectiveWorkspaceMode ,
218266 branch : branchForTaskCreation ,
@@ -373,7 +421,7 @@ export function TaskInput({
373421 { workspaceMode === "cloud" ? (
374422 < GitHubRepoPicker
375423 value = { selectedRepository }
376- onChange = { setSelectedRepository }
424+ onChange = { handleRepositorySelect }
377425 repositories = { repositories }
378426 isLoading = { isLoadingRepos }
379427 placeholder = "Select repository..."
@@ -398,7 +446,7 @@ export function TaskInput({
398446 < BranchSelector
399447 repoPath = {
400448 workspaceMode === "cloud"
401- ? selectedRepository
449+ ? selectedCloudRepository
402450 : selectedDirectory
403451 }
404452 currentBranch = { currentBranch }
@@ -407,7 +455,7 @@ export function TaskInput({
407455 }
408456 disabled = {
409457 isCreatingTask ||
410- ( workspaceMode === "cloud" && ! selectedRepository )
458+ ( workspaceMode === "cloud" && ! selectedCloudRepository )
411459 }
412460 loading = { branchLoading }
413461 workspaceMode = { workspaceMode }
@@ -446,7 +494,7 @@ export function TaskInput({
446494 onSubmit = { handleSubmit }
447495 hasDirectory = {
448496 workspaceMode === "cloud"
449- ? ! ! selectedRepository
497+ ? ! ! selectedCloudRepository
450498 : ! ! selectedDirectory
451499 }
452500 directoryTooltip = {
0 commit comments