Skip to content

Commit

Permalink
Filter out internal tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mruwnik committed Feb 20, 2024
1 parent 063a19d commit cf31656
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions app/routes/questions.$questionId.$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {ArticlesNav} from '~/components/ArticlesNav/Menu'
import {fetchGlossary} from '~/routes/questions.glossary'
import {loadQuestionDetail, loadTags} from '~/server-utils/stampy'
import useToC from '~/hooks/useToC'
import type {Question, Glossary} from '~/server-utils/stampy'
import type {Question, Glossary, Tag} from '~/server-utils/stampy'
import {reloadInBackgroundIfNeeded} from '~/server-utils/kv-cache'

export const LINK_WITHOUT_DETAILS_CLS = 'link-without-details'
Expand Down Expand Up @@ -59,11 +59,22 @@ const dummyQuestion = (title: string | undefined) =>
tags: [],
}) as any as Question

const updateTags = (question: Question, tags: Tag[]) => {
const mappedTags = tags.reduce((acc, t) => ({...acc, [t.name]: t}), {})
return {
...question,
tags: question.tags
?.map((name) => mappedTags[name as keyof typeof mappedTags])
.filter((t?: Tag) => t && !t?.internal)
.map(({name}) => name),
}
}

export default function RenderArticle() {
const [glossary, setGlossary] = useState<Glossary>({} as Glossary)
const params = useParams()
const pageid = params.questionId ?? '😱'
const {data} = useLoaderData<typeof loader>()
const {data, tags} = useLoaderData<typeof loader>()
const {findSection, getArticle, getPath} = useToC()
const section = findSection(pageid)

Expand All @@ -83,16 +94,21 @@ export default function RenderArticle() {
key={pageid}
fallback={<Article question={dummyQuestion(getArticle(pageid)?.title)} />}
>
<Await resolve={data}>
{(resolvedValue) => {
<Await resolve={Promise.all([data, tags])}>
{([resolvedValue, tags]) => {
if (resolvedValue instanceof Response) {
return <Error error={resolvedValue} />
} else if (!(resolvedValue as any)?.pageid) {
return (
<Error error={{statusText: 'Could not fetch question', status: 'emptyArticle'}} />
)
} else {
return <Article question={resolvedValue as Question} glossary={glossary} />
return (
<Article
question={updateTags(resolvedValue as Question, tags as Tag[])}
glossary={glossary}
/>
)
}
}}
</Await>
Expand Down

0 comments on commit cf31656

Please sign in to comment.