import React, { useCallback } from 'react'; import { useTranslation } from 'next-i18next'; export const PageStatusAlert = (): JSX.Element => { const { t } = useTranslation(); const refreshPage = useCallback(() => { window.location.reload(); }, []); const onClickResolveConflict = useCallback(() => { // this.props.pageContainer.setState({ // isConflictDiffModalOpen: true, // }); }, []); const getContentsForSomeoneEditingAlert = useCallback(() => { return [ ['bg-success', 'd-hackmd-none'], <> {t('hackmd.someone_editing')} , Open HackMD Editor , ]; }, [t]); const getContentsForDraftExistsAlert = (isRealtime) => { return [ ['bg-success', 'd-hackmd-none'], <> {t('hackmd.this_page_has_draft')} , Open HackMD Editor , ]; }; const getContentsForUpdatedAlert = () => { // const pageEditor = appContainer.getComponentInstance('PageEditor'); const isConflictOnEdit = false; // if (pageEditor != null) { // const markdownOnEdit = pageEditor.getMarkdown(); // isConflictOnEdit = markdownOnEdit !== pageContainer.state.markdown; // } // TODO: re-impl with Next.js way // const usernameComponentToString = ReactDOMServer.renderToString(); // const label1 = isConflictOnEdit // ? t('modal_resolve_conflict.file_conflicting_with_newer_remote') // // eslint-disable-next-line react/no-danger // : ; const label1 = '(TBD -- 2022.09.13)'; return [ ['bg-warning'], <> {label1} , <> { isConflictOnEdit && ( )} , ]; }; const isRevisionOutdated = revisionId !== remoteRevisionId; const isHackmdDocumentOutdated = revisionIdHackmdSynced !== remoteRevisionId; let getContentsFunc = null; // when remote revision is newer than both if (isHackmdDocumentOutdated && isRevisionOutdated) { getContentsFunc = getContentsForUpdatedAlert; } // when someone editing with HackMD else if (isHackmdDraftUpdatingInRealtime) { getContentsFunc = getContentsForSomeoneEditingAlert; } // when the draft of HackMD is newest else if (hasDraftOnHackmd) { getContentsFunc = getContentsForDraftExistsAlert; } // do not render anything else { return <>; } const [additionalClasses, label, btn] = getContentsFunc(); return (

{label}

{btn}

); };