fix(projects): make freshly-added projects editable
Make workspace-less projects flow through aggregated project fetching and keep the settings screen editable immediately after adding one.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { useCallback } from "react";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useHostRuntimeClient, useHostRuntimeIsConnected } from "@/runtime/host-runtime";
|
||||
import { projectsQueryKey } from "@/hooks/use-projects";
|
||||
import { useSessionStore } from "@/stores/session-store";
|
||||
import { openProjectDirectly, type OpenProjectResult } from "@/hooks/open-project";
|
||||
|
||||
@@ -9,6 +11,7 @@ export function useOpenProject(
|
||||
const normalizedServerId = serverId?.trim() ?? "";
|
||||
const client = useHostRuntimeClient(normalizedServerId);
|
||||
const isConnected = useHostRuntimeIsConnected(normalizedServerId);
|
||||
const queryClient = useQueryClient();
|
||||
const canAddProject = useSessionStore((state) =>
|
||||
normalizedServerId
|
||||
? state.sessions[normalizedServerId]?.serverInfo?.features?.projectAdd === true
|
||||
@@ -19,7 +22,7 @@ export function useOpenProject(
|
||||
|
||||
return useCallback(
|
||||
async (path: string) => {
|
||||
return openProjectDirectly({
|
||||
const result = await openProjectDirectly({
|
||||
serverId: normalizedServerId,
|
||||
projectPath: path,
|
||||
isConnected,
|
||||
@@ -28,6 +31,14 @@ export function useOpenProject(
|
||||
addEmptyProject,
|
||||
setHasHydratedWorkspaces,
|
||||
});
|
||||
// The aggregated projects query derives the project list from a fetch
|
||||
// that now includes empty projects; refetch so a freshly-added project
|
||||
// (no workspace yet) is immediately editable instead of only after a
|
||||
// restart.
|
||||
if (result.ok) {
|
||||
void queryClient.invalidateQueries({ queryKey: projectsQueryKey });
|
||||
}
|
||||
return result;
|
||||
},
|
||||
[
|
||||
addEmptyProject,
|
||||
@@ -35,6 +46,7 @@ export function useOpenProject(
|
||||
client,
|
||||
isConnected,
|
||||
normalizedServerId,
|
||||
queryClient,
|
||||
setHasHydratedWorkspaces,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -169,7 +169,7 @@ export function useSidebarWorkspacesList(options?: {
|
||||
void (async () => {
|
||||
const next = new Map<string, WorkspaceDescriptor>();
|
||||
try {
|
||||
const workspaces = await fetchAllWorkspaceDescriptors({
|
||||
const { workspaces, emptyProjects } = await fetchAllWorkspaceDescriptors({
|
||||
client,
|
||||
sort: [{ key: "activity_at", direction: "desc" }],
|
||||
});
|
||||
@@ -181,6 +181,9 @@ export function useSidebarWorkspacesList(options?: {
|
||||
}
|
||||
const store = useSessionStore.getState();
|
||||
store.setWorkspaces(serverId, next);
|
||||
// Keep parents with no workspaces yet, so a manual refresh doesn't drop
|
||||
// a freshly-added project from the sidebar.
|
||||
store.setEmptyProjects(serverId, emptyProjects);
|
||||
store.setHasHydratedWorkspaces(serverId, true);
|
||||
} catch (error) {
|
||||
console.error("[WorkspaceFetch][sidebar-refresh] failed", {
|
||||
|
||||
Reference in New Issue
Block a user