Skip to content

Commit

Permalink
rm redundant checks
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaudiomv committed Feb 18, 2024
1 parent 72a961b commit c3ce138
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 35 deletions.
33 changes: 9 additions & 24 deletions src/lib/DataConverter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,18 @@
let kmlDownloadUrl: string = '';
async function handleExport() {
if (query.trim() === '') {
return;
}
processing.set(true);
errorMessage.set('');
csvDownloadUrl = '';
xlsxDownloadUrl = '';
kmlDownloadUrl = '';
if (query.trim() === '') return;
try {
processing.set(true);
const data = await fetchData(query);
if (data && data.length > 0) {
// Process data for CSV
csvDownloadUrl = exportCSV(data);
// Process data for XLSX
xlsxDownloadUrl = exportXLSX(data);
// Process data for KML
kmlDownloadUrl = query.includes('GetSearchResults') ? exportKML(data) : '';
} else {
throw new Error('No data available for export.');
}
// Process data for CSV
csvDownloadUrl = exportCSV(data);
// Process data for XLSX
xlsxDownloadUrl = exportXLSX(data);
// Process data for KML
kmlDownloadUrl = query.includes('GetSearchResults') ? exportKML(data) : '';
} catch (error) {
if (error instanceof Error) {
errorMessage.set(error.message || 'Failed to export data.');
} else {
errorMessage.set('Failed to export data.');
}
errorMessage.set(error instanceof Error ? error.message : 'Failed to export data.');
} finally {
processing.set(false);
}
Expand Down
12 changes: 1 addition & 11 deletions src/lib/DataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,11 @@ export async function fetchData(query: string): Promise<any[]> {
}
return data;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message || 'Error loading data');
} else {
throw new Error('Error loading data');
}
throw new Error(error instanceof Error ? error.message : 'Error loading data');
}
}

export function exportCSV(data: any[]): string {
if (!Array.isArray(data) || data.length === 0) {
throw new Error('No data found');
}
const processedData = processExportData(data);
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet(processedData);
Expand All @@ -56,9 +49,6 @@ export function exportCSV(data: any[]): string {
}

export function exportXLSX(data: any[]): string {
if (!Array.isArray(data) || data.length === 0) {
throw new Error('No data found');
}
const processedData = processExportData(data);
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet(processedData);
Expand Down

0 comments on commit c3ce138

Please sign in to comment.