-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5447724
commit bd233fc
Showing
12 changed files
with
517 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
// DECLARAÇÕES | ||
const btnAdicionarTarefa = document.querySelector('.app__button--add-task'); | ||
const formAdicionarTarefa = document.querySelector('.app__form-add-task'); | ||
const textArea = document.querySelector('.app__form-textarea'); | ||
const ulTarefas = document.querySelector('.app__section-task-list'); | ||
const btnDeletar = document.querySelector('.app__form-footer__button--delete') | ||
const btnCancelar = document.querySelector('.app__form-footer__button--cancel'); | ||
const paragrafoDescricaoTarefa = document.querySelector('.app__section-active-task-description'); | ||
const btnRemoverConcluidas = document.querySelector('#btn-remover-concluidas'); | ||
const btnRemoverTodas = document.querySelector('#btn-remover-todas'); | ||
|
||
let tarefas = JSON.parse(localStorage.getItem('tarefas')) || []; | ||
let tarefaSelecionada = null | ||
let liTarefaSelecionada = null | ||
|
||
// FUNÇÕES | ||
function atualizarTarefas () { | ||
localStorage.setItem('tarefas', JSON.stringify(tarefas)); | ||
}; | ||
|
||
function criarElementoTarefa(tarefa) { | ||
const li = document.createElement('li'); | ||
li.classList.add('app__section-task-list-item'); | ||
|
||
const svg = document.createElement('svg'); | ||
svg.innerHTML = ` | ||
<svg class="app__section-task-icon-status" width="24" height="24" viewBox="0 0 24 24" fill="none" | ||
xmlns="http://www.w3.org/2000/svg"> | ||
<circle cx="12" cy="12" r="12" fill="#FFF"></circle> | ||
<path d="M9 16.1719L19.5938 5.57812L21 6.98438L9 18.9844L3.42188 13.4062L4.82812 12L9 16.1719Z" | ||
fill="#01080E"></path> | ||
</svg> | ||
`; | ||
|
||
const paragrafo = document.createElement('p'); | ||
paragrafo.textContent = tarefa.descricao; | ||
paragrafo.classList.add('app__section-task-list-item-description'); | ||
|
||
const botao = document.createElement('button'); | ||
botao.classList.add('app_button-edit'); | ||
botao.onclick = () => { | ||
const novaDescricao = prompt("Qual é o nono nome da tarefa?"); | ||
if (novaDescricao) { | ||
paragrafo.textContent = novaDescricao; | ||
tarefa.descricao = novaDescricao | ||
atualizarTarefas() | ||
} | ||
|
||
}; | ||
|
||
const imagemBotao = document.createElement('img'); | ||
imagemBotao.setAttribute('src', './imagens/edit.png'); | ||
botao.append(imagemBotao); | ||
|
||
li.append(svg); | ||
li.append(paragrafo); | ||
li.append(botao); | ||
|
||
if (tarefa.completa) { | ||
li.classList.add('app__section-task-list-item-complete'); | ||
botao.setAttribute('disabled', 'disabled'); | ||
} else { | ||
li.onclick = () => { | ||
document.querySelectorAll('.app__section-task-list-item-active').forEach(elemento => {elemento.classList.remove('app__section-task-list-item-active')}); | ||
|
||
if (tarefaSelecionada == tarefa) { | ||
paragrafoDescricaoTarefa.textContent = ''; | ||
tarefaSelecionada = null | ||
liTarefaSelecionada = null | ||
return | ||
}; | ||
|
||
tarefaSelecionada = tarefa; | ||
liTarefaSelecionada = li | ||
paragrafoDescricaoTarefa.textContent = tarefa.descricao; | ||
li.classList.add('app__section-task-list-item-active'); | ||
}; | ||
} | ||
|
||
return li; | ||
}; | ||
|
||
function deletarTarefa(cancelar) { | ||
textArea.value = ''; | ||
if (cancelar) { | ||
formAdicionarTarefa.classList.add('hidden'); | ||
} | ||
} | ||
|
||
function removerTarefas(somenteCompletas) { | ||
const seletor = somenteCompletas ? ".app__section-task-list-item-complete" : ".app__section-task-list-item"; | ||
|
||
document.querySelectorAll(seletor).forEach(elemento => { | ||
elemento.remove(); | ||
}); | ||
tarefas = somenteCompletas ? tarefas.filter(tarefa => !tarefa.completa) : []; | ||
atualizarTarefas(); | ||
}; | ||
|
||
|
||
// EVENTOS | ||
btnRemoverConcluidas.onclick = () => removerTarefas(true); | ||
btnRemoverTodas.onclick = () => removerTarefas(false); | ||
|
||
btnAdicionarTarefa.addEventListener("click", () => { | ||
formAdicionarTarefa.classList.remove('hidden'); | ||
}); | ||
|
||
document.onkeydown = (e) => { | ||
if (e.code === "Escape" && !formAdicionarTarefa.classList.contains('hidden')) { | ||
deletarTarefa(true) | ||
} | ||
} | ||
|
||
formAdicionarTarefa.addEventListener('submit', (e) => { | ||
e.preventDefault(); | ||
const tarefa = { | ||
descricao: textArea.value, | ||
} | ||
tarefas.push(tarefa); | ||
const elementoTarefa = criarElementoTarefa(tarefa); | ||
ulTarefas.append(elementoTarefa); | ||
atualizarTarefas(); | ||
deletarTarefa(true) | ||
}); | ||
|
||
|
||
|
||
tarefas.forEach(tarefa => { | ||
const elementoTarefa = criarElementoTarefa(tarefa); | ||
ulTarefas.append(elementoTarefa); | ||
}); | ||
|
||
btnCancelar.addEventListener("click", () => { | ||
deletarTarefa(true) | ||
}); | ||
|
||
btnDeletar.addEventListener("click", () => { | ||
deletarTarefa(false) | ||
}); | ||
|
||
document.addEventListener('FocoFinalizado', () => { | ||
if (tarefaSelecionada && liTarefaSelecionada) { | ||
liTarefaSelecionada.classList.remove('app__section-task-list-item-active'); | ||
liTarefaSelecionada.classList.add('app__section-task-list-item-complete'); | ||
liTarefaSelecionada.querySelector('button').setAttribute('disabled', 'disabled'); | ||
tarefaSelecionada.completa = true; | ||
atualizarTarefas(); | ||
}; | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.