-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add category selection (Low/Medium/High) to tasks #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| const API_URL = 'http://localhost:3000/api/tasks'; | ||
| const CATEGORIES = ['Low', 'Medium', 'High']; | ||
| const DEFAULT_CATEGORY = 'Medium'; | ||
|
Comment on lines
1
to
+3
|
||
| const taskList = document.getElementById('taskList'); | ||
| const taskForm = document.getElementById('taskForm'); | ||
| const taskInput = document.getElementById('taskInput'); | ||
| const categorySelect = document.getElementById('categorySelect'); | ||
| const themeToggle = document.getElementById('themeToggle'); | ||
|
|
||
| // Theme functionality | ||
| function initTheme() { | ||
| const savedTheme = localStorage.getItem('theme') || 'light'; | ||
|
|
@@ -35,28 +37,42 @@ async function fetchTasks() { | |
| } | ||
|
|
||
| function addTaskToDOM(task) { | ||
| const category = task.category || DEFAULT_CATEGORY; | ||
| const li = document.createElement('li'); | ||
| li.innerHTML = ` | ||
| <span class="${task.completed ? 'completed' : ''}">${task.title}</span> | ||
| <div> | ||
| <button onclick="toggleComplete('${task.id}', ${!task.completed})">✓</button> | ||
| <button onclick="deleteTask('${task.id}')">✕</button> | ||
| </div> | ||
| `; | ||
| const titleSpan = document.createElement('span'); | ||
| titleSpan.className = task.completed ? 'completed' : ''; | ||
| titleSpan.textContent = task.title; | ||
| const categoryBadge = document.createElement('span'); | ||
| categoryBadge.className = `category-badge category-${category.toLowerCase()}`; | ||
| categoryBadge.textContent = category; | ||
| const actions = document.createElement('div'); | ||
| const completeBtn = document.createElement('button'); | ||
| completeBtn.textContent = '✓'; | ||
| completeBtn.onclick = () => toggleComplete(task.id, !task.completed); | ||
| const deleteBtn = document.createElement('button'); | ||
| deleteBtn.textContent = '✕'; | ||
| deleteBtn.onclick = () => deleteTask(task.id); | ||
| actions.appendChild(completeBtn); | ||
| actions.appendChild(deleteBtn); | ||
| li.appendChild(titleSpan); | ||
| li.appendChild(categoryBadge); | ||
| li.appendChild(actions); | ||
| taskList.appendChild(li); | ||
| } | ||
|
|
||
| taskForm.addEventListener('submit', async e => { | ||
| e.preventDefault(); | ||
| const title = taskInput.value; | ||
| const category = categorySelect.value; | ||
| const res = await fetch(API_URL, { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ title }) | ||
| body: JSON.stringify({ title, category }) | ||
| }); | ||
| const task = await res.json(); | ||
| addTaskToDOM(task); | ||
| taskInput.value = ''; | ||
| categorySelect.value = DEFAULT_CATEGORY; | ||
| }); | ||
|
|
||
| async function toggleComplete(id, completed) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -189,3 +189,61 @@ li button:active { | |||||||
| padding: 0.75em 0.5em; | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| #categorySelect { | ||||||||
| padding: 0.75em 0.5em; | ||||||||
| border: none; | ||||||||
| border-radius: 4px; | ||||||||
| background: var(--input-bg); | ||||||||
| color: var(--text-color); | ||||||||
| box-shadow: 0 1px 2px var(--input-shadow); | ||||||||
| font-size: 1em; | ||||||||
| cursor: pointer; | ||||||||
| outline: none; | ||||||||
| transition: box-shadow 0.2s; | ||||||||
| } | ||||||||
|
|
||||||||
| #categorySelect:focus { | ||||||||
| box-shadow: 0 2px 8px var(--input-focus-shadow); | ||||||||
| } | ||||||||
|
|
||||||||
| .category-badge { | ||||||||
| font-size: 0.75em; | ||||||||
| font-weight: 500; | ||||||||
| padding: 0.2em 0.65em; | ||||||||
| border-radius: 12px; | ||||||||
| text-transform: uppercase; | ||||||||
| letter-spacing: 0.5px; | ||||||||
| margin: 0 0.5em; | ||||||||
|
||||||||
| margin: 0 0.5em; | |
| margin: 0 0.5em; | |
| flex: 0 0 auto; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
<select id="categorySelect">has no accessible name (no<label>and noaria-label/aria-labelledby). Add an explicit label or an ARIA label so screen readers can announce what this control does.