zkt26/sk1/index.html

150 lines
4.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Notes App</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Segoe UI', sans-serif;
background: #0f172a;
color: #e2e8f0;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 40px 16px;
}
header { text-align: center; margin-bottom: 32px; }
header h1 {
font-size: 2rem;
font-weight: 700;
background: linear-gradient(135deg, #818cf8, #38bdf8);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
header p { color: #64748b; margin-top: 4px; font-size: 0.9rem; }
.card {
background: #1e293b;
border: 1px solid #334155;
border-radius: 16px;
padding: 24px;
width: 100%;
max-width: 580px;
}
textarea {
width: 100%;
height: 90px;
background: #0f172a;
border: 1px solid #334155;
border-radius: 10px;
color: #e2e8f0;
font-size: 0.95rem;
padding: 12px;
resize: none;
outline: none;
transition: border-color 0.2s;
}
textarea:focus { border-color: #818cf8; }
textarea::placeholder { color: #475569; }
button.add-btn {
margin-top: 12px;
width: 100%;
padding: 11px;
background: linear-gradient(135deg, #818cf8, #38bdf8);
border: none;
border-radius: 10px;
color: #0f172a;
font-weight: 700;
font-size: 0.95rem;
cursor: pointer;
transition: opacity 0.2s;
}
button.add-btn:hover { opacity: 0.85; }
#status { color: #f87171; font-size: 0.85rem; margin-top: 8px; min-height: 18px; }
.notes-list { width: 100%; max-width: 580px; margin-top: 24px; display: flex; flex-direction: column; gap: 12px; }
.note {
background: #1e293b;
border: 1px solid #334155;
border-radius: 12px;
padding: 16px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }
.note-body { flex: 1; }
.note-body span { display: block; white-space: pre-wrap; font-size: 0.95rem; line-height: 1.5; color: #cbd5e1; }
.note-body small { display: block; margin-top: 6px; font-size: 0.75rem; color: #475569; }
.del {
background: transparent;
border: 1px solid #475569;
color: #94a3b8;
border-radius: 8px;
padding: 4px 10px;
cursor: pointer;
font-size: 0.8rem;
transition: background 0.2s, color 0.2s;
white-space: nowrap;
}
.del:hover { background: #f87171; border-color: #f87171; color: #fff; }
.empty { text-align: center; color: #475569; font-size: 0.9rem; padding: 24px 0; }
</style>
</head>
<body>
<header>
<h1>✦ Notes App</h1>
<p>Capture your thoughts, instantly.</p>
</header>
<div class="card">
<textarea id="content" placeholder="Write a note..."></textarea>
<button class="add-btn" onclick="addNote()">+ Add Note</button>
<p id="status"></p>
</div>
<div class="notes-list" id="notes"></div>
<script>
async function loadNotes() {
const res = await fetch('/api/notes');
const notes = await res.json();
const container = document.getElementById('notes');
if (!notes.length) {
container.innerHTML = '<p class="empty">No notes yet. Add one above!</p>';
return;
}
container.innerHTML = notes.map(n => `
<div class="note">
<div class="note-body">
<span>${escHtml(n.content)}</span>
<small>${new Date(n.created_at).toLocaleString()}</small>
</div>
<button class="del" onclick="deleteNote(${n.id})">✕ Delete</button>
</div>`).join('');
}
async function addNote() {
const ta = document.getElementById('content');
const content = ta.value.trim();
if (!content) return;
const res = await fetch('/api/notes', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({content})
});
const status = document.getElementById('status');
if (res.ok) { ta.value = ''; status.textContent = ''; loadNotes(); }
else status.textContent = 'Error adding note.';
}
async function deleteNote(id) {
await fetch('/api/notes/' + id, {method: 'DELETE'});
loadNotes();
}
function escHtml(s) {
return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}
loadNotes();
</script>
</body>
</html>