undefined / trash.html
Vinarator's picture
Create a Notes App, with a notes section, and a history section.
e44cae2 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ScribbleSync - Trash</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<style>
.trash-item {
transition: all 0.2s ease;
}
.trash-item:hover {
transform: translateY(-2px);
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body class="bg-gray-50">
<!-- Navigation -->
<nav class="bg-white shadow-sm fixed w-full z-10">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16">
<div class="flex">
<div class="flex-shrink-0 flex items-center">
<i data-feather="edit-3" class="text-indigo-600 h-6 w-6"></i>
<span class="ml-2 text-xl font-bold text-indigo-600">ScribbleSync</span>
</div>
<div class="hidden sm:ml-6 sm:flex sm:space-x-8">
<a href="index.html" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">
Notes
</a>
<a href="history.html" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">
History
</a>
<a href="trash.html" class="border-indigo-500 text-gray-900 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">
Trash
</a>
</div>
</div>
<div class="-mr-2 flex items-center sm:hidden">
<button type="button" id="mobile-menu-button" class="inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-indigo-500">
<i data-feather="menu"></i>
</button>
</div>
</div>
</div>
<!-- Mobile menu -->
<div id="mobile-menu" class="sm:hidden hidden">
<div class="pt-2 pb-3 space-y-1">
<a href="index.html" class="border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700 block pl-3 pr-4 py-2 border-l-4 text-base font-medium">
Notes
</a>
<a href="history.html" class="border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700 block pl-3 pr-4 py-2 border-l-4 text-base font-medium">
History
</a>
<a href="trash.html" class="bg-indigo-50 border-indigo-500 text-indigo-700 block pl-3 pr-4 py-2 border-l-4 text-base font-medium">
Trash
</a>
</div>
</div>
</nav>
<!-- Main Content -->
<main class="pt-20 pb-10 px-4 sm:px-6 lg:px-8">
<div class="max-w-7xl mx-auto">
<div class="mb-8">
<h1 class="text-3xl font-bold text-gray-900">Trash</h1>
<p class="mt-2 text-sm text-gray-500">Deleted notes will be permanently removed after 30 days</p>
</div>
<!-- Trash Items -->
<div id="trash-container" class="space-y-4">
<!-- Trash items will be added here dynamically -->
<div id="empty-trash" class="text-center py-16">
<i data-feather="trash-2" class="mx-auto h-12 w-12 text-gray-400"></i>
<h3 class="mt-2 text-lg font-medium text-gray-900">Trash is empty</h3>
<p class="mt-1 text-sm text-gray-500">Deleted notes will appear here</p>
</div>
</div>
</div>
</main>
<script>
document.addEventListener('DOMContentLoaded', function() {
feather.replace();
// Mobile menu toggle
const mobileMenuButton = document.getElementById('mobile-menu-button');
const mobileMenu = document.getElementById('mobile-menu');
mobileMenuButton.addEventListener('click', function() {
if (mobileMenu.classList.contains('hidden')) {
mobileMenu.classList.remove('hidden');
} else {
mobileMenu.classList.add('hidden');
}
});
// Load trash items from localStorage
const trash = JSON.parse(localStorage.getItem('trash')) || [];
const trashContainer = document.getElementById('trash-container');
const emptyTrash = document.getElementById('empty-trash');
function renderTrashItems() {
trashContainer.innerHTML = '';
if (trash.length === 0) {
emptyTrash.classList.remove('hidden');
return;
}
emptyTrash.classList.add('hidden');
trash.forEach(item => {
const itemDate = new Date(item.deletedAt);
const formattedDate = itemDate.toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
const daysLeft = 30 - Math.floor((new Date() - itemDate) / (1000 * 60 * 60 * 24));
const trashItem = document.createElement('div');
trashItem.className = 'bg-white overflow-hidden shadow rounded-lg trash-item p-6';
trashItem.innerHTML = `
<div class="flex justify-between items-start">
<div>
<h3 class="text-lg font-medium text-gray-900">${item.title}</h3>
<p class="text-sm text-gray-500 mt-1">Deleted ${formattedDate}</p>
<p class="text-sm ${daysLeft > 7 ? 'text-green-600' : 'text-red-600'} mt-1">
${daysLeft > 0 ? `Will be permanently deleted in ${daysLeft} days` : 'Will be deleted soon'}
</p>
</div>
<div class="flex space-x-2">
<button class="restore-btn p-2 rounded-full hover:bg-gray-100" data-id="${item.id}">
<i data-feather="rotate-ccw" class="text-indigo-600"></i>
</button>
<button class="delete-forever-btn p-2 rounded-full hover:bg-red-50" data-id="${item.id}">
<i data-feather="trash" class="text-red-600"></i>
</button>
</div>
</div>
<div class="mt-4 text-sm text-gray-600">
<p>${item.content.substring(0, 200)}${item.content.length > 200 ? '...' : ''}</p>
</div>
`;
trashContainer.appendChild(trashItem);
});
feather.replace();
// Add event listeners to buttons
document.querySelectorAll('.restore-btn').forEach(btn => {
btn.addEventListener('click', restoreItem);
});
document.querySelectorAll('.delete-forever-btn').forEach(btn => {
btn.addEventListener('click', deleteForever);
});
}
function restoreItem(e) {
const id = e.currentTarget.getAttribute('data-id');
const itemIndex = trash.findIndex(item => item.id === id);
if (itemIndex !== -1) {
const restoredItem = trash[itemIndex];
// Add back to notes
const notes = JSON.parse(localStorage.getItem('notes')) || [];
notes.unshift({
id: restoredItem.id,
title: restoredItem.title,
content: restoredItem.content,
createdAt: restoredItem.createdAt,
updatedAt: new Date().toISOString()
});
localStorage.setItem('notes', JSON.stringify(notes));
// Remove from trash
trash.splice(itemIndex, 1);
localStorage.setItem('trash', JSON.stringify(trash));
renderTrashItems();
}
}
function deleteForever(e) {
if (confirm('Are you sure you want to permanently delete this note? This action cannot be undone.')) {
const id = e.currentTarget.getAttribute('data-id');
const itemIndex = trash.findIndex(item => item.id === id);
if (itemIndex !== -1) {
trash.splice(itemIndex, 1);
localStorage.setItem('trash', JSON.stringify(trash));
renderTrashItems();
}
}
}
renderTrashItems();
});
</script>
</body>
</html>