Skip to content

Commit

Permalink
Updates // save & load tasks & journals from localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
purplehepatica committed Dec 6, 2023
1 parent 021b3a4 commit 66e5a38
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 61 deletions.
45 changes: 2 additions & 43 deletions app/projekty/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ <h1>Supreme Pomodoro</h1>
</hgroup>
</a>

<!--<section>
<small class="center"><mark>click on item to enter full-screen mode & hold on item to mark for deletion</mark></small>
</section>-->

<form id="add-project-form" role="group">
<input name="value" placeholder="Dodaj nowy projekt..." />
<button type="submit" class="primary">
Expand All @@ -42,18 +38,6 @@ <h2>Lista projektów</h2>
<button class="delete-projects-data secondary">
Wyczyść wszystko
</button>
<!--<div class="btn-group">
<button class="edit-tasks-button secondary" data-edit-mode="false">
<span class="material-icons">
edit
</span>
</button>
<button class="remove-selected-tasks-button warning">
<span class="material-icons">
delete_outline
</span>
</button>
</div>-->
</section>

<div class="projects"></div>
Expand All @@ -71,11 +55,6 @@ <h3 class="project-title editable"></h3>
<button class="projects-dialog-close-button close contrast">
</button>
</div>
<!--<small class="left"><mark>double click on text to edit & hold on item to mark for deletion</mark></small>-->

<!--<blockquote class="description editable">
</blockquote>-->
<div class="add-subtasks-container flex row gap bottom">
<div class="task-tabs" role="group">
<button aria-current="true" class="tasks-tab secondary">Zadania</button>
Expand All @@ -98,40 +77,20 @@ <h3 class="project-title editable"></h3>
</span>
</button>
</form>

<!--<div style="width: 85px">
<button class="remove-checked-subtasks-button warning hide">
<span class="material-icons">
delete_outline
</span>
</button>
</div>-->
</div>

<!-- <div class="subtasks-tabs container flex" role="group">
<button aria-current="true" class="active-subtasks-tab secondary">
Aktywne
</button>
<button class="checked-subtasks-tab secondary">
Odznaczone
</button>
</div>-->

<hr/>

<div class="project-main-container">
<div class="tasks-container">
<hr/>

</div>

<div class="hide journals-container">

</div>
</div>


</article>
</dialog>
</main>
Expand Down
8 changes: 4 additions & 4 deletions app/projekty/js/data/appData.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ export const saveProjectData = (id, data) => {
localStorage.setItem("appData", JSON.stringify(appData));
}

