Skip to content

Commit 64d81c5

Browse files
authored
fix: correctly load default canvas in settings (#76)
* refactor: update default canvas API endpoint in SettingsDialog - Changed the API call in SettingsDialog to use the new endpoint '/api/templates/default' for fetching default canvas data. - Removed the previous fetch implementation, streamlining the code by utilizing the api.getDefaultCanvas() method for better maintainability. * fix: update API response handling in getDefaultCanvas and log default canvas data - Modified the getDefaultCanvas function to return result.data instead of the entire result object, ensuring correct data retrieval. - Added a console log in SettingsDialog to output the fetched default canvas data for debugging purposes.
1 parent eeb2cf0 commit 64d81c5

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/frontend/src/api/hooks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ export const api = {
118118

119119
getDefaultCanvas: async (): Promise<CanvasData> => {
120120
try {
121-
const result = await fetchApi('/api/pad/from-template/default');
122-
return result;
121+
const result = await fetchApi('/api/templates/default');
122+
return result.data;
123123
} catch (error) {
124124
throw error;
125125
}

src/frontend/src/ui/SettingsDialog.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { UserSettings, DEFAULT_SETTINGS } from "../types/settings";
55
import { RefreshCw } from "lucide-react";
66
import { normalizeCanvasData } from "../utils/canvasUtils";
77
import { capture } from "../utils/posthog";
8+
import { api } from "../api/hooks";
89
import "./SettingsDialog.scss";
910

1011
interface SettingsDialogProps {
@@ -47,25 +48,18 @@ const SettingsDialog: React.FC<SettingsDialogProps> = ({
4748
setIsRestoring(true);
4849
capture('restore_tutorial_canvas_clicked');
4950

50-
// Fetch the default canvas data from the backend
51-
const response = await fetch('/api/canvas/default', {
52-
method: 'GET',
53-
credentials: 'include'
54-
});
55-
56-
if (!response.ok) {
57-
throw new Error(`Failed to fetch default canvas: ${response.statusText}`);
58-
}
51+
// Use the API function from hooks.ts to fetch the default canvas
52+
const defaultCanvasData = await api.getDefaultCanvas();
5953

60-
const defaultCanvasData = await response.json();
54+
console.debug("Default canvas data:", defaultCanvasData);
6155

6256
// Normalize the canvas data before updating the scene
6357
const normalizedData = normalizeCanvasData(defaultCanvasData);
6458

6559
// Update the canvas with the normalized default data
6660
excalidrawAPI.updateScene(normalizedData);
6761

68-
console.log("Canvas reset to default successfully");
62+
console.debug("Canvas reset to default successfully");
6963

7064
// Close the dialog after successful restore
7165
handleClose();

0 commit comments

Comments
 (0)