anycoder-1049c6f4 / index.html
akhaliq's picture
akhaliq HF Staff
Upload folder using huggingface_hub
b65f824 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 rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
}
.header {
width: 100%;
max-width: 600px;
margin-bottom: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
.title {
font-size: 2rem;
font-weight: 700;
color: white;
text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.built-with {
font-size: 0.8rem;
color: rgba(255,255,255,0.8);
text-decoration: none;
transition: opacity 0.3s ease;
}
.built-with:hover {
opacity: 0.7;
}
.todo-container {
width: 100%;
max-width: 600px;
background: white;
border-radius: 16px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
overflow: hidden;
display: flex;
flex-direction: column;
}
.input-section {
padding: 20px;
border-bottom: 1px solid #f0f0f0;
}
.input-group {
display: flex;
gap: 10px;
}
.todo-input {
flex: 1;
padding: 12px 16px;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-size: 1rem;
transition: all 0.3s ease;
}
.todo-input:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.add-btn {
padding: 12px 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
font-weight: 600;
transition: all 0.3s ease;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.add-btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 8px rgba(0,0,0,0.15);
}
.add-btn:active {
transform: translateY(0);
}
.todo-list {
flex: 1;
overflow-y: auto;
max-height: 400px;
}
.todo-item {
display: flex;
align-items: center;
padding: 16px 20px;
border-bottom: 1px solid #f0f0f0;
transition: all 0.3s ease;
}
.todo-item:hover {
background-color: #f8f9ff;
}
.todo-checkbox {
width: 20px;
height: 20px;
border-radius: 4px;
border: 2px solid #e0e0e0;
cursor: pointer;
transition: all 0.3s ease;
margin-right: 12px;
}
.todo-checkbox:checked {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-color: transparent;
}
.todo-text {
flex: 1;
font-size: 1rem;
color: #333;
}
.todo-item.completed .todo-text {
text-decoration: line-through;
color: #999;
}
.delete-btn {
background: none;
border: none;
color: #ff4444;
cursor: pointer;
font-size: 1.2rem;
padding: 8px;
border-radius: 4px;
transition: all 0.3s ease;
}
.delete-btn:hover {
background-color: rgba(255, 68, 68, 0.1);
transform: scale(1.1);
}
.footer {
text-align: center;
margin-top: 20px;
color: rgba(255,255,255,0.8);
font-size: 0.9rem;
}
.footer a {
color: white;
text-decoration: none;
font-weight: 600;
}
.empty-state {
padding: 40px 20px;
text-align: center;
color: #999;
font-size: 1rem;
}
@media (max-width: 480px) {
.title {
font-size: 1.5rem;
}
.input-group {
flex-direction: column;
}
.add-btn {
width: 100%;
}
.todo-container {
border-radius: 12px;
}
}
</style>
</head>
<body>
<div class="header">
<h1 class="title">Todo App</h1>
<a href="https://huggingface.co/spaces/akhaliq/anycoder" class="built-with" target="_blank">Built with anycoder</a>
</div>
<div class="todo-container">
<div class="input-section">
<div class="input-group">
<input type="text" class="todo-input" placeholder="Add a new task..." id="todoInput">
<button class="add-btn" id="addBtn">Add</button>
</div>
</div>
<div class="todo-list" id="todoList">
<div class="empty-state">
No tasks yet. Add one above!
</div>
</div>
</div>
<div class="footer">
Made with ❤️ by <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">anycoder</a> | v1.0.0
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const todoInput = document.getElementById('todoInput');
const addBtn = document.getElementById('addBtn');
const todoList = document.getElementById('todoList');
const emptyState = document.querySelector('.empty-state');
// Load todos from localStorage
loadTodos();
// Add todo when button is clicked
addBtn.addEventListener('click', addTodo);
// Add todo when Enter key is pressed
todoInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
addTodo();
}
});
function addTodo() {
const todoText = todoInput.value.trim();
if (todoText === '') {
alert('Please enter a task!');
return;
}
// Create todo object
const todo = {
id: Date.now(),
text: todoText,
completed: false
};
// Save to localStorage
saveTodo(todo);
// Render the todo
renderTodo(todo);
// Clear input
todoInput.value = '';
// Hide empty state if there are todos
if (todoList.children.length > 1) {
emptyState.style.display = 'none';
}
}
function renderTodo(todo) {
const todoItem = document.createElement('div');
todoItem.className = 'todo-item';
if (todo.completed) {
todoItem.classList.add('completed');
}
todoItem.dataset.id = todo.id;
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.className = 'todo-checkbox';
checkbox.checked = todo.completed;
checkbox.addEventListener('change', function() {
toggleTodoComplete(todo.id);
});
const textSpan = document.createElement('span');
textSpan.className = 'todo-text';
textSpan.textContent = todo.text;
const deleteBtn = document.createElement('button');
deleteBtn.className = 'delete-btn';
deleteBtn.innerHTML = '<i class="fas fa-trash"></i>';
deleteBtn.addEventListener('click', function(e) {
e.stopPropagation();
deleteTodo(todo.id);
});
todoItem.appendChild(checkbox);
todoItem.appendChild(textSpan);
todoItem.appendChild(deleteBtn);
// Insert before empty state
todoList.insertBefore(todoItem, emptyState);
}
function saveTodo(todo) {
let todos = JSON.parse(localStorage.getItem('todos')) || [];
todos.push(todo);
localStorage.setItem('todos', JSON.stringify(todos));
}
function loadTodos() {
let todos = JSON.parse(localStorage.getItem('todos')) || [];
if (todos.length > 0) {
emptyState.style.display = 'none';
todos.forEach(todo => renderTodo(todo));
}
}
function toggleTodoComplete(id) {
let todos = JSON.parse(localStorage.getItem('todos')) || [];
todos = todos.map(todo => {
if (todo.id == id) {
todo.completed = !todo.completed;
}
return todo;
});
localStorage.setItem('todos', JSON.stringify(todos));
// Update UI
const todoItem = document.querySelector(`.todo-item[data-id="${id}"]`);
if (todoItem) {
todoItem.classList.toggle('completed');
}
}
function deleteTodo(id) {
if (confirm('Are you sure you want to delete this task?')) {
let todos = JSON.parse(localStorage.getItem('todos')) || [];
todos = todos.filter(todo => todo.id != id);
localStorage.setItem('todos', JSON.stringify(todos));
// Remove from UI
const todoItem = document.querySelector(`.todo-item[data-id="${id}"]`);
if (todoItem) {
todoItem.remove();
// Show empty state if no todos left
if (todoList.children.length === 1) {
emptyState.style.display = 'block';
}
}
}
}
});
</script>
</body>
</html>