import {fetchPost} from "../../util/fetch";
import {unicode2Emoji} from "../../emoji";
import {Constants} from "../../constants";
import {escapeHtml} from "../../util/escape";
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
import {openModel} from "./model";
import {openMobileFileById} from "../editor";
export const getRecentDocs = () => {
fetchPost("/api/storage/getRecentDocs", {}, (response) => {
let html = "";
response.data.forEach((item: any, index: number) => {
html += `
${unicode2Emoji(item.icon || Constants.SIYUAN_IMAGE_FILE, false, "b3-list-item__graphic", true)}
${escapeHtml(item.title)}
`;
});
openModel({
title: window.siyuan.languages.recentDocs,
icon: "iconList",
html: ``,
bindEvent(element: HTMLElement) {
element.firstElementChild.addEventListener("click", (event) => {
const liElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item");
if (liElement) {
openMobileFileById(liElement.dataset.nodeId, [Constants.CB_GET_SCROLL])
}
});
}
})
});
}