diff --git a/app/src/history/history.ts b/app/src/history/history.ts
index 24723c039..cdf26d67b 100644
--- a/app/src/history/history.ts
+++ b/app/src/history/history.ts
@@ -80,16 +80,16 @@ const renderRepoItem = (response: IWebSocketData, element: Element, type: string
return;
}
let actionHTML = "";
- if (type === "cloudTag") {
+ if (type === "getCloudRepoTagSnapshots") {
actionHTML = `
`;
- } else if (type === "cloud") {
+ } else if (type === "getCloudRepoSnapshots") {
actionHTML = ``;
- } else if (type === "localTag") {
+ } else if (type === "getRepoTagSnapshots") {
actionHTML = `
`;
- } else if (type === "local") {
+ } else if (type === "getRepoSnapshots") {
actionHTML = `
`;
}
@@ -133,47 +133,33 @@ const renderRepoItem = (response: IWebSocketData, element: Element, type: string
};
const renderRepo = (element: Element, currentPage: number) => {
+ const selectValue = (element.querySelector(".b3-select") as HTMLSelectElement).value
element.lastElementChild.innerHTML = '
';
const previousElement = element.querySelector('[data-type="previous"]');
const nextElement = element.querySelector('[data-type="next"]');
- if (currentPage < 0) {
- if (currentPage === -1) {
- fetchPost("/api/repo/getRepoTagSnapshots", {}, (response) => {
- renderRepoItem(response, element, "localTag");
- });
- } else if (currentPage === -2) {
- fetchPost("/api/repo/getCloudRepoTagSnapshots", {}, (response) => {
- renderRepoItem(response, element, "cloudTag");
- });
- } else if (currentPage === -3) {
- fetchPost("/api/repo/getCloudRepoSnapshots", {page: currentPage}, (response) => {
- if (currentPage < response.data.pageCount) {
- nextElement.removeAttribute("disabled");
- } else {
- nextElement.setAttribute("disabled", "disabled");
- }
- renderRepoItem(response, element, "cloud");
- });
- }
+ element.setAttribute("data-init", "true");
+ if (selectValue === "getRepoTagSnapshots" || selectValue === "getCloudRepoTagSnapshots") {
+ fetchPost(`/api/repo/${selectValue}`, {}, (response) => {
+ renderRepoItem(response, element, selectValue);
+ });
previousElement.classList.add("fn__none");
nextElement.classList.add("fn__none");
} else {
previousElement.classList.remove("fn__none");
nextElement.classList.remove("fn__none");
- element.setAttribute("data-init", "true");
element.setAttribute("data-page", currentPage.toString());
if (currentPage > 1) {
previousElement.removeAttribute("disabled");
} else {
previousElement.setAttribute("disabled", "disabled");
}
- fetchPost("/api/repo/getRepoSnapshots", {page: currentPage}, (response) => {
+ fetchPost(`/api/repo/${selectValue}`, {page: currentPage}, (response) => {
if (currentPage < response.data.pageCount) {
nextElement.removeAttribute("disabled");
} else {
nextElement.setAttribute("disabled", "disabled");
}
- renderRepoItem(response, element, "local");
+ renderRepoItem(response, element, selectValue);
});
}
};
@@ -294,10 +280,10 @@ export const openHistory = () => {
@@ -370,18 +356,9 @@ const bindEvent = (element: Element, dialog?: Dialog) => {
});
disabledProtyle(historyEditor.protyle);
const repoElement = element.querySelector('#historyContainer [data-type="repo"]');
- const selectElement = repoElement.querySelector(".b3-select") as HTMLSelectElement;
- selectElement.addEventListener("change", () => {
- const value = selectElement.value;
- if (value === "0") {
- renderRepo(repoElement, 1);
- } else if (value === "1") {
- renderRepo(repoElement, -1);
- } else if (value === "2") {
- renderRepo(repoElement, -2);
- } else if (value === "3") {
- renderRepo(repoElement, -3);
- }
+ const repoSelectElement = repoElement.querySelector(".b3-select") as HTMLSelectElement;
+ repoSelectElement.querySelector(".b3-select").addEventListener("change", () => {
+ renderRepo(repoElement, 1);
const btnElement = element.querySelector(".b3-button[data-type='compare']");
btnElement.setAttribute("disabled", "disabled");
btnElement.removeAttribute("data-ids");
@@ -474,7 +451,8 @@ const bindEvent = (element: Element, dialog?: Dialog) => {
target.nextElementSibling.classList.toggle("fn__none");
target.firstElementChild.firstElementChild.classList.toggle("b3-list-item__arrow--open");
break;
- } else if (target.classList.contains("b3-list-item") && type === "repoitem") {
+ } else if (target.classList.contains("b3-list-item") && type === "repoitem" &&
+ ["getRepoSnapshots", "getRepoTagSnapshots"].includes(repoSelectElement.value)) {
const btnElement = element.querySelector(".b3-button[data-type='compare']");
const idJSON = JSON.parse(btnElement.getAttribute("data-ids") || "[]");
const id = target.getAttribute("data-id");
@@ -563,7 +541,7 @@ const bindEvent = (element: Element, dialog?: Dialog) => {
const tag = target.parentElement.getAttribute("data-tag");
confirmDialog(window.siyuan.languages.deleteOpConfirm, `${window.siyuan.languages.confirmDelete} ${tag}?`, () => {
fetchPost("/api/repo/" + type, {tag}, () => {
- renderRepo(repoElement, type === "removeRepoTagSnapshot" ? -1 : -2);
+ renderRepo(repoElement, 1);
});
});
break;
@@ -639,7 +617,7 @@ const bindEvent = (element: Element, dialog?: Dialog) => {
historyEditor = undefined;
}
break;
- } else if (type === "compare") {
+ } else if (type === "compare" && !target.getAttribute("disabled")) {
showDiff(JSON.parse(target.getAttribute("data-ids") || "[]"));
break;
}