clarify updateSheetState

This commit is contained in:
arc-alex
2024-01-03 00:55:31 +01:00
parent a719f5827e
commit ba89673d5f
@@ -78,6 +78,12 @@ export default function SheetsModal(props: SheetsModalProps) {
fileInputRef.current?.click(); fileInputRef.current?.click();
}; };
const updateSheetState = () => {
const currentSheetId = sheetRef.current?.value ?? '';
const currentWorksheet = worksheetRef.current?.value ?? '';
getSheetState(currentSheetId, currentWorksheet).then((data) => setState(data));
};
const handleFile = async (event: ChangeEvent<HTMLInputElement>) => { const handleFile = async (event: ChangeEvent<HTMLInputElement>) => {
if (!event.target.files?.length) { if (!event.target.files?.length) {
return; return;
@@ -90,12 +96,12 @@ export default function SheetsModal(props: SheetsModalProps) {
// TODO: show this in the modal // TODO: show this in the modal
console.error(error); console.error(error);
} }
setState(await getSheetState(sheetRef.current?.value ?? '', worksheetRef.current?.value ?? '')); updateSheetState();
}; };
useEffect(() => { useEffect(() => {
if (isOpen) { if (isOpen) {
getSheetState(sheetRef.current?.value ?? '', worksheetRef.current?.value ?? '').then((data) => setState(data)); updateSheetState();
} }
}, [isOpen]); }, [isOpen]);
@@ -103,14 +109,7 @@ export default function SheetsModal(props: SheetsModalProps) {
getSheetsAuthUrl().then((data) => { getSheetsAuthUrl().then((data) => {
if (data !== 'bad') { if (data !== 'bad') {
openLink(data); openLink(data);
window.addEventListener( window.addEventListener('focus', () => updateSheetState(), { once: true });
'focus',
() =>
getSheetState(sheetRef.current?.value ?? '', worksheetRef.current?.value ?? '').then((data) =>
setState(data),
),
{ once: true },
);
} }
}); });
}; };
@@ -124,7 +123,9 @@ export default function SheetsModal(props: SheetsModalProps) {
}; };
const handlePushData = () => { const handlePushData = () => {
postPushSheet(sheetRef.current?.value ?? '', worksheetRef.current?.value ?? ''); const currentSheetId = sheetRef.current?.value ?? '';
const currentWorksheet = worksheetRef.current?.value ?? '';
postPushSheet(currentSheetId, currentWorksheet);
}; };
const handleFinalise = async () => { const handleFinalise = async () => {
@@ -173,7 +174,6 @@ export default function SheetsModal(props: SheetsModalProps) {
<div style={{ display: 'flex', flexDirection: 'column' }}> <div style={{ display: 'flex', flexDirection: 'column' }}>
<AlertTitle>Sync with Google Sheets</AlertTitle> <AlertTitle>Sync with Google Sheets</AlertTitle>
<AlertDescription> <AlertDescription>
Add information here, maybe a link too. <br />
<ModalLink href='our-docs'>For more information, see the docs</ModalLink> <ModalLink href='our-docs'>For more information, see the docs</ModalLink>
</AlertDescription> </AlertDescription>
</div> </div>