Просмотр исходного кода

fetch tags data when page is null

kaori 3 лет назад
Родитель
Сommit
4069cc4aaf
2 измененных файлов с 3 добавлено и 2 удалено
  1. 1 0
      packages/app/src/server/routes/page.js
  2. 2 2
      packages/app/src/stores/page.tsx

+ 1 - 0
packages/app/src/server/routes/page.js

@@ -319,6 +319,7 @@ module.exports = function(crowi, app) {
       // retrieve templates
       if (req.user != null) {
         const template = await Page.findTemplate(path);
+
         if (template.templateBody) {
           const body = replacePlaceholdersOfTemplate(template.templateBody, req);
           const tags = template.templateTags;

+ 2 - 2
packages/app/src/stores/page.tsx

@@ -97,7 +97,7 @@ export const useSWRxDescendantsPageListForCurrrentPath = (pageNumber?: number):
 
 
 export const useSWRxTagsInfo = (pageId: Nullable<string>): SWRResponse<IPageTagsInfo | undefined, Error> => {
-  const key = pageId == null ? null : `/pages.getPageTag?pageId=${pageId}`;
+  const key = pageId == null ? 'tmpPage' : `/pages.getPageTag?pageId=${pageId}`;
 
   const { data: templateTagData } = useTemplateTagData();
   const { data: shareLinkId } = useShareLinkId();
@@ -113,7 +113,7 @@ export const useSWRxTagsInfo = (pageId: Nullable<string>): SWRResponse<IPageTags
       const res = await apiGet<IPageTagsInfo>(endpoint, { pageId });
       tags = res?.tags;
     }
-    // when the page does not exist
+    // when templates applicable to the new page
     else if (templateTagData != null) {
       tags = templateTagData.split(',').filter((str: string) => {
         return str !== ''; // filter empty values