Skip to content

Commit

Permalink
move markdown.jsx to use fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
FinnIckler committed Dec 12, 2024
1 parent f3ce4bb commit 119e063
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/webpacker/components/Markdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
});

Expand Down
14 changes: 14 additions & 0 deletions app/webpacker/lib/utils/markdown.js
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 119e063

Please sign in to comment.