A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
feat(ui): add method to set header
robin7391cfcda161
diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.tsindex 3de63668..6b686d26 100644--- a/ui/src/common/interface.ts+++ b/ui/src/common/interface.ts@@ -280,6 +280,12 @@ export interface AdminSettingsGeneral {contact_email: string;}+export interface HeadInfo {+ title?: string;+ description?: string;+ keywords?: string;+}+export interface AdminSettingsInterface {language: string;theme: string;diff --git a/ui/src/hooks/index.ts b/ui/src/hooks/index.tsindex eaff57de..511f8012 100644--- a/ui/src/hooks/index.ts+++ b/ui/src/hooks/index.ts@@ -5,6 +5,7 @@ import usePageUsers from './usePageUsers';import useChangeModal from './useChangeModal';import useEditStatusModal from './useEditStatusModal';import useChangeUserRoleModal from './useChangeUserRoleModal';+import useHeadInfo from './useHeadInfo';export {useTagModal,@@ -14,4 +15,5 @@ export {useChangeModal,useEditStatusModal,useChangeUserRoleModal,+ useHeadInfo,};diff --git a/ui/src/hooks/useHeadInfo/index.tsx b/ui/src/hooks/useHeadInfo/index.tsxnew file mode 100644index 00000000..28887a01--- /dev/null+++ b/ui/src/hooks/useHeadInfo/index.tsx@@ -0,0 +1,12 @@+import { useEffect } from 'react';++import { HeadInfo } from '@/common/interface';+import { headInfoStore } from '@/stores';++export default function useHeadInfo(info: HeadInfo) {+ const { update } = headInfoStore.getState();++ useEffect(() => {+ update(info);+ }, [info]);+}diff --git a/ui/src/stores/headInfo.ts b/ui/src/stores/headInfo.tsnew file mode 100644index 00000000..d01e0e61--- /dev/null+++ b/ui/src/stores/headInfo.ts@@ -0,0 +1,27 @@+import create from 'zustand';++import { HeadInfo } from '@/common/interface';++interface HeadInfoType {+ headInfo: HeadInfo;+ update: (params: HeadInfo) => void;+}++const headInfo = create<HeadInfoType>((set) => ({+ headInfo: {+ title: '',+ description: '',+ keywords: '',+ },+ update: (params) =>+ set((state) => {+ return {+ headInfo: {+ ...state.headInfo,+ ...params,+ },+ };+ }),+}));++export default headInfo;diff --git a/ui/src/stores/index.ts b/ui/src/stores/index.tsindex 473bafbb..bb5f8226 100644--- a/ui/src/stores/index.ts+++ b/ui/src/stores/index.ts@@ -4,6 +4,7 @@ import globalStore from './global';import siteInfoStore from './siteInfo';import interfaceStore from './interface';import brandingStore from './branding';+import headInfoStore from './headInfo';export {toastStore,@@ -12,4 +13,5 @@ export {siteInfoStore,interfaceStore,brandingStore,+ headInfoStore,};diff --git a/ui/src/utils/common.ts b/ui/src/utils/common.tsindex 1b8ac340..19d05f2f 100644--- a/ui/src/utils/common.ts+++ b/ui/src/utils/common.ts@@ -1,5 +1,10 @@+import { useEffect } from 'react';+import i18next from 'i18next';+import { HeadInfo } from '@/common/interface';+import { headInfoStore } from '@/stores';+const Diff = require('diff');function thousandthDivision(num) {@@ -193,6 +198,15 @@ function diffText(newText: string, oldText: string): string {?.replace(/<input/gi, '<input');}+function useHeadInfo(info: HeadInfo) {+ const { update } = headInfoStore.getState();++ useEffect(() => {+ update(info);+ }, [info]);+ return null;+}+export {thousandthDivision,formatCount,@@ -206,4 +220,5 @@ export {labelStyle,handleFormError,diffText,+ useHeadInfo,};