generated from pascalmartineau/wp-skeleton
wip: refactor sections
This commit is contained in:
@@ -3,11 +3,12 @@ import { createSSRApp, h } from "vue";
|
||||
import type { TheSectionFragment } from "#graphql-operations";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { fieldGroupName, ...attrs } = await readBody<TheSectionFragment>(event);
|
||||
try {
|
||||
const section = await readBody<TheSectionFragment>(event);
|
||||
const { component, attrs } = useSection(section);
|
||||
const app = createSSRApp({
|
||||
render() {
|
||||
return h(sectionsMap[fieldGroupName as FieldGroupName], attrs);
|
||||
return h(component, attrs);
|
||||
},
|
||||
});
|
||||
const html = await renderToString(app);
|
||||
|
||||
@@ -6659,7 +6659,7 @@ type GroupAbstractBuilder implements AcfFieldGroup & AcfFieldGroupFields & Group
|
||||
"""
|
||||
Field of the "flexible_content" Field Type added to the schema as part of the "GroupAbstractBuilder" Field Group
|
||||
"""
|
||||
sections: [GroupAbstractBuilderSections_Layout]!
|
||||
sections: [GroupAbstractBuilderSections_Layout]
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -6752,7 +6752,7 @@ interface GroupAbstractBuilder_Fields implements AcfFieldGroup & AcfFieldGroupFi
|
||||
"""
|
||||
Field of the "flexible_content" Field Type added to the schema as part of the "GroupAbstractBuilder" Field Group
|
||||
"""
|
||||
sections: [GroupAbstractBuilderSections_Layout]!
|
||||
sections: [GroupAbstractBuilderSections_Layout]
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -7363,7 +7363,7 @@ type GroupPostArticle implements AcfFieldGroup & AcfFieldGroupFields & GroupAbst
|
||||
"""
|
||||
Field of the "flexible_content" Field Type added to the schema as part of the "GroupAbstractBuilder" Field Group
|
||||
"""
|
||||
sections: [GroupAbstractBuilderSections_Layout]!
|
||||
sections: [GroupAbstractBuilderSections_Layout]
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -7376,7 +7376,7 @@ interface GroupPostArticle_Fields implements AcfFieldGroup & AcfFieldGroupFields
|
||||
"""
|
||||
Field of the "flexible_content" Field Type added to the schema as part of the "GroupAbstractBuilder" Field Group
|
||||
"""
|
||||
sections: [GroupAbstractBuilderSections_Layout]!
|
||||
sections: [GroupAbstractBuilderSections_Layout]
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -8177,7 +8177,7 @@ type GroupPostPage implements AcfFieldGroup & AcfFieldGroupFields & GroupAbstrac
|
||||
"""
|
||||
Field of the "flexible_content" Field Type added to the schema as part of the "GroupAbstractBuilder" Field Group
|
||||
"""
|
||||
sections: [GroupAbstractBuilderSections_Layout]!
|
||||
sections: [GroupAbstractBuilderSections_Layout]
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -8190,7 +8190,7 @@ interface GroupPostPage_Fields implements AcfFieldGroup & AcfFieldGroupFields &
|
||||
"""
|
||||
Field of the "flexible_content" Field Type added to the schema as part of the "GroupAbstractBuilder" Field Group
|
||||
"""
|
||||
sections: [GroupAbstractBuilderSections_Layout]!
|
||||
sections: [GroupAbstractBuilderSections_Layout]
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -8229,7 +8229,7 @@ type GroupPostProject implements AcfFieldGroup & AcfFieldGroupFields & GroupAbst
|
||||
"""
|
||||
Field of the "flexible_content" Field Type added to the schema as part of the "GroupAbstractBuilder" Field Group
|
||||
"""
|
||||
sections: [GroupAbstractBuilderSections_Layout]!
|
||||
sections: [GroupAbstractBuilderSections_Layout]
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -8294,7 +8294,7 @@ interface GroupPostProject_Fields implements AcfFieldGroup & AcfFieldGroupFields
|
||||
"""
|
||||
Field of the "flexible_content" Field Type added to the schema as part of the "GroupAbstractBuilder" Field Group
|
||||
"""
|
||||
sections: [GroupAbstractBuilderSections_Layout]!
|
||||
sections: [GroupAbstractBuilderSections_Layout]
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -8671,7 +8671,7 @@ type GroupPostTemplate implements AcfFieldGroup & AcfFieldGroupFields & GroupAbs
|
||||
"""
|
||||
Field of the "flexible_content" Field Type added to the schema as part of the "GroupAbstractBuilder" Field Group
|
||||
"""
|
||||
sections: [GroupAbstractBuilderSections_Layout]!
|
||||
sections: [GroupAbstractBuilderSections_Layout]
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -8684,7 +8684,7 @@ interface GroupPostTemplate_Fields implements AcfFieldGroup & AcfFieldGroupField
|
||||
"""
|
||||
Field of the "flexible_content" Field Type added to the schema as part of the "GroupAbstractBuilder" Field Group
|
||||
"""
|
||||
sections: [GroupAbstractBuilderSections_Layout]!
|
||||
sections: [GroupAbstractBuilderSections_Layout]
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -25068,9 +25068,6 @@ enum UserRoleEnum {
|
||||
|
||||
"""User role with specific capabilities"""
|
||||
SUBSCRIBER
|
||||
|
||||
"""User role with specific capabilities"""
|
||||
TRANSLATOR
|
||||
}
|
||||
|
||||
"""Connection between the User type and the Comment type"""
|
||||
|
||||
12
wp-content/themes/ccat/server/utils/useSection.ts
Normal file
12
wp-content/themes/ccat/server/utils/useSection.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { TheSectionFragment } from "#graphql-operations";
|
||||
import SectionTextBlock from "~/components/sections/SectionTextBlock.vue";
|
||||
|
||||
const sections = {
|
||||
GroupAbstractBuilderSectionsTextBlockLayout: SectionTextBlock,
|
||||
} as const;
|
||||
|
||||
export function useSection({ fieldGroupName, ...attrs }: TheSectionFragment) {
|
||||
const component = sections[fieldGroupName as keyof typeof sections];
|
||||
if (!component) throw createError({ statusCode: 500, statusMessage: "Erreur interne", message: "Type de section invalide." });
|
||||
return { component, attrs };
|
||||
}
|
||||
Reference in New Issue
Block a user