This commit is contained in:
Vanessa 2023-02-23 15:16:56 +08:00
parent 45302d5a28
commit 56ca4ed2e1
2 changed files with 18 additions and 14 deletions

View file

@ -9,14 +9,10 @@ import {viewCards} from "./viewCards";
import {Constants} from "../constants";
export const genCardItem = (item: ICardPackage) => {
return `<li data-id="${item.id}" class="b3-list-item b3-list-item--narrow${isMobile() ? "" : " b3-list-item--hide-action"}">
<span class="b3-list-item__text">${item.name}</span>
<span class="counter b3-tooltips b3-tooltips__w${isMobile() ? "" : " fn__none"}" aria-label="${window.siyuan.languages.riffCard}">${item.size}</span>
<span data-type="add" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.addDeck}">
<svg><use xlink:href="#iconAdd"></use></svg>
</span>
<span data-type="remove" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.removeDeck}">
<svg><use xlink:href="#iconMin"></use></svg>
return `<li data-id="${item.id}" data-name="${item.name}" class="b3-list-item b3-list-item--narrow${isMobile() ? "" : " b3-list-item--hide-action"}">
<span class="b3-list-item__text">
<span>${item.name}</span>
<span class="b3-list-item__meta">${item.size}</span>
</span>
<span data-type="rename" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.rename}">
<svg><use xlink:href="#iconEdit"></use></svg>
@ -27,7 +23,12 @@ export const genCardItem = (item: ICardPackage) => {
<span data-type="view" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.cardPreview}">
<svg><use xlink:href="#iconEye"></use></svg>
</span>
<span class="b3-list-item__meta${isMobile() ? " fn__none" : ""}">${item.size}</span>
<span data-type="remove" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.removeDeck}">
<svg><use xlink:href="#iconMin"></use></svg>
</span>
<span data-type="add" style="display: block" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.addDeck}">
<svg><use xlink:href="#iconAdd"></use></svg>
</span>
<span class="b3-list-item__meta${isMobile() ? " fn__none" : ""}">${item.updated}</span>
</li>`;
};
@ -116,7 +117,7 @@ export const makeCard = (nodeElement: Element[]) => {
event.preventDefault();
break;
} else if (type === "delete") {
confirmDialog(window.siyuan.languages.confirm, `${window.siyuan.languages.confirmDelete} <b>${target.parentElement.querySelector(".b3-list-item__text").textContent}</b>?`, () => {
confirmDialog(window.siyuan.languages.confirm, `${window.siyuan.languages.confirmDelete} <b>${target.parentElement.getAttribute("data-name")}</b>?`, () => {
fetchPost("/api/riff/removeRiffDeck", {
deckID: target.parentElement.getAttribute("data-id"),
}, () => {
@ -127,7 +128,7 @@ export const makeCard = (nodeElement: Element[]) => {
event.preventDefault();
break;
} else if (type === "view") {
viewCards(target.parentElement.getAttribute("data-id"), target.parentElement.querySelector(".b3-list-item__text").textContent, (removeResponse) => {
viewCards(target.parentElement.getAttribute("data-id"), target.parentElement.getAttribute("data-name"), (removeResponse) => {
target.parentElement.outerHTML = genCardItem(removeResponse.data);
});
event.stopPropagation();
@ -148,7 +149,7 @@ export const makeCard = (nodeElement: Element[]) => {
renameDialog.bindInput(inputElement, () => {
(btnsElement[1] as HTMLButtonElement).click();
});
inputElement.value = target.parentElement.querySelector(".b3-list-item__text").textContent;
inputElement.value = target.parentElement.getAttribute("data-name");
inputElement.focus();
inputElement.select();
btnsElement[0].addEventListener("click", () => {
@ -159,7 +160,8 @@ export const makeCard = (nodeElement: Element[]) => {
name: inputElement.value,
deckID: target.parentElement.getAttribute("data-id"),
}, () => {
target.parentElement.querySelector(".b3-list-item__text").textContent = inputElement.value;
target.parentElement.querySelector(".b3-list-item__text span").textContent = inputElement.value;
target.parentElement.setAttribute("data-name", inputElement.value);
});
renameDialog.destroy();
});

View file

@ -129,14 +129,16 @@ export const viewCards = (deckID: string, title: string, cb:(response:IWebSocket
if (!nextElment && target.parentElement.parentElement.childElementCount > 1) {
nextElment = target.parentElement.parentElement.firstElementChild;
}
if (!nextElment) {
getArticle(edit, "");
listElement.innerHTML = `<div class="b3-list--empty">${window.siyuan.languages.emptyContent}</div>`
} else {
getArticle(edit, nextElment.getAttribute("data-id"));
listElement.querySelector(".b3-list-item--focus")?.classList.remove("b3-list-item--focus");
nextElment.classList.add("b3-list-item--focus");
target.parentElement.remove();
}
target.parentElement.remove();
cb(removeResponse);
});
event.stopPropagation();