feat: implement Phase 12.3 - Project Export/Import

Added full export/import functionality for projects:

Export Features:
- Export button for each project in Projects dialog
- Downloads project as JSON file with all data
- Includes tracks, audio buffers, effects, automation, settings
- Filename format: {project_name}_{timestamp}.json

Import Features:
- Import button in Projects dialog header
- File picker for .json files
- Automatically generates new project ID to avoid conflicts
- Appends "(Imported)" to project name
- Preserves all project data

This enables:
- Backup of projects outside the browser
- Sharing projects with collaborators
- Migration between computers/browsers
- Version snapshots at different stages

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-19 10:25:06 +01:00
parent 9ad504478d
commit a626427142
3 changed files with 150 additions and 1 deletions

View File

@@ -42,6 +42,8 @@ import {
listProjects,
removeProject,
duplicateProject,
exportProjectAsJSON,
importProjectFromJSON,
type ProjectMetadata,
} from '@/lib/storage/projects';
import { getAudioContext } from '@/lib/audio/context';
@@ -1110,6 +1112,70 @@ export function AudioEditor() {
}
}, [projects, loadProjectsList, addToast]);
// Export project
const handleExportProject = React.useCallback(async (projectId: string) => {
try {
const project = projects.find(p => p.id === projectId);
if (!project) return;
await exportProjectAsJSON(projectId);
addToast({
title: 'Project Exported',
description: `"${project.name}" exported successfully`,
variant: 'success',
duration: 2000,
});
} catch (error) {
console.error('Failed to export project:', error);
addToast({
title: 'Export Failed',
description: 'Could not export project',
variant: 'error',
duration: 3000,
});
}
}, [projects, addToast]);
// Import project
const handleImportProject = React.useCallback(async () => {
try {
// Create file input
const input = document.createElement('input');
input.type = 'file';
input.accept = '.json';
input.onchange = async (e) => {
const file = (e.target as HTMLInputElement).files?.[0];
if (!file) return;
try {
const projectId = await importProjectFromJSON(file);
await loadProjectsList();
addToast({
title: 'Project Imported',
description: 'Project imported successfully',
variant: 'success',
duration: 2000,
});
} catch (error) {
console.error('Failed to import project:', error);
addToast({
title: 'Import Failed',
description: 'Could not import project file',
variant: 'error',
duration: 3000,
});
}
};
input.click();
} catch (error) {
console.error('Failed to open file picker:', error);
}
}, [loadProjectsList, addToast]);
// Zoom controls
const handleZoomIn = () => {
setZoom((prev) => Math.min(20, prev + 1));
@@ -1586,6 +1652,8 @@ export function AudioEditor() {
onLoadProject={handleLoadProject}
onDeleteProject={handleDeleteProject}
onDuplicateProject={handleDuplicateProject}
onExportProject={handleExportProject}
onImportProject={handleImportProject}
/>
</>
);