/**
* GoingsOn - Import Module
*
* Imports tasks, projects, or events from a CSV/TSV file. The entity type is
* auto-detected from the header columns by the native importer (Rust). CSV is
* GoingsOn's import interchange format; convert other tools' exports to CSV
* with a separate converter, then bring them in here.
*/
(function() {
'use strict';
const esc = GoingsOn.utils.escapeHtml;
const escAttrVal = GoingsOn.utils.escapeAttrValue;
// ============ State ============
let selectedFilePath = null;
let previewData = null;
// ============ Import Wizard ============
/**
* Opens the import modal (choose file, then preview and confirm).
*/
function openImportModal() {
selectedFilePath = null;
previewData = null;
const content = `
1. Choose a CSV or TSV file
Columns are matched by name (description, due, priority, project, tags for tasks; start/end for events; name/type for projects).
2. Preview
Loading preview...
`;
GoingsOn.ui.openModal('Import from CSV', content);
}
/**
* Opens the file dialog, then loads a preview.
*/
async function selectFile() {
try {
const { open } = window.__TAURI__.dialog;
const filePath = await open({
multiple: false,
filters: [{ name: 'CSV / TSV', extensions: ['csv', 'tsv'] }],
});
if (!filePath) return; // User cancelled
selectedFilePath = filePath;
document.getElementById('selected-file-name').textContent = getFileName(filePath);
document.getElementById('import-step-preview').classList.remove('hidden');
await loadPreview();
} catch (err) {
GoingsOn.ui.showToast('Failed to select file: ' + GoingsOn.utils.getErrorMessage(err), 'error');
}
}
/**
* Gets the filename from a full path.
*/
function getFileName(path) {
return path.split(/[/\\]/).pop() || path;
}
/**
* Loads and displays the preview of the import data.
*/
async function loadPreview() {
const container = document.getElementById('import-preview-container');
container.innerHTML = '