fix:新建项目更新项目选项
This commit is contained in:
@@ -20,7 +20,7 @@ export function ProjectManagementPage({
|
|||||||
onConnectionChange: (online: boolean) => void;
|
onConnectionChange: (online: boolean) => void;
|
||||||
}) {
|
}) {
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
const { user } = useAuth();
|
const { user, refreshWorkspaces } = useAuth();
|
||||||
const [projects, setProjects] = useState<Workspace[]>([]);
|
const [projects, setProjects] = useState<Workspace[]>([]);
|
||||||
const [projectLoading, setProjectLoading] = useState(true);
|
const [projectLoading, setProjectLoading] = useState(true);
|
||||||
const [projectDialogOpen, setProjectDialogOpen] = useState(false);
|
const [projectDialogOpen, setProjectDialogOpen] = useState(false);
|
||||||
@@ -107,6 +107,7 @@ export function ProjectManagementPage({
|
|||||||
description: projectForm.description.trim() || undefined,
|
description: projectForm.description.trim() || undefined,
|
||||||
});
|
});
|
||||||
setProjects((current) => [...current, created]);
|
setProjects((current) => [...current, created]);
|
||||||
|
void refreshWorkspaces();
|
||||||
onNotify({ tone: "success", message: "项目已创建" });
|
onNotify({ tone: "success", message: "项目已创建" });
|
||||||
}
|
}
|
||||||
setProjectDialogOpen(false);
|
setProjectDialogOpen(false);
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ type AuthContextValue = {
|
|||||||
login: (username: string, password: string) => Promise<void>;
|
login: (username: string, password: string) => Promise<void>;
|
||||||
logout: () => Promise<void>;
|
logout: () => Promise<void>;
|
||||||
setCurrentWorkspace: (workspaceId: string) => void;
|
setCurrentWorkspace: (workspaceId: string) => void;
|
||||||
|
refreshWorkspaces: () => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const AuthContext = createContext<AuthContextValue | null>(null);
|
const AuthContext = createContext<AuthContextValue | null>(null);
|
||||||
@@ -167,6 +168,23 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
window.localStorage.setItem(workspaceStorageKey, workspace.workspace_id);
|
window.localStorage.setItem(workspaceStorageKey, workspace.workspace_id);
|
||||||
}, [workspaces]);
|
}, [workspaces]);
|
||||||
|
|
||||||
|
const refreshWorkspaces = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const session = await authRequest<AuthSession>("/api/v1/auth/me");
|
||||||
|
const storedId = typeof window === "undefined"
|
||||||
|
? null
|
||||||
|
: window.localStorage.getItem(workspaceStorageKey);
|
||||||
|
const newWorkspace = selectWorkspace(session, storedId);
|
||||||
|
setWorkspaces(session.workspaces);
|
||||||
|
setWorkspace(newWorkspace);
|
||||||
|
if (newWorkspace && typeof window !== "undefined") {
|
||||||
|
window.localStorage.setItem(workspaceStorageKey, newWorkspace.workspace_id);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("刷新 workspace 列表失败:", error);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
const value = useMemo<AuthContextValue>(() => ({
|
const value = useMemo<AuthContextValue>(() => ({
|
||||||
user,
|
user,
|
||||||
workspaces,
|
workspaces,
|
||||||
@@ -175,7 +193,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
login,
|
login,
|
||||||
logout,
|
logout,
|
||||||
setCurrentWorkspace,
|
setCurrentWorkspace,
|
||||||
}), [currentWorkspace, loading, login, logout, setCurrentWorkspace, user, workspaces]);
|
refreshWorkspaces,
|
||||||
|
}), [currentWorkspace, loading, login, logout, setCurrentWorkspace, user, workspaces, refreshWorkspaces]);
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user