Skip to content

Commit be013a5

Browse files
committed
fix: edit dialog fix and alerts added
1 parent 289b4ec commit be013a5

File tree

7 files changed

+38
-10
lines changed

7 files changed

+38
-10
lines changed

src/client/create-diagram-dialog/components/create-diagram-dialog.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { buildUrl, handleDialogClose } from '../../utils/helpers';
33
import { serverFunctions } from '../../utils/serverFunctions';
44
import useAuth from '../../hooks/useAuth';
55
import { CircularProgress, Container, Typography } from '@mui/material';
6+
import { showAlertDialog } from '../../utils/alert';
67

78
const CreateDiagramDialog = () => {
89
const { authState, authStatus } = useAuth();
@@ -37,6 +38,7 @@ const CreateDiagramDialog = () => {
3738
handleDialogClose();
3839
} catch (error) {
3940
console.error('Error inserting image with metadata', error);
41+
showAlertDialog('Error inserting image, please try again');
4042
}
4143
}
4244
};

src/client/edit-diagram-dialog/components/edit-diagram-dialog.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { useEffect, useState } from 'react';
22
import { serverFunctions } from '../../utils/serverFunctions';
33
import { buildUrl, handleDialogClose } from '../../utils/helpers';
44
import useAuth from '../../hooks/useAuth';
5-
6-
const editUrl = localStorage.getItem('editUrl');
5+
import { showAlertDialog } from '../../utils/alert';
76

87
const EditDiagramDialog = () => {
98
const { authState, authStatus } = useAuth();
@@ -14,12 +13,6 @@ const EditDiagramDialog = () => {
1413

1514
const getMetadata = async () => {
1615
try {
17-
if (editUrl) {
18-
const iframeUrl = buildUrl(editUrl, authState.token);
19-
setDiagramsUrl(iframeUrl);
20-
localStorage.removeItem('editUrl');
21-
return;
22-
}
2316
const metadata = await serverFunctions.readSelectedImageMetadata();
2417
if (typeof metadata !== 'string') return;
2518

@@ -63,6 +56,7 @@ const EditDiagramDialog = () => {
6356
handleDialogClose();
6457
} catch (error) {
6558
console.error('Error updating image with metadata', error);
59+
showAlertDialog('Error updating image, please try again');
6660
}
6761
}
6862
};

src/client/select-diagram-dialog/components/select-diagram-dialog.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@ import { buildUrl, handleDialogClose } from '../../utils/helpers';
33
import { serverFunctions } from '../../utils/serverFunctions';
44
import useAuth from '../../hooks/useAuth';
55
import { CircularProgress, Container, Typography } from '@mui/material';
6+
import { showAlertDialog } from '../../utils/alert';
7+
8+
const editUrl = localStorage.getItem('editUrl');
69

710
const SelectDiagramDialog = () => {
811
const { authState, authStatus } = useAuth();
912
const [diagramsUrl, setDiagramsUrl] = useState('');
1013

1114
useEffect(() => {
1215
if (!authState?.authorized) return;
16+
17+
if (editUrl) {
18+
const url = buildUrl(editUrl, authState.token);
19+
setDiagramsUrl(url);
20+
localStorage.removeItem('editUrl');
21+
return;
22+
}
1323
const url = buildUrl(
1424
'/app/plugins/select?pluginSource=googledocs',
1525
authState.token
@@ -36,6 +46,7 @@ const SelectDiagramDialog = () => {
3646
);
3747
handleDialogClose();
3848
} catch (error) {
49+
showAlertDialog('Error inserting image, please try again');
3950
console.error('Error inserting image with metadata', error);
4051
}
4152
}

src/client/sidebar/components/Sidebar.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import LoadingOverlay from '../../components/loading-overlay';
1414
import { buildUrl } from '../../utils/helpers';
1515
import useAuth from '../../hooks/useAuth';
1616
import Button from '../../components/button';
17+
import { showAlertDialog } from '../../utils/alert';
1718

1819
interface ChartImage {
1920
altDescription: string;
@@ -55,6 +56,7 @@ const Sidebar = () => {
5556
} catch (error) {
5657
console.error('Error getting images', error);
5758
setChartImagesState('error');
59+
showAlertDialog('Error getting images, please try again');
5860
}
5961
}, []);
6062

@@ -84,6 +86,7 @@ const Sidebar = () => {
8486
getImages();
8587
} catch (error) {
8688
console.error('Error inserting image with metadata', error);
89+
showAlertDialog('Error inserting image, please try again');
8790
}
8891
return;
8992
}
@@ -92,7 +95,7 @@ const Sidebar = () => {
9295
if (!editUrl) return;
9396
try {
9497
localStorage.setItem('editUrl', editUrl);
95-
await serverFunctions.openEditDiagramDialogWithUrl();
98+
await serverFunctions.openSelectDiagramDialog();
9699
} catch (error) {
97100
console.error('Error opening edit dialog', error);
98101
}
@@ -105,7 +108,7 @@ const Sidebar = () => {
105108
localStorage.setItem('previewUrl', viewUrl);
106109
await serverFunctions.openPreviewDiagramDialog();
107110
} catch (error) {
108-
console.error('Error opening edit dialog', error);
111+
console.error('Error opening view dialog', error);
109112
}
110113
}
111114
};
@@ -157,6 +160,7 @@ const Sidebar = () => {
157160
} catch (error) {
158161
console.error('Error updating all diagrams', error);
159162
setUpdateDiagramsState('error');
163+
showAlertDialog('Error updating diagrams, please try again');
160164
}
161165
};
162166

@@ -168,6 +172,7 @@ const Sidebar = () => {
168172
} catch (error) {
169173
console.error('Error inserting diagram', error);
170174
setSelectDiagramState('error');
175+
showAlertDialog('Error inserting diagram, please try again');
171176
}
172177
};
173178

@@ -179,6 +184,7 @@ const Sidebar = () => {
179184
} catch (error) {
180185
console.error('Error creating new diagram', error);
181186
setCreateDiagramState('error');
187+
showAlertDialog('Error creating new diagram, please try again');
182188
}
183189
};
184190

src/client/utils/alert.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { serverFunctions } from './serverFunctions';
2+
3+
export const showAlertDialog = async (message: string) => {
4+
try {
5+
await serverFunctions.showAlertDialog(message);
6+
} catch (error) {
7+
console.log('Error showing alert dialog', error);
8+
}
9+
};

src/server/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
syncImages,
2020
selectChartImage,
2121
getChartImages,
22+
showAlertDialog,
2223
} from './ui';
2324

2425
// Public functions must be exported as named exports
@@ -43,4 +44,5 @@ export {
4344
syncImages,
4445
selectChartImage,
4546
getChartImages,
47+
showAlertDialog,
4648
};

src/server/ui.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,3 +496,7 @@ export function selectChartImage(altDescription) {
496496
// Set the selection to the range that includes the second image
497497
DocumentApp.getActiveDocument().setSelection(range);
498498
}
499+
500+
export function showAlertDialog(errorText) {
501+
DocumentApp.getUi().alert(errorText);
502+
}

0 commit comments

Comments
 (0)