From 08821d2342f1c980a8ee6c5a3f28cdc70d10737f Mon Sep 17 00:00:00 2001 From: Peter Hozak Date: Fri, 16 Aug 2024 09:55:35 +0200 Subject: [PATCH] hide in-progress banner in sub-sections #753 --- app/components/Article/index.tsx | 17 +++++++++++------ app/routes/questions.$questionId.$.tsx | 13 +++++++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/components/Article/index.tsx b/app/components/Article/index.tsx index cf7fa41e..8cea290a 100644 --- a/app/components/Article/index.tsx +++ b/app/components/Article/index.tsx @@ -149,6 +149,7 @@ type ArticleProps = { } export const Article = ({question, glossary, className}: ArticleProps) => { const {title, text, pageid} = question + console.debug('gg') return (
@@ -156,12 +157,16 @@ export const Article = ({question, glossary, className}: ArticleProps) => { {question.banners?.filter((b) => b.title).map(Banner)} - + {text ? ( + + ) : ( +
+ )} diff --git a/app/routes/questions.$questionId.$.tsx b/app/routes/questions.$questionId.$.tsx index 8776ca96..f36620bd 100644 --- a/app/routes/questions.$questionId.$.tsx +++ b/app/routes/questions.$questionId.$.tsx @@ -66,8 +66,15 @@ const updateRelated = (question: Question, allQuestions?: Question[]) => { } } -const updateFields = (question: Question, tags?: Tag[], allQuestions?: Question[]) => - updateTags(updateRelated(question, allQuestions), tags) +const updateBanners = (question: Question, hideBanners?: boolean) => + hideBanners ? {...question, banners: []} : question + +const updateFields = ( + question: Question, + hideBanners?: boolean, + tags?: Tag[], + allQuestions?: Question[] +) => updateTags(updateRelated(updateBanners(question, hideBanners), allQuestions), tags) export default function RenderArticle() { const location = useLocation() @@ -80,6 +87,7 @@ export default function RenderArticle() { const {question} = useLoaderData() const {toc, findSection, getArticle, getPath} = useToC() const section = findSection(location?.state?.section || pageid) + const hideBannersIfSubsection = section?.children?.some((c) => c.pageid === pageid) useEffect(() => { setShowNav(false) @@ -153,6 +161,7 @@ export default function RenderArticle() {