diff --git a/app/components/Article/index.tsx b/app/components/Article/index.tsx index b7639701..55a87627 100644 --- a/app/components/Article/index.tsx +++ b/app/components/Article/index.tsx @@ -49,7 +49,7 @@ const ArticleFooter = (question: Question) => { + ) + + const stopBubbling = (e: any) => { + e.preventDefault() + e.stopPropagation() + e.nativeEvent.stopImmediatePropagation() + } + return ( -
+
+
+ {showSettings && ( +
+
Answer detail
+ + + +
+ )} + setShowSettings((current) => !current)} + /> +
) diff --git a/app/routes/questions.$questionId.$.tsx b/app/routes/questions.$questionId.$.tsx index 57ea659f..f497fab5 100644 --- a/app/routes/questions.$questionId.$.tsx +++ b/app/routes/questions.$questionId.$.tsx @@ -9,11 +9,12 @@ import Error from '~/components/Error' import XIcon from '~/components/icons-generated/X' import ChevronRight from '~/components/icons-generated/ChevronRight' import {ArticlesNav} from '~/components/ArticlesNav/ArticleNav' -import {fetchGlossary} from '~/routes/questions.glossary' -import {loadQuestionDetail, loadTags} from '~/server-utils/stampy' +import {QuestionStatus, loadQuestionDetail} from '~/server-utils/stampy' import useToC from '~/hooks/useToC' -import type {Question, Glossary, Tag} from '~/server-utils/stampy' +import useGlossary from '~/hooks/useGlossary' +import type {Question, Tag} from '~/server-utils/stampy' import {reloadInBackgroundIfNeeded} from '~/server-utils/kv-cache' +import {useOnSiteQuestions, useTags} from '~/hooks/useCachedObjects' export const LINK_WITHOUT_DETAILS_CLS = 'link-without-details' @@ -27,11 +28,7 @@ export const loader = async ({request, params}: LoaderFunctionArgs) => { try { const dataPromise = loadQuestionDetail(request, questionId).catch(raise500) - const tagsPromise = loadTags(request) - .then(({data}) => data) - .catch(raise500) - - return defer({question: dataPromise, tags: tagsPromise}) + return defer({question: dataPromise}) } catch (error: unknown) { console.log(error) const msg = `No question found with ID ${questionId}. Please go to Discord and report where you found this link.` @@ -46,8 +43,8 @@ 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}), {}) +const updateTags = (question: Question, tags?: Tag[]) => { + const mappedTags = tags?.reduce((acc, t) => ({...acc, [t.name]: t}), {}) || {} return { ...question, tags: question.tags @@ -57,24 +54,32 @@ const updateTags = (question: Question, tags: Tag[]) => { } } +const updateRelated = (question: Question, allQuestions?: Question[]) => { + const live = + allQuestions + ?.filter(({status}) => status === QuestionStatus.LIVE_ON_SITE) + .map(({pageid}) => pageid) || [] + return { + ...question, + relatedQuestions: question.relatedQuestions.filter(({pageid}) => live.includes(pageid)), + } +} + +const updateFields = (question: Question, tags?: Tag[], allQuestions?: Question[]) => + updateTags(updateRelated(question, allQuestions), tags) + export default function RenderArticle() { const location = useLocation() - const [glossary, setGlossary] = useState({} as Glossary) const [showNav, setShowNav] = useState(false) // Used on mobile const params = useParams() + const {items: onSiteQuestions} = useOnSiteQuestions() + const {items: tags} = useTags() + const glossary = useGlossary() const pageid = params.questionId ?? '😱' - const {question, tags} = useLoaderData() + const {question} = useLoaderData() const {toc, findSection, getArticle, getPath} = useToC() const section = findSection(location?.state?.section || pageid) - useEffect(() => { - const getGlossary = async () => { - const {data} = await fetchGlossary() - setGlossary(data) - } - getGlossary() - }, [setGlossary]) - useEffect(() => { setShowNav(false) }, [location.key]) @@ -134,8 +139,8 @@ export default function RenderArticle() { /> } > - - {([resolvedQuestion, resolvedTags]) => { + + {(resolvedQuestion) => { if (resolvedQuestion instanceof Response || !('data' in resolvedQuestion)) { return } else if (!resolvedQuestion.data.pageid) { @@ -145,7 +150,11 @@ export default function RenderArticle() { } else { return (
diff --git a/app/server-utils/parsing-utils.ts b/app/server-utils/parsing-utils.ts index 1cb8b3df..c1d03b84 100644 --- a/app/server-utils/parsing-utils.ts +++ b/app/server-utils/parsing-utils.ts @@ -94,5 +94,5 @@ export const allLinksOnNewTab = (html: string): string => { // Open external links on new tab by using target="_blank", // pros&cons were extensively discussed in https://github.com/StampyAI/stampy-ui/issues/222 // internal links look like , so all absolute http links are treated as external - return html.replace(/( { return (