TaskDecay v1.0.0 MVP — smart task review & archive Chrome extension
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import { getSettings, setSettings, clearAllTasks } from './storage.js';
|
||||
import { fetchAllTasks } from './apis/index.js';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
const el = (id: string) => document.getElementById(id) as HTMLInputElement;
|
||||
|
||||
const settings = await getSettings();
|
||||
el('todoistEnabled').checked = settings.providers.todoist.enabled;
|
||||
el('todoistToken').value = settings.providers.todoist.token;
|
||||
el('ticktickEnabled').checked = settings.providers.ticktick.enabled;
|
||||
el('ticktickToken').value = settings.providers.ticktick.token;
|
||||
el('notionEnabled').checked = settings.providers.notion.enabled;
|
||||
el('notionToken').value = settings.providers.notion.token;
|
||||
el('notionDbs').value = (settings.providers.notion.projectIds || []).join(', ');
|
||||
el('decayThreshold').value = String(settings.decayThresholdDays);
|
||||
el('reviewInterval').value = String(settings.reviewIntervalDays);
|
||||
el('maxTasks').value = String(settings.maxTasksPerReview);
|
||||
el('autoArchive').value = String(settings.autoArchiveDays);
|
||||
|
||||
document.getElementById('saveBtn')?.addEventListener('click', async () => {
|
||||
const status = document.getElementById('status')!;
|
||||
status.textContent = '';
|
||||
status.className = 'status';
|
||||
|
||||
const newSettings = {
|
||||
...settings,
|
||||
providers: {
|
||||
todoist: {
|
||||
enabled: el('todoistEnabled').checked,
|
||||
token: el('todoistToken').value.trim(),
|
||||
lastSync: settings.providers.todoist.lastSync,
|
||||
projectIds: null,
|
||||
},
|
||||
ticktick: {
|
||||
enabled: el('ticktickEnabled').checked,
|
||||
token: el('ticktickToken').value.trim(),
|
||||
lastSync: settings.providers.ticktick.lastSync,
|
||||
projectIds: null,
|
||||
},
|
||||
notion: {
|
||||
enabled: el('notionEnabled').checked,
|
||||
token: el('notionToken').value.trim(),
|
||||
lastSync: settings.providers.notion.lastSync,
|
||||
projectIds: el('notionDbs').value.split(',').map(s => s.trim()).filter(Boolean),
|
||||
},
|
||||
},
|
||||
decayThresholdDays: parseInt(el('decayThreshold').value) || 14,
|
||||
reviewIntervalDays: parseInt(el('reviewInterval').value) || 7,
|
||||
maxTasksPerReview: parseInt(el('maxTasks').value) || 20,
|
||||
autoArchiveDays: parseInt(el('autoArchive').value) || 90,
|
||||
};
|
||||
|
||||
await setSettings(newSettings);
|
||||
status.textContent = 'Settings saved.';
|
||||
status.classList.add('success');
|
||||
});
|
||||
|
||||
document.getElementById('testBtn')?.addEventListener('click', async () => {
|
||||
const status = document.getElementById('status')!;
|
||||
status.textContent = 'Testing...';
|
||||
status.className = 'status';
|
||||
try {
|
||||
const testSettings = {
|
||||
...settings,
|
||||
providers: {
|
||||
todoist: { enabled: el('todoistEnabled').checked, token: el('todoistToken').value.trim(), lastSync: null, projectIds: null },
|
||||
ticktick: { enabled: el('ticktickEnabled').checked, token: el('ticktickToken').value.trim(), lastSync: null, projectIds: null },
|
||||
notion: { enabled: el('notionEnabled').checked, token: el('notionToken').value.trim(), lastSync: null, projectIds: el('notionDbs').value.split(',').map(s => s.trim()).filter(Boolean) },
|
||||
},
|
||||
};
|
||||
const tasks = await fetchAllTasks(testSettings.providers);
|
||||
status.textContent = `Connection OK! Found ${tasks.length} tasks across enabled providers.`;
|
||||
status.classList.add('success');
|
||||
} catch (e) {
|
||||
status.textContent = `Error: ${(e as Error).message}`;
|
||||
status.classList.add('error');
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('clearBtn')?.addEventListener('click', async () => {
|
||||
if (!confirm('Clear all stored tasks and sync data?')) return;
|
||||
await clearAllTasks();
|
||||
const status = document.getElementById('status')!;
|
||||
status.textContent = 'All data cleared.';
|
||||
status.className = 'status success';
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user