|
|
@@ -1,7 +1,7 @@
|
|
|
import React, { useState, useCallback } from 'react';
|
|
|
|
|
|
import type { IUser, IUserHasId } from '@growi/core';
|
|
|
-import { GetServerSideProps, GetServerSidePropsContext } from 'next';
|
|
|
+import { NextPage, GetServerSideProps, GetServerSidePropsContext } from 'next';
|
|
|
import { useTranslation } from 'next-i18next';
|
|
|
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
|
|
|
import dynamic from 'next/dynamic';
|
|
|
@@ -9,8 +9,14 @@ import Head from 'next/head';
|
|
|
|
|
|
import type { CrowiRequest } from '~/interfaces/crowi-request';
|
|
|
import type { RendererConfig } from '~/interfaces/services/renderer';
|
|
|
+import type { ISidebarConfig } from '~/interfaces/sidebar-config';
|
|
|
import type { IDataTagCount } from '~/interfaces/tag';
|
|
|
+import type { IUserUISettings } from '~/interfaces/user-ui-settings';
|
|
|
+import type { UserUISettingsModel } from '~/server/models/user-ui-settings';
|
|
|
import { useSWRxTagsList } from '~/stores/tag';
|
|
|
+import {
|
|
|
+ usePreferDrawerModeByUser, usePreferDrawerModeOnEditByUser, useSidebarCollapsed, useCurrentSidebarContents, useCurrentProductNavWidth,
|
|
|
+} from '~/stores/ui';
|
|
|
|
|
|
import { BasicLayout } from '../components/Layout/BasicLayout';
|
|
|
import {
|
|
|
@@ -21,7 +27,7 @@ import {
|
|
|
|
|
|
import { NextPageWithLayout } from './_app.page';
|
|
|
import {
|
|
|
- CommonProps, getServerSideCommonProps, getNextI18NextConfig, generateCustomTitle,
|
|
|
+ CommonProps, getServerSideCommonProps, getNextI18NextConfig, generateCustomTitle, useInitSidebarConfig,
|
|
|
} from './utils/commons';
|
|
|
|
|
|
const PAGING_LIMIT = 10;
|
|
|
@@ -32,6 +38,12 @@ type Props = CommonProps & {
|
|
|
isSearchServiceReachable: boolean,
|
|
|
isSearchScopeChildrenAsDefault: boolean,
|
|
|
|
|
|
+ // ui
|
|
|
+ userUISettings?: IUserUISettings
|
|
|
+
|
|
|
+ // sidebar
|
|
|
+ sidebarConfig: ISidebarConfig,
|
|
|
+
|
|
|
rendererConfig: RendererConfig,
|
|
|
};
|
|
|
|
|
|
@@ -60,6 +72,9 @@ const TagPage: NextPageWithLayout<CommonProps> = (props: Props) => {
|
|
|
useIsSearchServiceReachable(props.isSearchServiceReachable);
|
|
|
useIsSearchScopeChildrenAsDefault(props.isSearchScopeChildrenAsDefault);
|
|
|
|
|
|
+ // init sidebar config with UserUISettings and sidebarConfig
|
|
|
+ useInitSidebarConfig(props.sidebarConfig, props.userUISettings);
|
|
|
+
|
|
|
useRendererConfig(props.rendererConfig);
|
|
|
|
|
|
const title = generateCustomTitle(props, t('Tags'));
|
|
|
@@ -106,6 +121,20 @@ TagPage.getLayout = function getLayout(page) {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+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;
|
|
|
@@ -165,6 +194,7 @@ export const getServerSideProps: GetServerSideProps = async(context: GetServerSi
|
|
|
props.currentUser = user.toObject();
|
|
|
}
|
|
|
|
|
|
+ await injectUserUISettings(context, props);
|
|
|
injectServerConfigurations(context, props);
|
|
|
await injectNextI18NextConfigurations(context, props, ['translation']);
|
|
|
|