Fresh Redux Snapshot Access - 2

创建于 差异永不过期
11 删除
35
8 添加
33
export function serializeTask(t: GanttTask): SerializedTask {
export function serializeTask(t: GanttTask): SerializedTask {
const startDate = t.start_date instanceof Date
const startDate = dateToISO(t.start_date as Date | string | null | undefined);
? t.start_date.toISOString()

: typeof t.start_date === "string"
? t.start_date
: null;


return {
return {
id: t.id,
id: t.id,
text: t.text,
text: t.text,
start_date: startDate,
start_date: startDate,
duration: t.duration ?? 1,
duration: t.duration ?? 1,
progress: Number(t.progress) || 0,
progress: Number(t.progress) || 0,
parent: t.parent ?? 0,
parent: t.parent ?? 0,
type: t.type ?? "task",
type: t.type ?? "task",
open: t.open,
open: t.open,
sortorder: (t as any).sortorder ?? 0,
sortorder: (t as any).sortorder ?? 0,
assignee_user_id: (t as any).assignee_user_id ?? null,
assignee_user_id: (t as any).assignee_user_id ?? null,
};
};
}
}


/** Convert a serialized task back to a Gantt Task (with Date objects). */
/** Convert a serialized task back to a Gantt Task (with Date objects). */
export function deserializeTask(s: SerializedTask): GanttTask & { sortorder: number; assignee_user_id?: string | null } {
export function deserializeTask(s: SerializedTask): GanttTask & { sortorder: number; assignee_user_id?: string | null } {
return {
return {
id: s.id,
id: s.id,
text: s.text,
text: s.text,
start_date: s.start_date ? new Date(s.start_date) : new Date(),
start_date: isoToDate(s.start_date),
duration: s.duration,
duration: s.duration,
progress: s.progress,
progress: s.progress,
parent: s.parent,
parent: s.parent,
type: s.type as GanttTask["type"],
type: s.type as GanttTask["type"],
open: s.open,
open: s.open,
sortorder: s.sortorder,
sortorder: s.sortorder,
assignee_user_id: s.assignee_user_id,
assignee_user_id: s.assignee_user_id,
} as any;
} as any;
}