34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
import { element } from "./dom.js";
|
|
import { formatDate } from "./format.js";
|
|
|
|
const maxRecentPaths = 5;
|
|
|
|
export function recentDestinations(entries) {
|
|
const paths = [];
|
|
for (const entry of entries) {
|
|
if (!paths.includes(entry.destination)) paths.push(entry.destination);
|
|
if (paths.length >= maxRecentPaths) break;
|
|
}
|
|
return paths;
|
|
}
|
|
|
|
export function renderHistory(elements, entries) {
|
|
elements.title.textContent = entries.length > 0 ? `History (${entries.length})` : "History";
|
|
elements.empty.hidden = entries.length > 0;
|
|
elements.clearButton.hidden = entries.length === 0;
|
|
elements.list.replaceChildren(...entries.map(renderEntry));
|
|
}
|
|
|
|
function renderEntry(entry) {
|
|
const item = element("li", "history-item");
|
|
const items = entry.items || [];
|
|
const itemText = items.length === 1 ? items[0] : `${items.length} items`;
|
|
item.append(
|
|
element("div", "history-name", entry.fileName || itemText),
|
|
element("p", "history-meta muted", `${itemText} moved to ${entry.destination}`),
|
|
element("p", "history-meta muted", formatDate(entry.movedAt)),
|
|
);
|
|
if (entry.sourceUrl) item.append(element("p", "history-meta muted", entry.sourceUrl));
|
|
return item;
|
|
}
|