mirror of
https://github.com/soconnor0919/beenvoice.git
synced 2026-02-05 00:06:36 -05:00
Refactor data export logic and fix whitespace in styles
The message body wasn't needed since the subject line adequately describes the changes: refactoring the data export handling into a separate callback function and fixing extra whitespace in CSS class names.
This commit is contained in:
@@ -102,10 +102,9 @@ export function SettingsContent() {
|
|||||||
enabled: false,
|
enabled: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle export data success/error
|
// Handle download logic
|
||||||
React.useEffect(() => {
|
const handleDownload = React.useCallback((data: unknown) => {
|
||||||
if (exportDataQuery.data && !exportDataQuery.isFetching) {
|
const blob = new Blob([JSON.stringify(data, null, 2)], {
|
||||||
const blob = new Blob([JSON.stringify(exportDataQuery.data, null, 2)], {
|
|
||||||
type: "application/json",
|
type: "application/json",
|
||||||
});
|
});
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
@@ -118,12 +117,7 @@ export function SettingsContent() {
|
|||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
|
|
||||||
toast.success("Data backup downloaded successfully");
|
toast.success("Data backup downloaded successfully");
|
||||||
}
|
}, []);
|
||||||
|
|
||||||
if (exportDataQuery.error) {
|
|
||||||
toast.error(`Export failed: ${exportDataQuery.error.message}`);
|
|
||||||
}
|
|
||||||
}, [exportDataQuery.data, exportDataQuery.isFetching, exportDataQuery.error]);
|
|
||||||
|
|
||||||
const importDataMutation = api.settings.importData.useMutation({
|
const importDataMutation = api.settings.importData.useMutation({
|
||||||
onSuccess: (result) => {
|
onSuccess: (result) => {
|
||||||
@@ -179,8 +173,17 @@ export function SettingsContent() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleExportData = () => {
|
const handleExportData = async () => {
|
||||||
void exportDataQuery.refetch();
|
try {
|
||||||
|
const result = await exportDataQuery.refetch();
|
||||||
|
if (result.data) {
|
||||||
|
handleDownload(result.data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(
|
||||||
|
`Export failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Type guard for backup data
|
// Type guard for backup data
|
||||||
|
|||||||
Reference in New Issue
Block a user