From 4be5fb4d3de7dbfa2c4395cc515b8e7528c2a4ab Mon Sep 17 00:00:00 2001 From: jialin Date: Thu, 7 May 2026 18:25:49 +0800 Subject: [PATCH] feat: add use current user --- src/hooks/use-current-user.ts | 11 +++++++++++ src/layouts/extraRender.tsx | 6 +----- src/layouts/index.tsx | 24 +++++------------------- 3 files changed, 17 insertions(+), 24 deletions(-) create mode 100644 src/hooks/use-current-user.ts diff --git a/src/hooks/use-current-user.ts b/src/hooks/use-current-user.ts new file mode 100644 index 00000000..ac66da8b --- /dev/null +++ b/src/hooks/use-current-user.ts @@ -0,0 +1,11 @@ +import { useModel } from '@@/plugin-model'; + +export default function useCurrentUser() { + const cu = useModel?.('@@initialState')?.initialState?.currentUser; + if (!cu) return undefined; + return { + ...cu, + fullName: cu.full_name ?? cu.fullName, + isAdmin: cu.is_admin ?? cu.isAdmin + }; +} diff --git a/src/layouts/extraRender.tsx b/src/layouts/extraRender.tsx index a9a6a511..988d0625 100644 --- a/src/layouts/extraRender.tsx +++ b/src/layouts/extraRender.tsx @@ -119,11 +119,7 @@ export const ExtraContent = (props: { isDarkTheme?: boolean }) => { }; const { initialState } = initialInfo; - const GlobalSettings = pluginManager?.components?.GlobalSettings; - // Plugin slot. A registered plugin can supply an Org switcher via - // components.OrgSwitcher; the host renders nothing when no plugin - // provides it. - const OrgSwitcher = pluginManager?.components?.OrgSwitcher; + const { GlobalSettings, OrgSwitcher } = pluginManager?.components || {}; console.log('plugin+++++++++', pluginManager); const navigate = useNavigate(); diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index 2b831777..df8d947b 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -4,6 +4,7 @@ import DarkMask from '@/components/dark-mask'; import routeCachekey from '@/config/route-cachekey'; import { DEFAULT_ENTER_PAGE, GPUSTACK_API_BASE_URL } from '@/config/settings'; import { COLOR_PRIMARY } from '@/config/theme'; +import useCurrentUser from '@/hooks/use-current-user'; import useUserSettings from '@/hooks/use-user-settings'; import useUserSettingsStorage from '@/hooks/use-user-settings-storage'; import useAddResource from '@/pages/dashboard/hooks/use-add-resource'; @@ -133,7 +134,6 @@ export default (props: any) => { }); const [, contextHolder] = Modal.useModal(); const { themeData, setUserSettings, userSettings } = useUserSettings(); - const userSettingsStorage = useUserSettingsStorage(); const [userInfo] = useAtom(userAtom); const [routeCache] = useAtom(routeCacheAtom); const location = useLocation(); @@ -346,24 +346,10 @@ export default (props: any) => { defaultColorPrimary: COLOR_PRIMARY }} hooks={{ - useUserSettings: useUserSettings, - useUserSettingsStorage: () => userSettingsStorage, - useIntl: useIntl, - // Bridge umi's `@@initialState` model so plugins consuming - // `useCurrentUser` from @gpustack/core-ui get the signed-in - // user without depending on @umijs/max directly. Translate - // the host's snake_case fields to core-ui's camelCase - // `CurrentUser` shape, but pass everything else through so - // hosts can carry extra fields. - useCurrentUser: () => { - const cu = useModel?.('@@initialState')?.initialState?.currentUser; - if (!cu) return undefined; - return { - ...cu, - fullName: cu.full_name ?? cu.fullName, - isAdmin: cu.is_admin ?? cu.isAdmin - }; - } + useUserSettings, + useUserSettingsStorage, + useIntl, + useCurrentUser }} i18n={intl} locale={{