Skip to content

Commit

Permalink
Allow deleting tasks and changed disk saves to manual, after creation…
Browse files Browse the repository at this point in the history
…/deletion actions rather than on a timer
  • Loading branch information
Caleb-o committed Oct 21, 2023
1 parent 5e5da9f commit 71ea0fe
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 30 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ <h1>Error Occured</h1>
rows="16"
></textarea>
<button id="modal-save-btn">Save</button>
<button id="modal-delete-btn">Delete</button>
</div>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions index.js

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@
gap: 16px;

padding: 24px 32px;
float: none;

overflow: hidden;
white-space: nowrap;
overflow-x: scroll;
overflow-y: hidden;
}

.list-heading-text {
Expand Down Expand Up @@ -324,6 +327,11 @@
animation-duration: 0.35s;
}

#modal-content button {
padding: 4px;
margin-right: 0.5rem;
}

/* Add Animation */
@keyframes animatetop {
from {
Expand Down
11 changes: 9 additions & 2 deletions ts-src/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CardHandler } from './cardhandler';
import { CardList } from './cardlist';
import { generateElementsForLoadedData } from './layout';
import { generateElementsFromLoadedData } from './layout';
import { Color, DueDate, TagKind, TaskItem } from './task';

interface KanbanBoardData {
Expand Down Expand Up @@ -57,7 +57,13 @@ export class API {
this.cardHandler.push(new CardList(list, listNameToID(list)))
);

generateElementsForLoadedData(this);
this.cardHandler.setHasDefault();

generateElementsFromLoadedData(this);
}

public removeTaskItem(item: TaskItem) {
this.tasks.delete(item.ID);
}

public tryAddNewList(): boolean {
Expand All @@ -70,6 +76,7 @@ export class API {

public renameTaskList(oldID: string, newID: string) {
this.cardHandler.renameTaskList(oldID, newID);
this.cardHandler.setHasDefault();
}

public deleteTaskList(identifier: string) {
Expand Down
14 changes: 11 additions & 3 deletions ts-src/cardhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,30 @@ export class CardHandler {
this.lists = new Map();
}

public push(card: CardList) {
this.lists.set(card.Identifier, card);
public setHasDefault() {
this.hasDefault = this.lists.has('New List');
}

public push(list: CardList) {
this.lists.set(list.Identifier, list);
}

public tryAddNewList(): boolean {
if (this.lists.has('New List')) {
if (this.hasDefault) {
return false;
}

this.lists.set('New List', new CardList('New List', 'new-list'));
this.hasDefault = true;

return true;
}

public removeWithID(identifier: string) {
for (let [id, list] of this.lists.entries()) {
if (list.ElementID === identifier) {
this.lists.delete(id);
this.setHasDefault();
return;
}
}
Expand Down
5 changes: 0 additions & 5 deletions ts-src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@ import {
setupErrorModalLayout,
} from './layout';

// 30 seconds
const serialiseInterval = 30 * 1000;

function main() {
const api = new API();
api.tryLoadFromLocalStorage();

setInterval(() => api.serializeToLocalStorage(), serialiseInterval);

setupAddTask(api);
setupListAddButton(api);
setupDraggables(api);
Expand Down
65 changes: 50 additions & 15 deletions ts-src/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export function setupListAddButton(api: API) {
}

listDiv.insertBefore(listEl, listDiv.children[listDiv.children.length - 1]);

// Save results to disk
api.serializeToLocalStorage();
};
}

Expand All @@ -38,7 +41,6 @@ export function setupModalLayout() {
colorSelected.value = firstStyle.backgroundColor;
colorSelected.style.background = firstStyle.backgroundColor;

// When the user clicks on <span> (x), close the modal
span.onclick = function () {
modal.style.display = 'none';
};
Expand Down Expand Up @@ -93,6 +95,7 @@ export function setupNewTaskModalFields(api: API) {
const taskTitle = document.querySelector('#task-title') as HTMLInputElement;
const taskDesc = document.querySelector('#task-desc') as HTMLTextAreaElement;
const saveBtn = document.querySelector('#modal-save-btn') as HTMLButtonElement;
const deleteBtn = document.querySelector('#modal-delete-btn') as HTMLButtonElement;

const tagKind = document.querySelector('#kind-option') as HTMLSelectElement;
tagKind.value = 'prg';
Expand Down Expand Up @@ -142,12 +145,18 @@ export function setupNewTaskModalFields(api: API) {
taskDesc.value
);

// Save results to disk
api.serializeToLocalStorage();

// Hide modal
modal.style.display = 'none';
};

// Hide delete button when creating new task
deleteBtn.style.display = 'none';
}

export function generateElementsForLoadedData(api: API) {
export function generateElementsFromLoadedData(api: API) {
const listDiv = document.querySelector('#task-lists') as HTMLDivElement;

// Generate all list elements
Expand All @@ -158,9 +167,6 @@ export function generateElementsForLoadedData(api: API) {

// Generate all task elements
api.Tasks.forEach((task) => {
console.log(task);

console.log(`Loading '${task.ListID}'`);
const list = document.querySelector(`#${task.ListID}`) as HTMLDivElement;
const content = list.querySelector('.list-content') as HTMLDivElement;
content.appendChild(createTaskItemElement(api, task.Title, task.ID));
Expand All @@ -175,6 +181,7 @@ function populateTaskModalFields(api: API, taskID: string) {
const createdOn = document.querySelector('#created-on') as HTMLElement;
const taskTitle = document.querySelector('#task-title') as HTMLInputElement;
const saveBtn = document.querySelector('#modal-save-btn') as HTMLButtonElement;
const deleteBtn = document.querySelector('#modal-delete-btn') as HTMLButtonElement;
const taskDesc = document.querySelector('#task-desc') as HTMLTextAreaElement;

const tagKind = document.querySelector('#kind-option') as HTMLSelectElement;
Expand All @@ -201,6 +208,27 @@ function populateTaskModalFields(api: API, taskID: string) {
colorSelected.style.background,
taskDesc.value
);

// Save results to disk
api.serializeToLocalStorage();

// Hide modal
modal.style.display = 'none';
};

deleteBtn.style.display = 'inline';
deleteBtn.onclick = () => {
// TODO: Add confirmation modal

api.removeTaskItem(task);

const listEl = document.querySelector(`#${task.ListID}`) as HTMLElement;
const content = listEl.querySelector('.list-content') as HTMLElement;
content.removeChild(document.querySelector(`#task-id-${task.ID}`)!);

// Save results to disk
api.serializeToLocalStorage();

// Hide modal
modal.style.display = 'none';
};
Expand Down Expand Up @@ -274,6 +302,14 @@ function createListWithName(api: API, title: string): HTMLElement {

headerTitle.onchange = (e) => listHeaderChange(el, headerTitle, e, api);

const listContentZone = document.createElement('div') as HTMLDivElement;
el.appendChild(listContentZone);

listContentZone.setAttribute('value', listID);
listContentZone.className = 'list-content';

setupListDragZone(api, listContentZone);

const deleteSpan = document.createElement('span') as HTMLSpanElement;
header.appendChild(deleteSpan);

Expand All @@ -282,24 +318,19 @@ function createListWithName(api: API, title: string): HTMLElement {
deleteSpan.onclick = (e) => {
e.preventDefault();

if (el.children.length > 1) {
if (listContentZone.children.length > 0) {
showErrorModal('Cannot delete list that contains tasks.');
return;
}

api.deleteTaskList(listID);

const listDiv = document.querySelector('#task-lists') as HTMLDivElement;
listDiv.removeChild(el);
};

const listContentZone = document.createElement('div') as HTMLDivElement;
el.appendChild(listContentZone);

listContentZone.setAttribute('value', listID);
listContentZone.className = 'list-content';
api.deleteTaskList(listID);

setupListDragZone(api, listContentZone);
// Save results to disk
api.serializeToLocalStorage();
};

return el;
}
Expand All @@ -322,6 +353,10 @@ function listHeaderChange(el: HTMLElement, self: HTMLInputElement, e: Event, api
content.setAttribute('value', newID);

api.renameTaskList(self.defaultValue, self.value);

self.defaultValue = self.value;
el.id = newID;

// Save results to disk
api.serializeToLocalStorage();
}

0 comments on commit 71ea0fe

Please sign in to comment.