From 9280f7d16b9596dd6b5589f986f444e84ed50fed Mon Sep 17 00:00:00 2001 From: Ike Saunders Date: Thu, 12 Oct 2023 15:58:52 -0400 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20remove=20autosave=20from=20gdoc?= =?UTF-8?q?s=20preview=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adminSiteClient/Admin.tsx | 8 ----- adminSiteClient/GdocsPreviewPage.tsx | 51 ---------------------------- site/hooks.ts | 22 ------------ 3 files changed, 81 deletions(-) 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..97548780671 100644 --- a/adminSiteClient/GdocsPreviewPage.tsx +++ b/adminSiteClient/GdocsPreviewPage.tsx @@ -19,7 +19,6 @@ 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" @@ -40,7 +39,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 @@ -70,15 +68,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) @@ -124,42 +113,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 +131,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 +142,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 +156,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") @@ -389,7 +339,6 @@ export const GdocsPreviewPage = ({ match, history }: GdocsMatchProps) => { */}