From 119e063fee0db79f98f579cd187bddfc99fb285c Mon Sep 17 00:00:00 2001 From: FinnIckler Date: Thu, 12 Dec 2024 11:25:38 +0100 Subject: [PATCH] move markdown.jsx to use fetch --- app/webpacker/components/Markdown.jsx | 3 ++- app/webpacker/lib/utils/markdown.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 app/webpacker/lib/utils/markdown.js diff --git a/app/webpacker/components/Markdown.jsx b/app/webpacker/components/Markdown.jsx index 0bc792d688..9543b44a77 100644 --- a/app/webpacker/components/Markdown.jsx +++ b/app/webpacker/components/Markdown.jsx @@ -2,6 +2,7 @@ import React from 'react'; import { useQuery } from '@tanstack/react-query'; import DOMPurify from 'dompurify'; import Loading from './Requests/Loading'; +import renderMarkdownFetch from '../lib/utils/markdown'; /* @md: The markdown text as plain text @@ -13,7 +14,7 @@ export default function Markdown({ md, id = crypto.randomUUID() }) { isLoading, } = useQuery({ queryKey: ['markdown', id], - queryFn: () => window.wca.renderMarkdownRequest(md), + queryFn: () => renderMarkdownFetch(md), staleTime: Infinity, }); diff --git a/app/webpacker/lib/utils/markdown.js b/app/webpacker/lib/utils/markdown.js new file mode 100644 index 0000000000..2d9665bcd5 --- /dev/null +++ b/app/webpacker/lib/utils/markdown.js @@ -0,0 +1,14 @@ +import { fetchWithAuthenticityToken } from '../requests/fetchWithAuthenticityToken'; + +export default async function renderMarkdownFetch(markdownContent) { + const request = await fetchWithAuthenticityToken('/render_markdown', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + markdown_content: markdownContent, + }), + }); + return request.text(); +}