export const saveProjectTaskData = (projectID, taskID, journalData) => {
export const saveProjectTaskData = (projectID, taskID, taskData) => {

appData.projects[projectID].journals[taskID] = journalData;
incrementMaxProjectTaskID();
appData.projects[projectID].tasks[taskID] = taskData;
incrementMaxProjectTaskID(projectID);
localStorage.setItem("appData", JSON.stringify(appData));
}

export const saveProjectJournalData = (projectID, journalID, journalData) => {

appData.projects[projectID].journals[journalID] = journalData;
incrementMaxProjectJournalID();
incrementMaxProjectJournalID(projectID);
localStorage.setItem("appData", JSON.stringify(appData));
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {ELEMENTS} from "../../elements/ELEMENTS.js";
import {valueNotEmpty} from "../other/valueNotEmpty.js";
import {initializeProjectJournalBuild} from "../project/journal/initializeProjectJournalBuild.js";
import {getCurrentProjectID} from "../../data/appData.js";
import {getCurrentProjectID, getMaxProjectJournalID} from "../../data/appData.js";

export const handleAddProjectJournalFormSubmit = () => {

ELEMENTS.addProjectJournalForm.addEventListener("submit", (e) => {

e.preventDefault();

let inputValue = new FormData(ELEMENTS.addProjectJournalForm).get("value");
Expand All @@ -14,7 +15,10 @@ export const handleAddProjectJournalFormSubmit = () => {

const projectID = getCurrentProjectID();

initializeProjectJournalBuild(projectID, inputValue);
const projectJournalID = getMaxProjectJournalID(projectID);

initializeProjectJournalBuild(projectID, projectJournalID, inputValue);

ELEMENTS.addProjectJournalForm.reset();
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ELEMENTS} from "../../elements/ELEMENTS.js";
import {valueNotEmpty} from "../other/valueNotEmpty.js";
import {getCurrentProjectID} from "../../data/appData.js";
import {getCurrentProjectID, getMaxProjectJournalID, getMaxProjectTaskID} from "../../data/appData.js";
import {initializeProjectTaskBuild} from "../project/task/initializeProjectTaskBuild.js";

export const handleAddProjectTaskFormSubmit = () => {
Expand All @@ -15,7 +15,10 @@ export const handleAddProjectTaskFormSubmit = () => {

const projectID = getCurrentProjectID();

initializeProjectTaskBuild(projectID, inputValue);
const projectTaskID = getMaxProjectTaskID(projectID);

initializeProjectTaskBuild(projectID, projectTaskID, inputValue);

ELEMENTS.addProjectTaskForm.reset();
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {ELEMENTS} from "../../elements/ELEMENTS.js";
import {closeDialog} from "../dialog/closeDialog.js";
import {clearProjectDialogMainContainer} from "../project/clearProjectDialogMainContainer.js";

export const handleDialogCloseButtonClick = () => {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export const createProjectJournalElement = (projectData) => {

const {name, date} = projectData

const element = document.createElement("blockquote");
element.textContent = name;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {createProjectJournalEntry} from "./createProjectJournalEntry.js";
import {createProjectJournalElement} from "./createProjectJournalElement.js";
import {addProjectJournalElement} from "./addProjectJournalElement.js";
import {saveProjectJournalData} from "../../../data/appData.js";

export const initializeProjectJournalBuild = (projectID, journalContent) => {
export const initializeProjectJournalBuild = (projectID, projectJournalID, journalContent) => {

const journalData = createProjectJournalEntry(journalContent);
//saveProjectJournalData(projectJournalID, journalData);

saveProjectJournalData(projectID, projectJournalID, journalData);

const element = createProjectJournalElement(journalData);
addProjectJournalElement(element);
Expand Down
18 changes: 14 additions & 4 deletions app/projekty/js/functionalities/project/listProjectInfoInDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {ELEMENTS} from "../../elements/ELEMENTS.js";
import {getCurrentProjectID, getProjectData} from "../../data/appData.js";
import {addProjectTaskElement} from "./task/addProjectTaskElement.js";
import {createProjectJournalElement} from "./journal/createProjectJournalElement.js";
import {createProjectTaskElement} from "./task/createProjectTaskElement.js";
import {addProjectJournalElement} from "./journal/addProjectJournalElement.js";

export const listProjectInfoInDialog = (e) => {

Expand All @@ -15,8 +17,16 @@ export const listProjectInfoInDialog = (e) => {

const {tasks, journals} = projectData;

for (const task in tasks)
addProjectTaskElement(task)
for (const journal in journals)
createProjectJournalElement(journal)
for (const task in tasks) {

const taskData = tasks[task];
const taskElement = createProjectTaskElement(taskData);
addProjectTaskElement(taskElement);
}
for (const journal in journals) {

const journalData = journals[journal];
const journalElement = createProjectJournalElement(journalData);
addProjectJournalElement(journalElement);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {ELEMENTS} from "../../../elements/ELEMENTS.js";

export const addProjectTaskElement = (element) => {

ELEMENTS.tasksContainer.append(element);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {createProjectTaskEntry} from "./createProjectTaskEntry.js";
import {createProjectTaskElement} from "./createProjectTaskElement.js";
import {addProjectTaskElement} from "./addProjectTaskElement.js";
import {saveProjectTaskData} from "../../../data/appData.js";

export const initializeProjectTaskBuild = (projectID, inputValue) => {
export const initializeProjectTaskBuild = (projectID, projectTaskID, inputValue) => {

const taskData = createProjectTaskEntry(inputValue);
//saveProjectTaskData(projectTaskID, taskData);
saveProjectTaskData(projectID, projectTaskID, taskData);

const element = createProjectTaskElement(taskData);
addProjectTaskElement(element);
Expand Down

0 comments on commit 66e5a38

Please sign in to comment.