* feat: export schedule function to be added to handler * feat: use UserScheduleStore and return json * feat: download functionality * feat: oh wow we already have a blob download util that is very very nice * feat: return empty json if none found * feat: import function completion * feat: file uploading done * feat: new input component-stories made-settings input replaced with component * feat: attempt 1 to hook settings.tsx to importSchedule * feat: it works horray aka using right Course constructor it works * chore: fix jsdoc * chore: comments and debug style * docs: extra comment * feat: name of schedule more user friendly * feat: reworked how schedule is passed and check for file being schedule * feat: color is kept on import * fix: add sendResponse to exportSchedule --------- Co-authored-by: doprz <52579214+doprz@users.noreply.github.com>
25 lines
874 B
TypeScript
25 lines
874 B
TypeScript
import { UserScheduleStore } from '@shared/storage/UserScheduleStore';
|
|
|
|
/**
|
|
* Exports the provided schedule to a portable JSON
|
|
*
|
|
* @param scheduleId - The Id matching the to-be-exported schedule
|
|
* @returns JSON format of the provided schedule ID, empty if one was not found
|
|
*/
|
|
export default async function exportSchedule(scheduleId: string): Promise<string | undefined> {
|
|
try {
|
|
const storageData = await UserScheduleStore.get('schedules');
|
|
const selectedSchedule = storageData.find(s => s.id === scheduleId);
|
|
|
|
if (!selectedSchedule) {
|
|
console.warn(`Schedule ${scheduleId} does not exist`);
|
|
return JSON.stringify({});
|
|
}
|
|
|
|
console.log(selectedSchedule);
|
|
return JSON.stringify(selectedSchedule, null, 2);
|
|
} catch (error) {
|
|
console.error('Error getting storage data:', error);
|
|
}
|
|
}
|