|
@@ -10,6 +10,7 @@ import { SocketEventName } from '~/interfaces/websocket';
|
|
|
import {
|
|
import {
|
|
|
useIsSharedUser, useIsEditable, useShareLinkId, useIsNotFound,
|
|
useIsSharedUser, useIsEditable, useShareLinkId, useIsNotFound,
|
|
|
} from '~/stores/context';
|
|
} from '~/stores/context';
|
|
|
|
|
+import { useIsHackmdDraftUpdatingInRealtime } from '~/stores/hackmd';
|
|
|
import { useDescendantsPageListModal } from '~/stores/modal';
|
|
import { useDescendantsPageListModal } from '~/stores/modal';
|
|
|
import { useCurrentPagePath, useSWRxCurrentPage } from '~/stores/page';
|
|
import { useCurrentPagePath, useSWRxCurrentPage } from '~/stores/page';
|
|
|
import { useRemoteRevisionId, useRemoteRevisionLastUpdatUser } from '~/stores/remote-latest-page';
|
|
import { useRemoteRevisionId, useRemoteRevisionLastUpdatUser } from '~/stores/remote-latest-page';
|
|
@@ -50,6 +51,8 @@ const PageView = React.memo((): JSX.Element => {
|
|
|
const { mutate: mutateRemoteRevisionId } = useRemoteRevisionId();
|
|
const { mutate: mutateRemoteRevisionId } = useRemoteRevisionId();
|
|
|
const { mutate: mutateRemoteRevisionLastUpdateUser } = useRemoteRevisionLastUpdatUser();
|
|
const { mutate: mutateRemoteRevisionLastUpdateUser } = useRemoteRevisionLastUpdatUser();
|
|
|
|
|
|
|
|
|
|
+ const { mutate: mutateIsHackmdDraftUpdatingInRealtime } = useIsHackmdDraftUpdatingInRealtime();
|
|
|
|
|
+
|
|
|
const isTopPagePath = isTopPage(currentPagePath ?? '');
|
|
const isTopPagePath = isTopPage(currentPagePath ?? '');
|
|
|
const isUsersHomePagePath = isUsersHomePage(currentPagePath ?? '');
|
|
const isUsersHomePagePath = isUsersHomePage(currentPagePath ?? '');
|
|
|
|
|
|
|
@@ -62,6 +65,13 @@ const PageView = React.memo((): JSX.Element => {
|
|
|
mutateRemoteRevisionLastUpdateUser(s2cMessagePageUpdated.remoteLastUpdateUser);
|
|
mutateRemoteRevisionLastUpdateUser(s2cMessagePageUpdated.remoteLastUpdateUser);
|
|
|
}, [mutateRemoteRevisionId, mutateRemoteRevisionLastUpdateUser]);
|
|
}, [mutateRemoteRevisionId, mutateRemoteRevisionLastUpdateUser]);
|
|
|
|
|
|
|
|
|
|
+ const setIsHackmdDraftUpdatingInRealtime = useCallback((data) => {
|
|
|
|
|
+ const { s2cMessagePageUpdated } = data;
|
|
|
|
|
+ if (s2cMessagePageUpdated.pageId === currentPage?._id) {
|
|
|
|
|
+ mutateIsHackmdDraftUpdatingInRealtime(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [currentPage?._id, mutateIsHackmdDraftUpdatingInRealtime]);
|
|
|
|
|
+
|
|
|
// listen socket for someone updating this page
|
|
// listen socket for someone updating this page
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
|
|
|
|
@@ -75,6 +85,18 @@ const PageView = React.memo((): JSX.Element => {
|
|
|
|
|
|
|
|
}, [setLatestRemotePageData, socket]);
|
|
}, [setLatestRemotePageData, socket]);
|
|
|
|
|
|
|
|
|
|
+ // listen socket for hackmd saved
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+
|
|
|
|
|
+ if (socket == null) { return }
|
|
|
|
|
+
|
|
|
|
|
+ socket.on(SocketEventName.EditingWithHackmd, setIsHackmdDraftUpdatingInRealtime);
|
|
|
|
|
+
|
|
|
|
|
+ return () => {
|
|
|
|
|
+ socket.off(SocketEventName.EditingWithHackmd, setIsHackmdDraftUpdatingInRealtime);
|
|
|
|
|
+ };
|
|
|
|
|
+ }, [setIsHackmdDraftUpdatingInRealtime, socket]);
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<div className="d-flex flex-column flex-lg-row">
|
|
<div className="d-flex flex-column flex-lg-row">
|
|
|
|
|
|