Skip to content

Commit

Permalink
Updates // "projects" code refactor (functions split and clean up)
Browse files Browse the repository at this point in the history
  • Loading branch information
purplehepatica committed Nov 7, 2023
1 parent cd42a95 commit 806035e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 476 deletions.
4 changes: 2 additions & 2 deletions app/projekty/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h2><kbd>your badass productivity app</kbd></h2>
<section>
<div class="flex gap between">
<h2>Lista projektów</h2>
<div class="btn-group">
<!--<div class="btn-group">
<button class="edit-tasks-button secondary" data-edit-mode="false">
<span class="material-icons">
edit
Expand All @@ -51,7 +51,7 @@ <h2>Lista projektów</h2>
delete_outline
</span>
</button>
</div>
</div>-->
</div>

<div class="tasks"></div>
Expand Down
63 changes: 40 additions & 23 deletions app/projekty/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ const loadDataFromLocalStorage = () => {
}
}

const saveData = () => {

const saveDataToLocalStorage = () => {
localStorage.setItem("appData", JSON.stringify(appData));
}

Expand All @@ -55,16 +54,30 @@ const loadTasksFromLocalStorage = () => {

const { name } = appData.projects[project];

if (name !== "") addTaskElement(name, project)
if (name !== "") addProjectElement(name, project)
});
}

const validateAddTaskInput = () => {
const validateProjectInputData = () => Boolean(elements.taskInputField.value);



const createProjectEntryInAppData = () => {

if (!validateProjectInputData()) return;

appData.projects[projectsID] = {
name: elements.taskInputField.value,
subtasks: {
active: [],
checked: []
},
log: [] // Po arrayu, czy obiekcie?
}

if (elements.taskInputField.value) addTaskElement()
}

const addTaskElement = (name, project) => {
const addProjectElement = (name, project) => {

const element = document.createElement("article");
element.classList.add("task", "flex", "between");
Expand All @@ -75,26 +88,22 @@ const addTaskElement = (name, project) => {

element.innerHTML = `
<p>${value}</p>
<span class="drag-icon material-icons">
<!--<span class="drag-icon material-icons">
drag_indicator
</span>
</span>-->
`

/** while powinno sprawdzać, czy dany klucz istnieje, a jeśli nie, to powinno pozostawiać wolny klucz do wykonania następnej operacji**/
while (appData.projects[projectsID]) {
projectsID++;
}


element.dataset.taskId = project
? project
: projectsID
;

elements.mainTasksContainer.append(element);


/** dla wolnego klucza projectsID tworzony jest nowy obiekt konkretnego taska **/
if (elements.taskInputField.value !== "") {
appData.projects[projectsID] = {
name: elements.taskInputField.value,
Expand All @@ -106,13 +115,21 @@ const addTaskElement = (name, project) => {
}
}


elements.taskInputField.value = null;
saveData();
saveDataToLocalStorage();
}












const addSubtaskElement = (name, state) => {

const projectID = elements.taskDialog.dataset.taskId;
Expand All @@ -133,9 +150,9 @@ const addSubtaskElement = (name, state) => {

element.innerHTML = `
<p class="subtask-content">${value}</p>
<span class="drag-icon material-icons">
<!--<span class="drag-icon material-icons">
drag_indicator
</span>
</span>-->
`

container.append(input);
Expand All @@ -161,7 +178,7 @@ const addSubtaskElement = (name, state) => {
}

elements.subtaskInputField.value = null;
saveData();
saveDataToLocalStorage();
}

const validateAddSubtaskInput = () => {
Expand Down Expand Up @@ -259,18 +276,18 @@ const addLogElement = (e) => {
const logArr = [`${date} ${time}`, content]

appData.projects[projectID]["log"].push(logArr)
saveData();
saveDataToLocalStorage();
}




const initializeEventListeners = () => {

elements.addTaskButton.addEventListener("click", () => validateAddTaskInput());
elements.addTaskButton.addEventListener("click", createProjectEntryInAppData);

elements.taskInputField.addEventListener("keydown", (e) => e.key === "Enter"
? validateAddTaskInput()
? validateProjectInputData()
: undefined
);

Expand Down Expand Up @@ -320,7 +337,7 @@ const initializeEventListeners = () => {

appData.projects[projectID].subtasks.checked = [];
elements.checkedSubtasksContainer.innerHTML = "";
saveData();
saveDataToLocalStorage();
}
})

Expand Down Expand Up @@ -353,7 +370,7 @@ const initializeEventListeners = () => {
appData.projects[projectID].subtasks[oppositeState].push(content);

e.target.closest(".subtask-container").remove();
saveData();
saveDataToLocalStorage();
}
});

Expand Down Expand Up @@ -415,7 +432,7 @@ initializeFunctionalities();
/*const clearProjectsData = () => {
appData.projects = {};
saveData();
saveDataToLocalStorage();
}
clearProjectsData();*/
75 changes: 0 additions & 75 deletions app/projekty/index.old.html

This file was deleted.

Loading

0 comments on commit 806035e

Please sign in to comment.