chore: layout UI upgrade (#6577)

This commit is contained in:
Joel
2024-07-23 17:11:02 +08:00
committed by GitHub
parent ad7552ea8d
commit 6a9d202414
13 changed files with 51 additions and 19 deletions

View File

@@ -8,10 +8,13 @@ import { fetchAppList } from '@/service/apps'
import Loading from '@/app/components/base/loading'
import { fetchCurrentWorkspace, fetchLanggeniusVersion, fetchUserProfile } from '@/service/common'
import type { App } from '@/types/app'
import { Theme } from '@/types/app'
import type { ICurrentWorkspace, LangGeniusVersionResponse, UserProfileResponse } from '@/models/common'
import MaintenanceNotice from '@/app/components/header/maintenance-notice'
export type AppContextValue = {
theme: Theme
setTheme: (theme: Theme) => void
apps: App[]
mutateApps: VoidFunction
userProfile: UserProfileResponse
@@ -49,6 +52,8 @@ const initialWorkspaceInfo: ICurrentWorkspace = {
}
const AppContext = createContext<AppContextValue>({
theme: Theme.light,
setTheme: () => { },
apps: [],
mutateApps: () => { },
userProfile: {
@@ -112,11 +117,24 @@ export const AppContextProvider: FC<AppContextProviderProps> = ({ children }) =>
setCurrentWorkspace(currentWorkspaceResponse)
}, [currentWorkspaceResponse])
const [theme, setTheme] = useState<Theme>(Theme.light)
const handleSetTheme = useCallback((theme: Theme) => {
setTheme(theme)
globalThis.document.documentElement.setAttribute('data-theme', theme)
}, [])
useEffect(() => {
globalThis.document.documentElement.setAttribute('data-theme', theme)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
if (!appList || !userProfile)
return <Loading type='app' />
return (
<AppContext.Provider value={{
theme,
setTheme: handleSetTheme,
apps: appList.data,
mutateApps,
userProfile,
@@ -133,7 +151,7 @@ export const AppContextProvider: FC<AppContextProviderProps> = ({ children }) =>
}}>
<div className='flex flex-col h-full overflow-y-auto'>
{globalThis.document?.body?.getAttribute('data-public-maintenance-notice') && <MaintenanceNotice />}
<div ref={pageContainerRef} className='grow relative flex flex-col overflow-y-auto overflow-x-hidden bg-gray-100'>
<div ref={pageContainerRef} className='grow relative flex flex-col overflow-y-auto overflow-x-hidden bg-background-body'>
{children}
</div>
</div>