diff --git a/adminSiteClient/Admin.tsx b/adminSiteClient/Admin.tsx index 273fd935ea3..6185b6107a0 100644 --- a/adminSiteClient/Admin.tsx +++ b/adminSiteClient/Admin.tsx @@ -46,12 +46,6 @@ export class Admin { } @observable currentRequests: Promise[] = [] - // A way to cancel fetch requests - // e.g. currentRequestAbortControllers.get(request).abort() - @observable currentRequestAbortControllers: Map< - Promise, - AbortController - > = new Map() @computed get showLoadingIndicator(): boolean { return this.loadingIndicatorSetting === "default" @@ -132,7 +126,6 @@ export class Admin { abortController ) this.addRequest(request) - this.currentRequestAbortControllers.set(request, abortController) response = await request text = await response.text() @@ -154,7 +147,6 @@ export class Admin { } finally { if (request) { this.removeRequest(request) - this.currentRequestAbortControllers.delete(request) } } diff --git a/adminSiteClient/GdocsPreviewPage.tsx b/adminSiteClient/GdocsPreviewPage.tsx index 109ba390625..f5418353476 100644 --- a/adminSiteClient/GdocsPreviewPage.tsx +++ b/adminSiteClient/GdocsPreviewPage.tsx @@ -2,7 +2,6 @@ import React, { useCallback, useContext, useEffect, - useMemo, useRef, useState, } from "react" @@ -19,16 +18,10 @@ import { OwidGdocErrorMessage, OwidGdocErrorMessageType, slugify, - pick, } from "@ourworldindata/utils" import { Button, Col, Drawer, Row, Space, Tag, Typography } from "antd" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js" -import { - faGear, - faArrowsRotate, - faExclamationTriangle, - faAngleLeft, -} from "@fortawesome/free-solid-svg-icons" +import { faGear, faAngleLeft } from "@fortawesome/free-solid-svg-icons" import { getErrors } from "./gdocsValidation.js" import { GdocsSaveButtons } from "./GdocsSaveButtons.js" @@ -40,7 +33,6 @@ import { GdocsEditLink } from "./GdocsEditLink.js" import { openSuccessNotification } from "./gdocsNotifications.js" import { GdocsDiffButton } from "./GdocsDiffButton.js" import { GdocsDiff } from "./GdocsDiff.js" -import { useInterval } from "../site/hooks.js" export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { const { id } = match.params @@ -62,7 +54,6 @@ export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { } const hasChanges = useGdocsChanged(originalGdoc, currentGdoc) const [isSettingsOpen, setSettingsOpen] = useState(false) - const [hasSyncingError, setHasSyncingError] = useState(false) const [criticalErrorMessage, setCriticalErrorMessage] = useState< undefined | string >() @@ -70,15 +61,6 @@ export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { const [errors, setErrors] = React.useState() const { admin } = useContext(AdminAppContext) const store = useGdocsStore() - const [iframeScrollY, setIframeScrollY] = useState() - // Cancel all other requests in progress (most likely just the automatic fetch) - const cancelAllRequests = useMemo( - () => () => - admin.currentRequestAbortControllers.forEach((abortController) => { - abortController.abort() - }), - [admin] - ) const iframeRef = useRef(null) @@ -99,9 +81,6 @@ export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { if (checkIsPlainObjectWithGuard(error) && error.status === 500) { console.log("Critical error", error) setCriticalErrorMessage(error.message as string) - } else { - console.log("Syncing error", error) - setHasSyncingError(true) } }, []) @@ -124,42 +103,6 @@ export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { } }, [originalGdoc, fetchGdoc, handleError, admin]) - // synchronise content every 5 seconds - useInterval(async () => { - if (currentGdoc) { - const latestGdoc = await fetchGdoc(GdocsContentSource.Gdocs) - - // Save the scroll position of the iframe to restore it after the - // refresh. The condition is here to prevent firefox from - // calculating the scroll position on page load, which somehow results in a - // wrong value (likely at the bottom). - if (latestGdoc.revisionId !== currentGdoc.revisionId) { - setIframeScrollY(iframeRef.current?.contentWindow?.scrollY) - } - - setCurrentGdoc((current) => ({ - ...latestGdoc, - - // keep values that might've been updated in the admin (e.g. slug) as they are locally - ...pick(current, [ - "slug", - "published", - "publishedAt", - "publicationContext", - "breadcrumbs", - ]), - })) - } - }, 5000) - - const onIframeLoad = () => { - if (!iframeScrollY) return - // scroll the iframe to the position it was at before the refresh - iframeRef.current?.contentWindow?.scrollTo({ - top: iframeScrollY, - }) - } - const isLightningUpdate = useLightningUpdate( originalGdoc, currentGdoc, @@ -178,7 +121,6 @@ export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { const saveDraft = async () => { if (!currentGdoc) return - cancelAllRequests() if (currentGdoc.published) throw new Error("Cannot save a published doc as a draft") @@ -190,7 +132,6 @@ export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { const doPublish = async () => { if (!currentGdoc) return - cancelAllRequests() // set to today if not specified const publishedAt = currentGdoc.publishedAt ?? new Date() const slug = currentGdoc.slug || slugify(`${currentGdoc.content.title}`) @@ -205,7 +146,6 @@ export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { const doUnpublish = async () => { if (!currentGdoc) return - cancelAllRequests() const unpublishedGdoc = await store.unpublish(currentGdoc) setGdoc({ original: unpublishedGdoc, current: unpublishedGdoc }) openSuccessNotification("unpublished") @@ -281,29 +221,6 @@ export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { {!currentGdoc.published && ( Draft )} - {hasSyncingError ? ( - - } - color="warning" - > - Syncing error, retrying... - - ) : ( - - } - color="success" - > - preview - - )} @@ -389,7 +306,6 @@ export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { */}