fix: workspace refresh
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
import { useAuth } from "../../context/AuthContext";
|
||||
import { useScriptWorkspaceStore } from "../platform/state/scriptWorkspaceStore";
|
||||
import { useUiStore } from "../platform/state/uiStore";
|
||||
import { SystemAdminPage } from "./SystemAdminPage";
|
||||
|
||||
export default function SystemAdminRoute() {
|
||||
const { currentWorkspace, user } = useAuth();
|
||||
const setApiOnline = useScriptWorkspaceStore((s) => s.setApiOnline);
|
||||
const pushToast = useUiStore((s) => s.pushToast);
|
||||
|
||||
return (
|
||||
<SystemAdminPage
|
||||
// 切换 workspace / 用户时强制重 mount,清空内部 state 并重新拉取
|
||||
key={`${user?.user_id ?? "anon"}-${currentWorkspace?.workspace_id ?? "none"}`}
|
||||
onNotify={pushToast}
|
||||
onConnectionChange={setApiOnline}
|
||||
/>
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import { useAuth } from "../../context/AuthContext";
|
||||
import { useScriptWorkspaceStore } from "../platform/state/scriptWorkspaceStore";
|
||||
import { useUiStore } from "../platform/state/uiStore";
|
||||
import SchedulePage from "./SchedulePage";
|
||||
|
||||
export default function SchedulesPageRoute() {
|
||||
const { currentWorkspace, user } = useAuth();
|
||||
const setApiOnline = useScriptWorkspaceStore((s) => s.setApiOnline);
|
||||
const pushToast = useUiStore((s) => s.pushToast);
|
||||
|
||||
return (
|
||||
<SchedulePage
|
||||
// 切换 workspace / 用户时强制重 mount,清空内部 state 并重新拉取
|
||||
key={`${user?.user_id ?? "anon"}-${currentWorkspace?.workspace_id ?? "none"}`}
|
||||
onNotify={pushToast}
|
||||
onConnectionChange={setApiOnline}
|
||||
/>
|
||||
|
||||
@@ -78,13 +78,16 @@ function AuthenticatedLayout() {
|
||||
|
||||
const [sidebarCollapsed, setSidebarCollapsed] = useState(false);
|
||||
|
||||
// 绑定 api 到 script workspace store
|
||||
useEffect(() => {
|
||||
// 绑定 api 到 script workspace store。
|
||||
// 必须放在 render body(同步),不能用 useEffect([api]) + cleanup —
|
||||
// 后者会在 deps 变化时先 cleanup(null),再让 ScriptsPage 的 useEffect 跑,
|
||||
// 此时 _api 为 null,load() 抛 "script workspace API 未绑定"。
|
||||
bindScriptWorkspaceApi(api);
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
bindScriptWorkspaceApi(null);
|
||||
};
|
||||
}, [api]);
|
||||
}, []);
|
||||
|
||||
// 心跳 / cleanup / 切页结束编辑 / 卸载前释放
|
||||
useEditSessionLifecycle({ activePage });
|
||||
|
||||
Reference in New Issue
Block a user