|
|
@@ -1,3 +1,5 @@
|
|
|
+import { ReactNode } from 'react';
|
|
|
+
|
|
|
import type { GetServerSideProps, GetServerSidePropsContext } from 'next';
|
|
|
import { useTranslation } from 'next-i18next';
|
|
|
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
|
|
|
@@ -8,24 +10,18 @@ import SearchResultLayout from '~/components/Layout/SearchResultLayout';
|
|
|
import { DrawioViewerScript } from '~/components/Script/DrawioViewerScript';
|
|
|
import type { CrowiRequest } from '~/interfaces/crowi-request';
|
|
|
import type { RendererConfig } from '~/interfaces/services/renderer';
|
|
|
-import type { ISidebarConfig } from '~/interfaces/sidebar-config';
|
|
|
import type { IUser, IUserHasId } from '~/interfaces/user';
|
|
|
-import type { IUserUISettings } from '~/interfaces/user-ui-settings';
|
|
|
-import type { UserUISettingsModel } from '~/server/models/user-ui-settings';
|
|
|
import {
|
|
|
useCsrfToken, useCurrentUser, useDrawioUri, useIsContainerFluid, useIsSearchPage, useIsSearchScopeChildrenAsDefault,
|
|
|
useIsSearchServiceConfigured, useIsSearchServiceReachable, useRendererConfig, useShowPageLimitationL,
|
|
|
} from '~/stores/context';
|
|
|
-import {
|
|
|
- usePreferDrawerModeByUser, usePreferDrawerModeOnEditByUser, useSidebarCollapsed,
|
|
|
- useCurrentSidebarContents, useCurrentProductNavWidth,
|
|
|
-} from '~/stores/ui';
|
|
|
|
|
|
import { SearchPage } from '../components/SearchPage';
|
|
|
|
|
|
import type { NextPageWithLayout } from './_app.page';
|
|
|
+import type { CommonProps } from './utils/commons';
|
|
|
import {
|
|
|
- getNextI18NextConfig, getServerSideCommonProps, generateCustomTitle, CommonProps, useInitSidebarConfig,
|
|
|
+ getNextI18NextConfig, getServerSideCommonProps, generateCustomTitle, useInitSidebarConfig,
|
|
|
} from './utils/commons';
|
|
|
|
|
|
|
|
|
@@ -38,11 +34,6 @@ type Props = CommonProps & {
|
|
|
|
|
|
drawioUri: string | null,
|
|
|
|
|
|
- // UI
|
|
|
- userUISettings?: IUserUISettings
|
|
|
- // Sidebar
|
|
|
- sidebarConfig: ISidebarConfig,
|
|
|
-
|
|
|
// Render config
|
|
|
rendererConfig: RendererConfig,
|
|
|
|
|
|
@@ -54,8 +45,6 @@ type Props = CommonProps & {
|
|
|
};
|
|
|
|
|
|
const SearchResultPage: NextPageWithLayout<Props> = (props: Props) => {
|
|
|
- const { userUISettings } = props;
|
|
|
-
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
// commons
|
|
|
@@ -102,28 +91,30 @@ const SearchResultPage: NextPageWithLayout<Props> = (props: Props) => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+type LayoutProps = Props & {
|
|
|
+ children?: ReactNode
|
|
|
+}
|
|
|
+
|
|
|
+const Layout = ({ children, ...props }: LayoutProps): JSX.Element => {
|
|
|
+ // init sidebar config with UserUISettings and sidebarConfig
|
|
|
+ useInitSidebarConfig(props.sidebarConfig, props.userUISettings);
|
|
|
+
|
|
|
+ return (
|
|
|
+ <SearchResultLayout>
|
|
|
+ {children}
|
|
|
+ </SearchResultLayout>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
SearchResultPage.getLayout = function getLayout(page) {
|
|
|
return (
|
|
|
<>
|
|
|
<DrawioViewerScript />
|
|
|
- <SearchResultLayout>{page}</SearchResultLayout>
|
|
|
+ <Layout {...page.props}>{page}</Layout>
|
|
|
</>
|
|
|
);
|
|
|
};
|
|
|
|
|
|
-async function injectUserUISettings(context: GetServerSidePropsContext, props: Props): Promise<void> {
|
|
|
- const { model: mongooseModel } = await import('mongoose');
|
|
|
-
|
|
|
- const req = context.req as CrowiRequest<IUserHasId & any>;
|
|
|
- const { user } = req;
|
|
|
-
|
|
|
- const UserUISettings = mongooseModel('UserUISettings') as UserUISettingsModel;
|
|
|
- const userUISettings = user == null ? null : await UserUISettings.findOne({ user: user._id }).exec();
|
|
|
- if (userUISettings != null) {
|
|
|
- props.userUISettings = userUISettings.toObject();
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
function injectServerConfigurations(context: GetServerSidePropsContext, props: Props): void {
|
|
|
const req: CrowiRequest = context.req as CrowiRequest;
|
|
|
const { crowi } = req;
|
|
|
@@ -190,7 +181,6 @@ export const getServerSideProps: GetServerSideProps = async(context: GetServerSi
|
|
|
props.currentUser = user.toObject();
|
|
|
}
|
|
|
|
|
|
- await injectUserUISettings(context, props);
|
|
|
injectServerConfigurations(context, props);
|
|
|
await injectNextI18NextConfigurations(context, props, ['translation']);
|
|
|
|