forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskExport.ts
More file actions
109 lines (101 loc) · 2.61 KB
/
Copy pathtaskExport.ts
File metadata and controls
109 lines (101 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import type { ActionItem } from '@/types/conversation';
/**
* Export tasks to CSV format
*/
export function exportTasksToCSV(tasks: ActionItem[]): string {
const headers = ['id', 'description', 'due_at', 'completed', 'created_at', 'completed_at'];
const rows = tasks.map(t => [
t.id,
`"${t.description.replace(/"/g, '""')}"`, // Escape quotes in CSV
t.due_at || '',
t.completed ? 'true' : 'false',
t.created_at || '',
t.completed_at || '',
]);
return [headers.join(','), ...rows.map(r => r.join(','))].join('\n');
}
/**
* Export tasks to JSON format
*/
export function exportTasksToJSON(tasks: ActionItem[]): string {
return JSON.stringify(tasks, null, 2);
}
/**
* Export tasks to Markdown checklist format
*/
export function exportTasksToMarkdown(tasks: ActionItem[]): string {
return tasks
.map(t => {
const checkbox = t.completed ? '[x]' : '[ ]';
const due = t.due_at
? ` (due: ${new Date(t.due_at).toLocaleDateString()})`
: '';
return `- ${checkbox} ${t.description}${due}`;
})
.join('\n');
}
/**
* Copy tasks to clipboard as plain text
*/
export async function copyTasksToClipboard(tasks: ActionItem[]): Promise<void> {
const text = tasks
.map(t => {
const status = t.completed ? '[DONE] ' : '';
const due = t.due_at
? ` - Due: ${new Date(t.due_at).toLocaleDateString()}`
: '';
return `${status}${t.description}${due}`;
})
.join('\n');
await navigator.clipboard.writeText(text);
}
/**
* Download a file with the given content
*/
export function downloadFile(
content: string,
filename: string,
mimeType: string
): void {
const blob = new Blob([content], { type: mimeType });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
/**
* Export and download tasks in the specified format
*/
export function downloadTasks(
tasks: ActionItem[],
format: 'csv' | 'json' | 'markdown'
): void {
const timestamp = new Date().toISOString().split('T')[0];
switch (format) {
case 'csv':
downloadFile(
exportTasksToCSV(tasks),
`tasks-${timestamp}.csv`,
'text/csv'
);
break;
case 'json':
downloadFile(
exportTasksToJSON(tasks),
`tasks-${timestamp}.json`,
'application/json'
);
break;
case 'markdown':
downloadFile(
exportTasksToMarkdown(tasks),
`tasks-${timestamp}.md`,
'text/markdown'
);
break;
}
}