anycoder-5cedc44b / index.html
akhaliq's picture
akhaliq HF Staff
Upload folder using huggingface_hub
df725dd verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Todo App</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--primary: #6366f1;
--primary-dark: #4f46e5;
--secondary: #f1f5f9;
--accent: #10b981;
--danger: #ef4444;
--text: #1e293b;
--text-light: #64748b;
--white: #ffffff;
--shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
--shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.08);
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
.built-with {
text-align: center;
margin-bottom: 20px;
}
.built-with a {
color: var(--white);
text-decoration: none;
font-size: 0.9rem;
opacity: 0.9;
transition: opacity 0.3s ease;
}
.built-with a:hover {
opacity: 1;
text-decoration: underline;
}
.container {
width: 100%;
max-width: 600px;
background: var(--white);
border-radius: 24px;
box-shadow: var(--shadow);
overflow: hidden;
animation: slideUp 0.6s ease;
}
@keyframes slideUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.header {
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
padding: 30px;
color: var(--white);
text-align: center;
}
.header h1 {
font-size: 2rem;
font-weight: 700;
margin-bottom: 8px;
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
}
.header p {
opacity: 0.9;
font-size: 0.95rem;
}
.stats {
display: flex;
justify-content: center;
gap: 30px;
margin-top: 20px;
}
.stat {
text-align: center;
}
.stat-number {
font-size: 1.8rem;
font-weight: 700;
}
.stat-label {
font-size: 0.8rem;
opacity: 0.8;
text-transform: uppercase;
letter-spacing: 1px;
}
.input-section {
padding: 25px;
background: var(--secondary);
border-bottom: 1px solid #e2e8f0;
}
.input-wrapper {
display: flex;
gap: 12px;
}
.input-wrapper input {
flex: 1;
padding: 16px 20px;
border: 2px solid transparent;
border-radius: 14px;
font-size: 1rem;
background: var(--white);
color: var(--text);
transition: all 0.3s ease;
box-shadow: var(--shadow-sm);
}
.input-wrapper input:focus {
outline: none;
border-color: var(--primary);
box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}
.input-wrapper input::placeholder {
color: var(--text-light);
}
.add-btn {
padding: 16px 24px;
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
color: var(--white);
border: none;
border-radius: 14px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 8px;
box-shadow: var(--shadow-sm);
}
.add-btn:hover {
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}
.add-btn:active {
transform: translateY(0);
}
.filters {
display: flex;
gap: 10px;
padding: 20px 25px;
background: var(--white);
border-bottom: 1px solid #e2e8f0;
flex-wrap: wrap;
}
.filter-btn {
padding: 10px 20px;
border: 2px solid #e2e8f0;
border-radius: 10px;
background: var(--white);
color: var(--text-light);
font-size: 0.9rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
}
.filter-btn:hover {
border-color: var(--primary);
color: var(--primary);
}
.filter-btn.active {
background: var(--primary);
border-color: var(--primary);
color: var(--white);
}
.todo-list {
padding: 20px 25px;
max-height: 400px;
overflow-y: auto;
}
.todo-list::-webkit-scrollbar {
width: 6px;
}
.todo-list::-webkit-scrollbar-track {
background: #f1f5f9;
border-radius: 3px;
}
.todo-list::-webkit-scrollbar-thumb {
background: #cbd5e1;
border-radius: 3px;
}
.todo-item {
display: flex;
align-items: center;
gap: 15px;
padding: 18px;
background: var(--secondary);
border-radius: 14px;
margin-bottom: 12px;
transition: all 0.3s ease;
animation: fadeIn 0.4s ease;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateX(-20px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.todo-item:hover {
transform: translateX(5px);
box-shadow: var(--shadow-sm);
}
.todo-item.completed {
opacity: 0.7;
}
.todo-item.completed .todo-text {
text-decoration: line-through;
color: var(--text-light);
}
.checkbox {
width: 24px;
height: 24px;
border: 2px solid #cbd5e1;
border-radius: 8px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease;
flex-shrink: 0;
}
.checkbox:hover {
border-color: var(--primary);
}
.checkbox.checked {
background: var(--accent);
border-color: var(--accent);
}
.checkbox.checked i {
color: var(--white);
font-size: 0.8rem;
}
.todo-text {
flex: 1;
font-size: 1rem;
color: var(--text);
word-break: break-word;
}
.todo-date {
font-size: 0.75rem;
color: var(--text-light);
white-space: nowrap;
}
.todo-actions {
display: flex;
gap: 8px;
}
.action-btn {
width: 36px;
height: 36px;
border: none;
border-radius: 10px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease;
}
.edit-btn {
background: #fef3c7;
color: #f59e0b;
}
.edit-btn:hover {
background: #fde68a;
transform: scale(1.1);
}
.delete-btn {
background: #fee2e2;
color: var(--danger);
}
.delete-btn:hover {
background: #fecaca;
transform: scale(1.1);
}
.empty-state {
text-align: center;
padding: 50px 20px;
color: var(--text-light);
}
.empty-state i {
font-size: 4rem;
margin-bottom: 20px;
opacity: 0.3;
}
.empty-state h3 {
font-size: 1.2rem;
margin-bottom: 8px;
color: var(--text);
}
.empty-state p {
font-size: 0.95rem;
}
.footer {
padding: 20px 25px;
background: var(--secondary);
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 10px;
}
.footer-text {
color: var(--text-light);
font-size: 0.9rem;
}
.clear-btn {
padding: 10px 20px;
background: transparent;
border: 2px solid var(--danger);
color: var(--danger);
border-radius: 10px;
font-size: 0.9rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
}
.clear-btn:hover {
background: var(--danger);
color: var(--white);
}
/* Edit Modal */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
display: none;
align-items: center;
justify-content: center;
z-index: 1000;
padding: 20px;
}
.modal-overlay.active {
display: flex;
}
.modal {
background: var(--white);
border-radius: 20px;
padding: 30px;
width: 100%;
max-width: 400px;
animation: modalSlide 0.3s ease;
}
@keyframes modalSlide {
from {
opacity: 0;
transform: scale(0.9);
}
to {
opacity: 1;
transform: scale(1);
}
}
.modal h3 {
font-size: 1.3rem;
color: var(--text);
margin-bottom: 20px;
}
.modal input {
width: 100%;
padding: 14px 18px;
border: 2px solid #e2e8f0;
border-radius: 12px;
font-size: 1rem;
margin-bottom: 20px;
transition: all 0.3s ease;
}
.modal input:focus {
outline: none;
border-color: var(--primary);
}
.modal-actions {
display: flex;
gap: 12px;
justify-content: flex-end;
}
.modal-btn {
padding: 12px 24px;
border-radius: 10px;
font-size: 0.95rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
}
.cancel-btn {
background: var(--secondary);
border: none;
color: var(--text);
}
.cancel-btn:hover {
background: #e2e8f0;
}
.save-btn {
background: var(--primary);
border: none;
color: var(--white);
}
.save-btn:hover {
background: var(--primary-dark);
}
/* Responsive Design */
@media (max-width: 480px) {
.header h1 {
font-size: 1.5rem;
}
.stats {
gap: 20px;
}
.stat-number {
font-size: 1.4rem;
}
.input-wrapper {
flex-direction: column;
}
.add-btn {
justify-content: center;
}
.filters {
justify-content: center;
}
.todo-item {
flex-wrap: wrap;
}
.todo-actions {
width: 100%;
justify-content: flex-end;
margin-top: 10px;
}
.footer {
flex-direction: column;
text-align: center;
}
}
</style>
</head>
<body>
<div class="built-with">
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">Built with anycoder</a>
</div>
<div class="container">
<header class="header">
<h1><i class="fas fa-check-circle"></i> Todo App</h1>
<p>Organize your tasks efficiently</p>
<div class="stats">
<div class="stat">
<div class="stat-number" id="totalTasks">0</div>
<div class="stat-label">Total</div>
</div>
<div class="stat">
<div class="stat-number" id="completedTasks">0</div>
<div class="stat-label">Completed</div>
</div>
<div class="stat">
<div class="stat-number" id="pendingTasks">0</div>
<div class="stat-label">Pending</div>
</div>
</div>
</header>
<div class="input-section">
<div class="input-wrapper">
<input type="text" id="todoInput" placeholder="What needs to be done?" maxlength="100">
<button class="add-btn" onclick="addTodo()">
<i class="fas fa-plus"></i>
<span>Add</span>
</button>
</div>
</div>
<div class="filters">
<button class="filter-btn active" data-filter="all" onclick="filterTodos('all')">All</button>
<button class="filter-btn" data-filter="pending" onclick="filterTodos('pending')">Pending</button>
<button class="filter-btn" data-filter="completed" onclick="filterTodos('completed')">Completed</button>
</div>
<div class="todo-list" id="todoList">
<!-- Todos will be rendered here -->
</div>
<div class="footer">
<span class="footer-text" id="footerText">No tasks yet</span>
<button class="clear-btn" onclick="clearCompleted()">
<i class="fas fa-trash-alt"></i> Clear Completed
</button>
</div>
</div>
<!-- Edit Modal -->
<div class="modal-overlay" id="editModal">
<div class="modal">
<h3><i class="fas fa-edit"></i> Edit Task</h3>
<input type="text" id="editInput" placeholder="Update your task..." maxlength="100">
<div class="modal-actions">
<button class="modal-btn cancel-btn" onclick="closeModal()">Cancel</button>
<button class="modal-btn save-btn" onclick="saveEdit()">Save</button>
</div>
</div>
</div>
<script>
let todos = JSON.parse(localStorage.getItem('todos')) || [];
let currentFilter = 'all';
let editingId = null;
function saveTodos() {
localStorage.setItem('todos', JSON.stringify(todos));
}
function formatDate(date) {
const options = { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' };
return new Date(date).toLocaleDateString('en-US', options);
}
function updateStats() {
const total = todos.length;
const completed = todos.filter(t => t.completed).length;
const pending = total - completed;
document.getElementById('totalTasks').textContent = total;
document.getElementById('completedTasks').textContent = completed;
document.getElementById('pendingTasks').textContent = pending;
const footerText = document.getElementById('footerText');
if (total === 0) {
footerText.textContent = 'No tasks yet';
} else if (pending === 0) {
footerText.textContent = 'All tasks completed! 🎉';
} else {
footerText.textContent = `${pending} task${pending !== 1 ? 's' : ''} remaining`;
}
}
function renderTodos() {
const todoList = document.getElementById('todoList');
let filteredTodos = todos;
if (currentFilter === 'pending') {
filteredTodos = todos.filter(t => !t.completed);
} else if (currentFilter === 'completed') {
filteredTodos = todos.filter(t => t.completed);
}
if (filteredTodos.length === 0) {
let message = 'No tasks yet';
let subMessage = 'Add a new task to get started!';
if (currentFilter === 'pending') {
message = 'No pending tasks';
subMessage = 'All caught up! 🎉';
} else if (currentFilter === 'completed') {
message = 'No completed tasks';
subMessage = 'Complete some tasks to see them here';
}
todoList.innerHTML = `
<div class="empty-state">
<i class="fas fa-clipboard-list"></i>
<h3>${message}</h3>
<p>${subMessage}</p>
</div>
`;
} else {
todoList.innerHTML = filteredTodos.map(todo => `
<div class="todo-item ${todo.completed ? 'completed' : ''}" data-id="${todo.id}">
<div class="checkbox ${todo.completed ? 'checked' : ''}" onclick="toggleTodo(${todo.id})">
${todo.completed ? '<i class="fas fa-check"></i>' : ''}
</div>
<span class="todo-text">${escapeHtml(todo.text)}</span>
<span class="todo-date">${formatDate(todo.createdAt)}</span>
<div class="todo-actions">
<button class="action-btn edit-btn" onclick="openEditModal(${todo.id})" title="Edit">
<i class="fas fa-pen"></i>
</button>
<button class="action-btn delete-btn" onclick="deleteTodo(${todo.id})" title="Delete">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
`).join('');
}
updateStats();
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
function addTodo() {
const input = document.getElementById('todoInput');
const text = input.value.trim();
if (text === '') {
input.focus();
return;
}
const todo = {
id: Date.now(),
text: text,
completed: false,
createdAt: new Date().toISOString()
};
todos.unshift(todo);
saveTodos();
renderTodos();
input.value = '';
input.focus();
}
function toggleTodo(id) {
const todo = todos.find(t => t.id === id);
if (todo) {
todo.completed = !todo.completed;
saveTodos();
renderTodos();
}
}
function deleteTodo(id) {
todos = todos.filter(t => t.id !== id);
saveTodos();
renderTodos();
}
function openEditModal(id) {
const todo = todos.find(t => t.id === id);
if (todo) {
editingId = id;
document.getElementById('editInput').value = todo.text;
document.getElementById('editModal').classList.add('active');
document.getElementById('editInput').focus();
}
}
function closeModal() {
document.getElementById('editModal').classList.remove('active');
editingId = null;
}
function saveEdit() {
const input = document.getElementById('editInput');
const text = input.value.trim();
if (text === '' || editingId === null) {
return;
}
const todo = todos.find(t => t.id === editingId);
if (todo) {
todo.text = text;
saveTodos();
renderTodos();
}
closeModal();
}
function filterTodos(filter) {
currentFilter = filter;
document.querySelectorAll('.filter-btn').forEach(btn => {
btn.classList.remove('active');
if (btn.dataset.filter === filter) {
btn.classList.add('active');
}
});
renderTodos();
}
function clearCompleted() {
todos = todos.filter(t => !t.completed);
saveTodos();
renderTodos();
}
// Event Listeners
document.getElementById('todoInput').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
addTodo();
}
});
document.getElementById('editInput').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
saveEdit();
}
});
document.getElementById('editModal').addEventListener('click', function(e) {
if (e.target === this) {
closeModal();
}
});
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeModal();
}
});
// Initial render
renderTodos();
</script>
</body>
</html>