From 64c00706c8cb1f5a01db3765dd8aaf8dd240d788 Mon Sep 17 00:00:00 2001 From: AlexHalbesleben Date: Sun, 2 Oct 2022 20:21:08 -0500 Subject: [PATCH 1/5] Basic structure --- src/store/index.vuex.ts | 3 +++ src/store/storage/IDSubstore.ts | 9 +++++++++ src/store/storage/StorageStore.ts | 2 ++ src/store/storage/TasksSubstore.ts | 2 ++ src/types/Task.ts | 6 ++++++ src/util/IDUtils.ts | 25 +++++++++++++++++++++++++ 6 files changed, 47 insertions(+) create mode 100644 src/store/storage/IDSubstore.ts create mode 100644 src/util/IDUtils.ts diff --git a/src/store/index.vuex.ts b/src/store/index.vuex.ts index 96439f7..7fca968 100644 --- a/src/store/index.vuex.ts +++ b/src/store/index.vuex.ts @@ -2,6 +2,7 @@ import Chunk from "@/types/Chunk"; import UserEvent from "@/types/Event"; import UserReminder from "@/types/Reminder"; import Settings from "@/types/Settings"; +import IDUtils from "@/util/IDUtils"; import Vue from "vue"; import Vuex from "vuex"; import { @@ -42,6 +43,8 @@ export class Store extends VuexModule { constructor() { super(); + IDUtils.store = this; + this.tasks = this.storage.tasks.value; this.settings = this.storage.settings.value; this.events = this.storage.events.value; diff --git a/src/store/storage/IDSubstore.ts b/src/store/storage/IDSubstore.ts new file mode 100644 index 0000000..3220b78 --- /dev/null +++ b/src/store/storage/IDSubstore.ts @@ -0,0 +1,9 @@ +import { Store } from "../index.vuex"; +import StorageStore from "./StorageStore"; +import StorageSubstore from "./StorageSubstore"; + +export default class IDSubstore extends StorageSubstore { + constructor(store: Store, storage: StorageStore) { + super(store, storage, "id"); + } +} diff --git a/src/store/storage/StorageStore.ts b/src/store/storage/StorageStore.ts index d35d63c..b286044 100644 --- a/src/store/storage/StorageStore.ts +++ b/src/store/storage/StorageStore.ts @@ -1,6 +1,7 @@ import Substore from "../Substore"; import CompletedSubstore from "./CompletedSubstore"; import EventsSubstore from "./EventsSubstore"; +import IDSubstore from "./IDSubstore"; import RemindersSubstore from "./RemindersSubstore"; import SettingsSubstore from "./SettingsSubstore"; import TasksSubstore from "./TasksSubstore"; @@ -11,6 +12,7 @@ export default class StorageStore extends Substore { events = new EventsSubstore(this.store, this); completed = new CompletedSubstore(this.store, this); reminders = new RemindersSubstore(this.store, this); + id = new IDSubstore(this.store, this); updateTasks() { this.tasks.value = this.store.tasks; diff --git a/src/store/storage/TasksSubstore.ts b/src/store/storage/TasksSubstore.ts index fdf0f3b..1d873ba 100644 --- a/src/store/storage/TasksSubstore.ts +++ b/src/store/storage/TasksSubstore.ts @@ -1,4 +1,5 @@ import UserTask from "@/types/Task"; +import IDUtils from "@/util/IDUtils"; import { Store } from "../index.vuex"; import StorageStore from "./StorageStore"; import StorageSubstore from "./StorageSubstore"; @@ -29,6 +30,7 @@ export default class TasksSubstore extends StorageSubstore< startDate: task.startDate ? new Date(task.startDate) : null, chunks: task.chunks, backloaded: task.backloaded, + id: task.id ?? -1, lockedChunks: task.lockedChunks?.map((lockedChunk) => { return { date: new Date(lockedChunk.date), diff --git a/src/types/Task.ts b/src/types/Task.ts index 3b935d4..9bc056c 100644 --- a/src/types/Task.ts +++ b/src/types/Task.ts @@ -1,3 +1,5 @@ +import IDUtils from "@/util/IDUtils"; + export default class UserTask { name = ""; duration = 60; @@ -10,6 +12,8 @@ export default class UserTask { lockedChunks: { date: Date; number: number }[] = []; + id = 0; + get totalEffort(): number { return this.effort * this.duration; } @@ -24,6 +28,7 @@ export default class UserTask { lockedChunks = [] as { date: Date; number: number }[], backloaded = true, startDate = null as Date | null, + id = -1, }) { this.name = name; this.duration = duration; @@ -34,6 +39,7 @@ export default class UserTask { this.lockedChunks = lockedChunks; this.backloaded = backloaded; this.startDate = startDate; + this.id = id; } } diff --git a/src/util/IDUtils.ts b/src/util/IDUtils.ts new file mode 100644 index 0000000..d52f072 --- /dev/null +++ b/src/util/IDUtils.ts @@ -0,0 +1,25 @@ +import { Store } from "@/store/index.vuex"; + +export default class IDUtils { + static store: Store | undefined = undefined; + + static get lastID(): number { + if (!this.store) { + return -1; + } + try { + return this.store.storage.id.value; + } catch { + return -1; + } + } + + static nextID(): number { + if (!this.store) { + return -1; + } + const id = this.lastID + 1; + this.store.storage.id.value = id; + return id; + } +} From fda9ea4911b787633638f301b6305e988eb1b735 Mon Sep 17 00:00:00 2001 From: AlexHalbesleben Date: Sun, 2 Oct 2022 20:24:05 -0500 Subject: [PATCH 2/5] Add actual functionality --- src/components/ChunkModal.vue | 5 ++--- src/components/Task/TaskModal.vue | 5 ++--- src/store/ChunkStore.ts | 5 ++--- src/store/storage/TasksSubstore.ts | 1 - src/types/Task.ts | 2 -- src/util/TaskUtils.ts | 19 ------------------- 6 files changed, 6 insertions(+), 31 deletions(-) delete mode 100644 src/util/TaskUtils.ts diff --git a/src/components/ChunkModal.vue b/src/components/ChunkModal.vue index b1350b5..fe7ead4 100644 --- a/src/components/ChunkModal.vue +++ b/src/components/ChunkModal.vue @@ -49,7 +49,6 @@ import { Component, Vue } from "vue-property-decorator"; import vxm from "@/store/index.vuex"; import Chunk from "@/types/Chunk"; import DateUtils from "@/util/DateUtils"; -import TaskUtils from "@/util/TaskUtils"; import UserTask from "@/types/Task"; @Component @@ -153,8 +152,8 @@ export default class ChunkModal extends Vue { vxm.store.completedChunks.push(this.chunk); if ( - vxm.store.chunks.chunks.filter((chunk) => - TaskUtils.tasksEqual(chunk.task, this.chunk?.task ?? new UserTask({})) + vxm.store.chunks.chunks.filter( + (chunk) => chunk.task.id === (this.chunk?.task ?? new UserTask({})).id ).length <= 1 ) { Vue.delete(vxm.store.tasks, vxm.store.tasks.indexOf(this.chunk.task)); diff --git a/src/components/Task/TaskModal.vue b/src/components/Task/TaskModal.vue index 145713d..a770450 100644 --- a/src/components/Task/TaskModal.vue +++ b/src/components/Task/TaskModal.vue @@ -123,7 +123,6 @@ import UserTask, { TASK_DESCRIPTIONS } from "@/types/Task"; import { Component, Vue } from "vue-property-decorator"; import vxm from "@/store/index.vuex"; import DateUtils from "@/util/DateUtils"; -import TaskUtils from "@/util/TaskUtils"; @Component export default class TaskModal extends Vue { @@ -209,8 +208,8 @@ export default class TaskModal extends Vue { return; // We can't delete a task that hasn't been created } - for (let chunk of vxm.store.chunks.chunks.filter((chunk) => - TaskUtils.tasksEqual(chunk.task, this.task) + for (let chunk of vxm.store.chunks.chunks.filter( + (chunk) => chunk.task.id === this.task.id )) { chunk.date = DateUtils.currentDate; vxm.store.completedChunks.push(chunk); diff --git a/src/store/ChunkStore.ts b/src/store/ChunkStore.ts index 83b9cc3..ede5455 100644 --- a/src/store/ChunkStore.ts +++ b/src/store/ChunkStore.ts @@ -2,7 +2,6 @@ import Chunk from "@/types/Chunk"; import Settings from "@/types/Settings"; import UserTask from "@/types/Task"; import DateUtils from "@/util/DateUtils"; -import TaskUtils from "@/util/TaskUtils"; import Substore from "./Substore"; export default class ChunkStore extends Substore { @@ -98,8 +97,8 @@ export default class ChunkStore extends Substore { for (const task of this.tasks) { let { chunks } = task; chunks -= task.lockedChunks.length; - chunks -= this.store.completedChunks.filter((chunk) => - TaskUtils.tasksEqual(task, chunk.task) + chunks -= this.store.completedChunks.filter( + (chunk) => task.id === chunk.task.id ).length; const { due } = task; let daysUntilDue = DateUtils.daysBetween(DateUtils.currentDate, due); diff --git a/src/store/storage/TasksSubstore.ts b/src/store/storage/TasksSubstore.ts index 1d873ba..2a63182 100644 --- a/src/store/storage/TasksSubstore.ts +++ b/src/store/storage/TasksSubstore.ts @@ -1,5 +1,4 @@ import UserTask from "@/types/Task"; -import IDUtils from "@/util/IDUtils"; import { Store } from "../index.vuex"; import StorageStore from "./StorageStore"; import StorageSubstore from "./StorageSubstore"; diff --git a/src/types/Task.ts b/src/types/Task.ts index 9bc056c..1df69af 100644 --- a/src/types/Task.ts +++ b/src/types/Task.ts @@ -1,5 +1,3 @@ -import IDUtils from "@/util/IDUtils"; - export default class UserTask { name = ""; duration = 60; diff --git a/src/util/TaskUtils.ts b/src/util/TaskUtils.ts deleted file mode 100644 index 35917bc..0000000 --- a/src/util/TaskUtils.ts +++ /dev/null @@ -1,19 +0,0 @@ -import UserTask from "@/types/Task"; - -export default class TaskUtils { - static tasksEqual(task1: UserTask, task2: UserTask): boolean { - const testedKeys: (keyof UserTask)[] = [ - "name", - "due", - "duration", - "effort", - "description", - "chunks", - "startDate", - "backloaded", - ]; - return testedKeys.every( - (k) => task1[k]?.toString() === task2[k]?.toString() - ); - } -} From 94ca641b15a45b338355a7580d33f6edd55b7f74 Mon Sep 17 00:00:00 2001 From: AlexHalbesleben Date: Sun, 2 Oct 2022 20:51:33 -0500 Subject: [PATCH 3/5] Fix bug --- src/components/ChunkModal.vue | 2 +- src/components/Task/TaskModal.vue | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/ChunkModal.vue b/src/components/ChunkModal.vue index fe7ead4..381bcc4 100644 --- a/src/components/ChunkModal.vue +++ b/src/components/ChunkModal.vue @@ -153,7 +153,7 @@ export default class ChunkModal extends Vue { if ( vxm.store.chunks.chunks.filter( - (chunk) => chunk.task.id === (this.chunk?.task ?? new UserTask({})).id + (chunk) => chunk.task.id === this.chunk?.task?.id ).length <= 1 ) { Vue.delete(vxm.store.tasks, vxm.store.tasks.indexOf(this.chunk.task)); diff --git a/src/components/Task/TaskModal.vue b/src/components/Task/TaskModal.vue index a770450..409452a 100644 --- a/src/components/Task/TaskModal.vue +++ b/src/components/Task/TaskModal.vue @@ -237,6 +237,14 @@ export default class TaskModal extends Vue { : vxm.store.tasks, this.editedIndex ); + + let { completedChunks } = vxm.store; + for (let i = completedChunks.length - 1; i >= 0; i--) { + if (vxm.store.completedChunks[i]?.task.id === this.task?.id) { + Vue.delete(vxm.store.completedChunks, i); + } + } + vxm.store.chunks.update(); // Update chunks vxm.store.storage.updateTasks(); vxm.store.storage.updateCompleted(); From b36ef1fd9ca490ada03d35768854e16e9a52dfdb Mon Sep 17 00:00:00 2001 From: AlexHalbesleben Date: Sun, 2 Oct 2022 20:55:16 -0500 Subject: [PATCH 4/5] Fix another bug --- src/components/Day/DayModal.vue | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/Day/DayModal.vue b/src/components/Day/DayModal.vue index 203a980..8867b00 100644 --- a/src/components/Day/DayModal.vue +++ b/src/components/Day/DayModal.vue @@ -1,10 +1,6 @@