Sync YAML frontmatter with share and bookmark actions
This commit is contained in:
+90
-3
@@ -3269,8 +3269,18 @@
|
||||
RightSidebarManager.toggle();
|
||||
});
|
||||
|
||||
// Share button
|
||||
const shareBtn = el("button", { class: "btn-action", title: "Partager ce document" }, [icon("share-2", 14), document.createTextNode("Partager")]);
|
||||
// Share button — check if already shared
|
||||
const shareBtn = el("button", { class: "btn-action btn-share", title: "Partager ce document" }, [icon("share-2", 14), document.createTextNode("Partager")]);
|
||||
// Check if already shared and color the button
|
||||
(async () => {
|
||||
try {
|
||||
const shares = await api("/api/shares");
|
||||
if (shares.some(s => s.vault === data.vault && s.path === data.path)) {
|
||||
shareBtn.classList.add("shared");
|
||||
shareBtn.title = "Document partagé — cliquer pour gérer";
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
})();
|
||||
shareBtn.addEventListener("click", () => openShareDialog(data.vault, data.path));
|
||||
|
||||
// Bookmark button
|
||||
@@ -3399,6 +3409,59 @@
|
||||
}
|
||||
};
|
||||
|
||||
// ── Dashboard Shared Widget ──
|
||||
const DashboardSharedWidget = {
|
||||
async load() {
|
||||
const grid = document.getElementById("dashboard-shared-grid");
|
||||
const empty = document.getElementById("dashboard-shared-empty");
|
||||
if (!grid) return;
|
||||
try {
|
||||
const shares = await api("/api/shares");
|
||||
if (!shares.length) { if (empty) empty.style.display = ""; grid.innerHTML = ""; return; }
|
||||
if (empty) empty.style.display = "none";
|
||||
grid.innerHTML = shares.map(s => `
|
||||
<div class="shared-card" data-vault="${escapeHtml(s.vault)}" data-path="${escapeHtml(s.path)}">
|
||||
<div class="shared-card-header">
|
||||
<i data-lucide="file-text" style="width:14px;height:14px"></i>
|
||||
<span class="shared-card-title">${escapeHtml(s.path.split("/").pop().replace(/\.md$/i, ""))}</span>
|
||||
<span class="shared-card-vault">${escapeHtml(s.vault)}</span>
|
||||
</div>
|
||||
<div class="shared-card-meta">
|
||||
<span>${s.access_count || 0} vue(s)</span>
|
||||
${s.expires_at ? `<span>Expire le ${new Date(s.expires_at).toLocaleDateString("fr-FR")}</span>` : ""}
|
||||
</div>
|
||||
<div class="shared-card-actions">
|
||||
<button class="shared-copy-btn" data-url="${window.location.origin}/s/${s.token}">📋 Copier</button>
|
||||
<button class="shared-open-btn">📂 Ouvrir</button>
|
||||
<button class="shared-revoke-btn" data-id="${s.id}">🗑</button>
|
||||
</div>
|
||||
</div>
|
||||
`).join("");
|
||||
lucide.createIcons();
|
||||
grid.querySelectorAll(".shared-copy-btn").forEach(b => b.addEventListener("click", async (e) => {
|
||||
e.stopPropagation();
|
||||
const url = b.dataset.url;
|
||||
try { await navigator.clipboard.writeText(url); } catch { const ta = document.createElement("textarea"); ta.value=url; ta.style.position="fixed"; ta.style.left="-9999px"; document.body.appendChild(ta); ta.select(); document.execCommand("copy"); document.body.removeChild(ta); }
|
||||
showToast("Lien copié !", "success");
|
||||
}));
|
||||
grid.querySelectorAll(".shared-open-btn").forEach(b => b.addEventListener("click", (e) => {
|
||||
e.stopPropagation();
|
||||
const card = b.closest(".shared-card");
|
||||
if (card) TabManager.openPreview(card.dataset.vault, card.dataset.path);
|
||||
}));
|
||||
grid.querySelectorAll(".shared-revoke-btn").forEach(b => b.addEventListener("click", async (e) => {
|
||||
e.stopPropagation();
|
||||
await api(`/api/share/${b.dataset.id}`, { method: "DELETE" });
|
||||
showToast("Partage révoqué", "success");
|
||||
this.load();
|
||||
}));
|
||||
grid.querySelectorAll(".shared-card").forEach(card => card.addEventListener("click", () => {
|
||||
TabManager.openPreview(card.dataset.vault, card.dataset.path);
|
||||
}));
|
||||
} catch (err) { if (empty) empty.style.display = ""; }
|
||||
}
|
||||
};
|
||||
|
||||
// ── Dashboard Conflicts Widget ──
|
||||
const DashboardConflictsWidget = {
|
||||
async load() {
|
||||
@@ -4586,7 +4649,15 @@
|
||||
</div>
|
||||
</div>`;
|
||||
div.querySelector(".share-copy-btn").addEventListener("click", async () => {
|
||||
await navigator.clipboard.writeText(url);
|
||||
try {
|
||||
await navigator.clipboard.writeText(url);
|
||||
} catch (e) {
|
||||
// Fallback for non-HTTPS contexts
|
||||
const ta = document.createElement("textarea");
|
||||
ta.value = url; ta.style.position = "fixed"; ta.style.left = "-9999px";
|
||||
document.body.appendChild(ta); ta.select(); document.execCommand("copy");
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
showToast("Lien copié !", "success");
|
||||
div.remove();
|
||||
});
|
||||
@@ -5813,6 +5884,9 @@
|
||||
<button class="dashboard-tab" data-tab="recent">
|
||||
<i data-lucide="clock" style="width:14px;height:14px"></i> Récents
|
||||
</button>
|
||||
<button class="dashboard-tab" data-tab="shared">
|
||||
<i data-lucide="share-2" style="width:14px;height:14px"></i> Partagés
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Stats Panel -->
|
||||
@@ -5856,6 +5930,16 @@
|
||||
<p>Ouvrez un fichier pour le voir apparaître ici</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Shared Panel -->
|
||||
<div id="dashboard-panel-shared" class="dashboard-panel">
|
||||
<div id="dashboard-shared-grid" class="dashboard-recent-grid"></div>
|
||||
<div id="dashboard-shared-empty" class="dashboard-recent-empty">
|
||||
<i data-lucide="share-2"></i>
|
||||
<span>Aucun document partagé</span>
|
||||
<p>Partagez un document pour le voir apparaître ici</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
// Re-initialize widgets and dashboard tabs
|
||||
@@ -5889,6 +5973,9 @@
|
||||
if (typeof DashboardBookmarkWidget !== "undefined") {
|
||||
DashboardBookmarkWidget.load(selectedContextVault);
|
||||
}
|
||||
if (typeof DashboardSharedWidget !== "undefined") {
|
||||
DashboardSharedWidget.load();
|
||||
}
|
||||
}
|
||||
|
||||
function showLoading() {
|
||||
|
||||
Reference in New Issue
Block a user