Skip to content

Commit

Permalink
chore: little loading
Browse files Browse the repository at this point in the history
  • Loading branch information
lajbel committed Nov 8, 2024
1 parent 59d8397 commit 473dafd
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/components/Doc/DocPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@ export const DocPreview = component$(() => {
useOnDocument(
"onSetDocPreview",
$(async (e: CustomEvent<number>) => {
const modalType = document.getElementById("modal-type");
if (!modalType) return;
const openInNew = document.getElementById("open-in-new");
if (!openInNew) return;
openInNew.setAttribute("href", "");

modalType.innerHTML = `<div class="loading loading-dots"></div>`;

// get html of the page
const page = await fetch(`/api/doc${e.detail}`);

const html = await page.text();
const parser = new DOMParser();
const typeDom = parser.parseFromString(html, "text/html");
const type = typeDom.querySelector("article");
if (!type) return;
const modalType = document.getElementById("modal-type");
if (!modalType) return;

modalType.innerHTML = "";
modalType.appendChild(type);

const openInNew = document.getElementById("open-in-new");
if (openInNew) {
openInNew.setAttribute("href", `/doc${e.detail}`);
}
openInNew.setAttribute("href", `/doc${e.detail}`);
}),
);

Expand All @@ -31,7 +34,6 @@ export const DocPreview = component$(() => {
<a
id="open-in-new"
class="btn btn-ghost"
href={`/api/doc/`}
target="_blank"
>
Open in new tab
Expand Down

0 comments on commit 473dafd

Please sign in to comment.