hub / app.py
Artificial35's picture
Upload app.py with huggingface_hub
e569c43 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>
<style>
:root {
--primary-color: #4f46e5;
--primary-hover: #4338ca;
--secondary-color: #f3f4f6;
--text-color: #1f2937;
--text-light: #6b7280;
--border-color: #e5e7eb;
--success-color: #10b981;
--danger-color: #ef4444;
--shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background-color: #f9fafb;
color: var(--text-color);
line-height: 1.6;
min-height: 100vh;
display: flex;
flex-direction: column;
}
.container {
max-width: 600px;
width: 100%;
margin: 0 auto;
padding: 20px;
flex: 1;
}
header {
text-align: center;
margin-bottom: 40px;
padding-top: 40px;
}
h1 {
font-size: 3rem;
font-weight: 800;
background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 10px;
}
.subtitle {
color: var(--text-light);
font-size: 1.1rem;
}
.todo-input-container {
background: white;
border-radius: 12px;
padding: 20px;
box-shadow: var(--shadow);
margin-bottom: 30px;
display: flex;
gap: 12px;
align-items: center;
}
.todo-input {
flex: 1;
padding: 12px 16px;
border: 2px solid var(--border-color);
border-radius: 8px;
font-size: 1rem;
transition: all 0.3s ease;
outline: none;
}
.todo-input:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.add-btn {
background: var(--primary-color);
color: white;
border: none;
padding: 12px 24px;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 8px;
}
.add-btn:hover {
background: var(--primary-hover);
transform: translateY(-1px);
box-shadow: var(--shadow-lg);
}
.add-btn:active {
transform: translateY(0);
}
.filters {
display: flex;
gap: 10px;
margin-bottom: 20px;
justify-content: center;
flex-wrap: wrap;
}
.filter-btn {
padding: 8px 16px;
border: 2px solid var(--border-color);
background: white;
border-radius: 20px;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 500;
color: var(--text-light);
}
.filter-btn.active {
background: var(--primary-color);
color: white;
border-color: var(--primary-color);
}
.filter-btn:hover:not(.active) {
border-color: var(--primary-color);
color: var(--primary-color);
}
.todo-list {
background: white;
border-radius: 12px;
box-shadow: var(--shadow);
overflow: hidden;
}
.todo-item {
display: flex;
align-items: center;
padding: 16px 20px;
border-bottom: 1px solid var(--border-color);
transition: all 0.3s ease;
gap: 12px;
}
.todo-item:last-child {
border-bottom: none;
}
.todo-item:hover {
background: var(--secondary-color);
}
.todo-checkbox {
width: 22px;
height: 22px;
cursor: pointer;
accent-color: var(--success-color);
}
.todo-text {
flex: 1;
font-size: 1rem;
transition: all 0.3s ease;
}
.todo-item.completed .todo-text {
text-decoration: line-through;
color: var(--text-light);
}
.delete-btn {
background: none;
border: none;
color: var(--danger-color);
cursor: pointer;
padding: 6px;
border-radius: 6px;
transition: all 0.3s ease;
opacity: 0.7;
}
.delete-btn:hover {
opacity: 1;
background: rgba(239, 68, 68, 0.1);
}
.todo-stats {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16px 20px;
background: var(--secondary-color);
color: var(--text-light);
font-size: 0.9rem;
}
.clear-completed {
background: none;
border: none;
color: var(--danger-color);
cursor: pointer;
font-weight: 500;
transition: all 0.3s ease;
padding: 4px 8px;
border-radius: 4px;
}
.clear-completed:hover {
background: rgba(239, 68, 68, 0.1);
}
.empty-state {
text-align: center;
padding: 60px 20px;
color: var(--text-light);
}
.empty-state-icon {
font-size: 4rem;
margin-bottom: 16px;
opacity: 0.3;
}
.empty-state-text {
font-size: 1.1rem;
}
@media (max-width: 480px) {
h1 {
font-size: 2.5rem;
}
.todo-input-container {
flex-direction: column;
}
.add-btn {
width: 100%;
justify-content: center;
}
.todo-stats {
flex-direction: column;
gap: 12px;
text-align: center;
}
}
/* Animations */
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.todo-item {
animation: slideIn 0.3s ease;
}
/* Custom checkbox styling */
.todo-checkbox {
-webkit-appearance: none;
appearance: none;
background: white;
border: 2px solid var(--border-color);
border-radius: 6px;
position: relative;
transition: all 0.3s ease;
}
.todo-checkbox:checked {
background: var(--success-color);
border-color: var(--success-color);
}
.todo-checkbox:checked::after {
content: 'βœ“';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>Todo App</h1>
<p class="subtitle">Stay organized and productive</p>
</header>
<main>
<div class="todo-input-container">
<input
type="text"
class="todo-input"
id="todoInput"
placeholder="What needs to be done?"
autocomplete="off"
>
<button class="add-btn" id="addBtn">
<span>+</span>
<span>Add Task</span>
</button>
</div>
<div class="filters">
<button class="filter-btn active" data-filter="all">All</button>
<button class="filter-btn" data-filter="active">Active</button>
<button class="filter-btn" data-filter="completed">Completed</button>
</div>
<div class="todo-list" id="todoList">
<div class="empty-state" id="emptyState">
<div class="empty-state-icon">πŸ“</div>
<p class="empty-state-text">No tasks yet. Add one above!</p>
</div>
</div>
<div class="todo-stats" id="todoStats" style="display: none;">
<span id="itemsLeft">0 items left</span>
<button class="clear-completed" id="clearCompleted">Clear completed</button>
</div>
</main>
</div>
<script>
class TodoApp {
constructor() {
this.todos = JSON.parse(localStorage.getItem('todos')) || [];
this.filter = 'all';
this.init();
}
init() {
this.todoInput = document.getElementById('todoInput');
this.addBtn = document.getElementById('addBtn');
this.todoList = document.getElementById('todoList');
this.emptyState = document.getElementById('emptyState');
this.todoStats = document.getElementById('todoStats');
this.itemsLeft = document.getElementById('itemsLeft');
this.clearCompleted = document.getElementById('clearCompleted');
this.filterBtns = document.querySelectorAll('.filter-btn');
this.addBtn.addEventListener('click', () => this.addTodo());
this.todoInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') this.addTodo();
});
this.clearCompleted.addEventListener('click', () => this.clearCompletedTodos());
this.filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
this.filterBtns.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
this.filter = btn.dataset.filter;
this.render();
});
});
this.render();
}
addTodo() {
const text = this.todoInput.value.trim();
if (!text) return;
const todo = {
id: Date.now(),
text,
completed: false,
createdAt: new Date()
};
this.todos.unshift(todo);
this.todoInput.value = '';
this.saveTodos();
this.render();
}
deleteTodo(id) {
this.todos = this.todos.filter(todo => todo.id !== id);
this.saveTodos();
this.render();
}
toggleTodo(id) {
const todo = this.todos.find(todo => todo.id === id);
if (todo) {
todo.completed = !todo.completed;
this.saveTodos();
this.render();
}
}
clearCompletedTodos() {
this.todos = this.todos.filter(todo => !todo.completed);
this.saveTodos();
this.render();
}
saveTodos() {
localStorage.setItem('todos', JSON.stringify(this.todos));
}
getFilteredTodos() {
switch (this.filter) {
case 'active':
return this.todos.filter(todo => !todo.completed);
case 'completed':
return this.todos.filter(todo => todo.completed);
default:
return this.todos;
}
}
render() {
const filteredTodos = this.getFilteredTodos();
if (filteredTodos.length === 0) {
this.todoList.innerHTML = `
<div class="empty-state">
<div class="empty-state-icon">πŸ“</div>
<p class="empty-state-text">
${this.filter === 'all' ? 'No tasks yet. Add one above!' :
this.filter === 'active' ? 'No active tasks!' :
'No completed tasks!'}
</p>
</div>
`;
this.todoStats.style.display = 'none';
return;
}
this.todoStats.style.display = 'flex';
const activeCount = this.todos.filter(todo => !todo.completed).length;
this.itemsLeft.textContent = `${activeCount} item${activeCount !== 1 ? 's' : ''} left`;
this.todoList.innerHTML = filteredTodos.map(todo => `
<div class="todo-item ${todo.completed ? 'completed' : ''}" data-id="${todo.id}">
<input
type="checkbox"
class="todo-checkbox"
${todo.completed ? 'checked' : ''}
onchange="app.toggleTodo(${todo.id})"
>
<span class="todo-text">${this.escapeHtml(todo.text)}</span>
<button class="delete-btn" onclick="app.deleteTodo(${todo.id})">
βœ•
</button>
</div>
`).join('');
}
escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
}
const app = new TodoApp();
</script>
</body>
</html>