-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchive.html
More file actions
187 lines (164 loc) · 7.26 KB
/
Copy patharchive.html
File metadata and controls
187 lines (164 loc) · 7.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!doctype html>
<html lang="en" data-theme="light">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#0550FF" />
<link rel="manifest" href="manifest.json" />
<link rel="icon" href="data/assets/docslogo.svg" type="image/svg+xml">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Doto:wght@100..900&family=Inter+Tight:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" rel="stylesheet" />
<link rel="stylesheet" href="data/css/base.css" />
<link rel="stylesheet" href="data/css/home.css" />
<title>Archive - Buddy Docs</title>
</head>
<body>
<header class="topbar">
<div class="left">
<a href="index.html" title="Home"><img class="logo" src="data/assets/docslogo.svg" alt="Buddy Docs logo" /></a>
</div>
<div class="search-container">
<span class="material-symbols-outlined search-icon">search</span>
<input id="search" class="search-input" type="search" placeholder="Search archived documents" />
</div>
<div class="right">
<a href="./" class="icon-btn" title="Home"><span class="material-symbols-outlined">home</span></a>
</div>
</header>
<main class="container">
<section class="documents">
<div class="section-head">
<h3>Archived Documents</h3>
</div>
<div id="docGrid" class="doc-grid"></div>
</section>
</main>
<template id="docCardTmpl">
<div class="doc-card">
<a class="doc-link" href="#">
<div class="thumb"><span class="material-symbols-outlined">description</span></div>
<div class="meta">
<strong class="title">Untitled</strong>
<span class="type">Document</span>
<span class="due"></span>
</div>
</a>
<div class="menu-container">
<button class="more icon-btn" title="More"><span class="material-symbols-outlined">more_horiz</span></button>
<div class="dropdown-menu" hidden>
<button class="menu-item" data-action="unarchive">
<span class="material-symbols-outlined">unarchive</span>
Unarchive
</button>
<button class="menu-item delete" data-action="delete">
<span class="material-symbols-outlined">delete</span>
Delete
</button>
</div>
</div>
</div>
</template>
<script src="data/js/idb.js" type="module"></script>
<script src="data/js/theme.js" type="module"></script>
<script type="module">
import { listDocuments, saveDocument, deleteDocument } from './data/js/idb.js';
function dueBadge(d){
if (!d.dueDate) return '';
const today = new Date(); today.setHours(0,0,0,0);
const dd = new Date(d.dueDate); dd.setHours(0,0,0,0);
const diffDays = Math.round((dd - today) / (1000*60*60*24));
let cls = 'blue', label = '';
if (diffDays < 0){ cls = 'gray'; label = `${Math.abs(diffDays)}d ago`; }
else if (diffDays === 0){ cls = 'red'; label = 'Today'; }
else if (diffDays === 1){ cls = 'orange'; label = 'Tomorrow'; }
else if (diffDays <= 3){ cls = 'yellow'; label = `${diffDays}d`; }
else if (diffDays <= 7){ cls = 'green'; label = `${diffDays}d`; }
else { cls = 'blue'; label = `${diffDays}d`; }
return `<span class="badge ${cls}">Due ${label}</span>`;
}
function positionMenuNearButton(menuEl, buttonEl){
const r = buttonEl.getBoundingClientRect();
const margin = 8;
const menuW = menuEl.offsetWidth || 180;
const menuH = menuEl.offsetHeight || 120;
let top = r.bottom + margin;
let left = r.right - menuW;
const vw = window.innerWidth;
const vh = window.innerHeight;
if (left + menuW > vw - margin) left = vw - margin - menuW;
if (left < margin) left = margin;
if (top + menuH > vh - margin) {
top = r.top - margin - menuH;
}
if (top < margin) top = margin;
menuEl.style.left = `${Math.round(left)}px`;
menuEl.style.top = `${Math.round(top)}px`;
}
function closeAllMenus(except) {
document.querySelectorAll('.dropdown-menu').forEach(menu => {
if (menu !== except) menu.hidden = true;
});
}
function createDocCard(doc){
const tmpl = document.getElementById('docCardTmpl');
const node = tmpl.content.firstElementChild.cloneNode(true);
const link = node.querySelector('.doc-link');
link.href = `editor.html?id=${encodeURIComponent(doc.id)}`;
node.querySelector('.title').textContent = doc.title || 'Untitled';
node.querySelector('.type').textContent = (doc.type||'document').replace(/^./, c=>c.toUpperCase());
node.querySelector('.due').innerHTML = dueBadge(doc);
const thumb = node.querySelector('.thumb');
if (doc.content) thumb.innerHTML = doc.content.slice(0, 200) + (doc.content.length > 200 ? '...' : '');
const moreBtn = node.querySelector('.more');
const menu = node.querySelector('.dropdown-menu');
function open(){
closeAllMenus(menu);
if (menu.parentElement !== document.body) {
document.body.appendChild(menu);
}
positionMenuNearButton(menu, moreBtn);
requestAnimationFrame(() => {
menu.hidden = false;
});
window.addEventListener('resize', onWindowChange);
window.addEventListener('scroll', onWindowChange, true);
}
function close(){
menu.hidden = true;
window.removeEventListener('resize', onWindowChange);
window.removeEventListener('scroll', onWindowChange, true);
}
function onWindowChange(){ if (!menu.hidden) positionMenuNearButton(menu, moreBtn); }
moreBtn.addEventListener('click', (e)=>{ e.stopPropagation(); menu.hidden?open():close(); });
menu.addEventListener('click', async (e)=>{
e.stopPropagation();
const item = e.target.closest('.menu-item'); if (!item) return;
const a = item.dataset.action;
if (a === 'unarchive'){ doc.archived = false; await saveDocument(doc); }
if (a === 'delete'){ if (confirm('Delete this document?')) await deleteDocument(doc.id); }
await render();
close();
});
document.addEventListener('click', ()=> close());
window.addEventListener('resize', onWindowChange);
window.addEventListener('scroll', onWindowChange, true);
return node;
}
async function render(){
const grid = document.getElementById('docGrid');
const term = document.getElementById('search').value.trim().toLowerCase();
// Clean up any detached dropdown menus from body before re-rendering
document.querySelectorAll('body > .dropdown-menu').forEach(m => m.remove());
const items = await listDocuments({ search: term, onlyArchived: true });
grid.innerHTML = '';
for (const d of items){
grid.appendChild(createDocCard(d));
}
}
document.getElementById('search').addEventListener('input', ()=>render());
render();
</script>
</body>
</html>