fix(mobile): sync project switch with draft target state (#1307)
When a new session draft is open on mobile and the user switches projects via the ProjectBar, the draft target was not updated, causing a mismatch with the desktop project/branch selectors. handleProjectSwitch now mirrors the desktop handleDraftProjectChange: when a draft is open, it uses setActiveProjectIdOnly + setNewSessionDraftTarget instead of setActiveProject. The draft is also guarded against preserveDirectoryOverride to prevent overwriting a worktree-locked directory. When no draft is open, the original setActiveProject behavior is preserved. Co-authored-by: Jovines <jovines@qq.com>
This commit is contained in:
committed by
GitHub
co-authored by
Jovines
parent
fbffce4fdf
commit
7582db6df6
@@ -1436,6 +1436,7 @@ export const MobileSessionStatusBar: React.FC<MobileSessionStatusBarProps> = ({
|
||||
const projects = useProjectsStore((state) => state.projects);
|
||||
const activeProjectId = useProjectsStore((state) => state.activeProjectId);
|
||||
const setActiveProject = useProjectsStore((state) => state.setActiveProject);
|
||||
const setActiveProjectIdOnly = useProjectsStore((state) => state.setActiveProjectIdOnly);
|
||||
const removeProject = useProjectsStore((state) => state.removeProject);
|
||||
const getActiveProject = useProjectsStore((state) => state.getActiveProject);
|
||||
|
||||
@@ -1498,9 +1499,29 @@ export const MobileSessionStatusBar: React.FC<MobileSessionStatusBarProps> = ({
|
||||
};
|
||||
|
||||
const handleProjectSwitch = (projectId: string) => {
|
||||
if (projectId !== activeProjectId) {
|
||||
setActiveProject(projectId);
|
||||
if (projectId === activeProjectId) {
|
||||
return;
|
||||
}
|
||||
const draft = useSessionUIStore.getState().newSessionDraft;
|
||||
if (draft?.open) {
|
||||
if (
|
||||
draft.pendingWorktreeRequestId ||
|
||||
draft.bootstrapPendingDirectory ||
|
||||
draft.preserveDirectoryOverride
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const project = projects.find((p) => p.id === projectId);
|
||||
if (project) {
|
||||
setActiveProjectIdOnly(projectId);
|
||||
useSessionUIStore.getState().setNewSessionDraftTarget({
|
||||
projectId,
|
||||
directoryOverride: project.path,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
setActiveProject(projectId);
|
||||
};
|
||||
|
||||
const handleAddProject = () => {
|
||||
|
||||
Reference in New Issue
Block a user