implement ISO date for tasks
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
import type { Stepable } from '@/modules/task/interfaces/stepable'
|
import type { Stepable } from '@/modules/task/interfaces/stepable'
|
||||||
|
import type { ISODate } from '@/shared/types/date'
|
||||||
|
|
||||||
export interface Taskable {
|
export interface Taskable {
|
||||||
id: string
|
id: string
|
||||||
title: string
|
title: string
|
||||||
date: Date
|
date: ISODate
|
||||||
link: string | null
|
link: string | null
|
||||||
steps: Stepable[]
|
steps: Stepable[]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import type { Stepable } from '@/modules/task/interfaces/stepable'
|
import type { Stepable } from '@/modules/task/interfaces/stepable'
|
||||||
import type { Taskable } from '@/modules/task/interfaces/taskable'
|
import type { Taskable } from '@/modules/task/interfaces/taskable'
|
||||||
import { Step } from '@/modules/task/models/step'
|
import { Step } from '@/modules/task/models/step'
|
||||||
|
import { toISODate } from '@/shared/types/date'
|
||||||
|
|
||||||
export class Task implements Taskable {
|
export class Task implements Taskable {
|
||||||
public date = new Date()
|
public date = toISODate(new Date())
|
||||||
public steps: Step[] = []
|
public steps: Step[] = []
|
||||||
public link: string | null = null
|
public link: string | null = null
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,8 @@ import { defineStore } from 'pinia'
|
|||||||
import type { Taskable } from '../interfaces/taskable'
|
import type { Taskable } from '../interfaces/taskable'
|
||||||
import { Task } from '../models/task'
|
import { Task } from '../models/task'
|
||||||
|
|
||||||
interface StoredTaskable extends Omit<Taskable, 'date'> {
|
|
||||||
date: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TaskStoreState {
|
export interface TaskStoreState {
|
||||||
tasks: StoredTaskable[]
|
tasks: Taskable[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useTaskStore = defineStore('task-store', {
|
export const useTaskStore = defineStore('task-store', {
|
||||||
@@ -17,10 +13,7 @@ export const useTaskStore = defineStore('task-store', {
|
|||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
saveTask(task: Taskable) {
|
saveTask(task: Taskable) {
|
||||||
this.tasks.push({
|
this.tasks.push(task)
|
||||||
...task,
|
|
||||||
date: task.date.toISOString()
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
reset() {
|
reset() {
|
||||||
this.tasks = []
|
this.tasks = []
|
||||||
@@ -29,9 +22,7 @@ export const useTaskStore = defineStore('task-store', {
|
|||||||
getters: {
|
getters: {
|
||||||
recentTasks(state) {
|
recentTasks(state) {
|
||||||
return state.tasks
|
return state.tasks
|
||||||
.map((task) =>
|
.map((task) => Task.fromTaskable(task))
|
||||||
Task.fromTaskable({ ...task, date: new Date(task.date) })
|
|
||||||
)
|
|
||||||
.sort((a, b) => (a.date > b.date ? -1 : 1))
|
.sort((a, b) => (a.date > b.date ? -1 : 1))
|
||||||
},
|
},
|
||||||
getTask() {
|
getTask() {
|
||||||
|
|||||||
Reference in New Issue
Block a user