mirror of
https://github.com/docmost/docmost.git
synced 2025-11-11 09:02:06 +10:00
Compare commits
2 Commits
fix/billin
...
fix/editor
| Author | SHA1 | Date | |
|---|---|---|---|
| e4c01b8051 | |||
| c450cfc7da |
@ -34,6 +34,7 @@
|
|||||||
"jotai": "^2.12.1",
|
"jotai": "^2.12.1",
|
||||||
"jotai-optics": "^0.4.0",
|
"jotai-optics": "^0.4.0",
|
||||||
"js-cookie": "^3.0.5",
|
"js-cookie": "^3.0.5",
|
||||||
|
"jwt-decode": "^4.0.0",
|
||||||
"katex": "0.16.21",
|
"katex": "0.16.21",
|
||||||
"lowlight": "^3.2.0",
|
"lowlight": "^3.2.0",
|
||||||
"mermaid": "^11.4.1",
|
"mermaid": "^11.4.1",
|
||||||
|
|||||||
@ -19,8 +19,8 @@ export function useCollabToken(): UseQueryResult<ICollabToken, Error> {
|
|||||||
queryKey: ["collab-token"],
|
queryKey: ["collab-token"],
|
||||||
queryFn: () => getCollabToken(),
|
queryFn: () => getCollabToken(),
|
||||||
staleTime: 20 * 60 * 60 * 1000, //20hrs
|
staleTime: 20 * 60 * 60 * 1000, //20hrs
|
||||||
refetchInterval: 12 * 60 * 60 * 1000, // 12hrs
|
//refetchInterval: 12 * 60 * 60 * 1000, // 12hrs
|
||||||
refetchIntervalInBackground: true,
|
//refetchIntervalInBackground: true,
|
||||||
refetchOnMount: true,
|
refetchOnMount: true,
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
retry: (failureCount, error) => {
|
retry: (failureCount, error) => {
|
||||||
|
|||||||
@ -52,6 +52,7 @@ import { IPage } from "@/features/page/types/page.types.ts";
|
|||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { extractPageSlugId } from "@/lib";
|
import { extractPageSlugId } from "@/lib";
|
||||||
import { FIVE_MINUTES } from "@/lib/constants.ts";
|
import { FIVE_MINUTES } from "@/lib/constants.ts";
|
||||||
|
import { jwtDecode } from "jwt-decode";
|
||||||
|
|
||||||
interface PageEditorProps {
|
interface PageEditorProps {
|
||||||
pageId: string;
|
pageId: string;
|
||||||
@ -83,7 +84,6 @@ export default function PageEditor({
|
|||||||
const documentState = useDocumentVisibility();
|
const documentState = useDocumentVisibility();
|
||||||
const [isCollabReady, setIsCollabReady] = useState(false);
|
const [isCollabReady, setIsCollabReady] = useState(false);
|
||||||
const { pageSlug } = useParams();
|
const { pageSlug } = useParams();
|
||||||
const collabRetryCount = useRef(0);
|
|
||||||
const slugId = extractPageSlugId(pageSlug);
|
const slugId = extractPageSlugId(pageSlug);
|
||||||
|
|
||||||
const localProvider = useMemo(() => {
|
const localProvider = useMemo(() => {
|
||||||
@ -105,13 +105,11 @@ export default function PageEditor({
|
|||||||
connect: false,
|
connect: false,
|
||||||
preserveConnection: false,
|
preserveConnection: false,
|
||||||
onAuthenticationFailed: (auth: onAuthenticationFailedParameters) => {
|
onAuthenticationFailed: (auth: onAuthenticationFailedParameters) => {
|
||||||
collabRetryCount.current = collabRetryCount.current + 1;
|
const payload = jwtDecode(collabQuery?.token);
|
||||||
refetchCollabToken().then(() => {
|
const now = Date.now().valueOf() / 1000;
|
||||||
collabRetryCount.current = 0;
|
const isTokenExpired = now >= payload.exp;
|
||||||
});
|
if (isTokenExpired) {
|
||||||
|
refetchCollabToken();
|
||||||
if (collabRetryCount.current > 20) {
|
|
||||||
window.location.reload();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onStatus: (status) => {
|
onStatus: (status) => {
|
||||||
@ -265,19 +263,13 @@ export default function PageEditor({
|
|||||||
documentState === "visible" &&
|
documentState === "visible" &&
|
||||||
remoteProvider?.status === WebSocketStatus.Disconnected
|
remoteProvider?.status === WebSocketStatus.Disconnected
|
||||||
) {
|
) {
|
||||||
const reconnectTimeout = setTimeout(
|
resetIdle();
|
||||||
() => {
|
remoteProvider.connect();
|
||||||
remoteProvider.connect();
|
setTimeout(() => {
|
||||||
resetIdle();
|
setIsCollabReady(true);
|
||||||
},
|
}, 600);
|
||||||
collabRetryCount.current > 2 ? 3000 : 0,
|
|
||||||
);
|
|
||||||
|
|
||||||
setIsCollabReady(true);
|
|
||||||
|
|
||||||
return () => clearTimeout(reconnectTimeout);
|
|
||||||
}
|
}
|
||||||
}, [isIdle, documentState, remoteProvider?.status]);
|
}, [isIdle, documentState, remoteProvider]);
|
||||||
|
|
||||||
const isSynced = isLocalSynced && isRemoteSynced;
|
const isSynced = isLocalSynced && isRemoteSynced;
|
||||||
|
|
||||||
@ -286,7 +278,7 @@ export default function PageEditor({
|
|||||||
if (
|
if (
|
||||||
!isCollabReady &&
|
!isCollabReady &&
|
||||||
isSynced &&
|
isSynced &&
|
||||||
remoteProvider.status === WebSocketStatus.Connected
|
remoteProvider?.status === WebSocketStatus.Connected
|
||||||
) {
|
) {
|
||||||
setIsCollabReady(true);
|
setIsCollabReady(true);
|
||||||
}
|
}
|
||||||
|
|||||||
9
pnpm-lock.yaml
generated
9
pnpm-lock.yaml
generated
@ -272,6 +272,9 @@ importers:
|
|||||||
js-cookie:
|
js-cookie:
|
||||||
specifier: ^3.0.5
|
specifier: ^3.0.5
|
||||||
version: 3.0.5
|
version: 3.0.5
|
||||||
|
jwt-decode:
|
||||||
|
specifier: ^4.0.0
|
||||||
|
version: 4.0.0
|
||||||
katex:
|
katex:
|
||||||
specifier: 0.16.21
|
specifier: 0.16.21
|
||||||
version: 0.16.21
|
version: 0.16.21
|
||||||
@ -6612,6 +6615,10 @@ packages:
|
|||||||
jws@3.2.2:
|
jws@3.2.2:
|
||||||
resolution: {integrity: sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==}
|
resolution: {integrity: sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==}
|
||||||
|
|
||||||
|
jwt-decode@4.0.0:
|
||||||
|
resolution: {integrity: sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==}
|
||||||
|
engines: {node: '>=18'}
|
||||||
|
|
||||||
katex@0.16.21:
|
katex@0.16.21:
|
||||||
resolution: {integrity: sha512-XvqR7FgOHtWupfMiigNzmh+MgUVmDGU2kXZm899ZkPfcuoPuFxyHmXsgATDpFZDAXCI8tvinaVcDo8PIIJSo4A==}
|
resolution: {integrity: sha512-XvqR7FgOHtWupfMiigNzmh+MgUVmDGU2kXZm899ZkPfcuoPuFxyHmXsgATDpFZDAXCI8tvinaVcDo8PIIJSo4A==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
@ -16534,6 +16541,8 @@ snapshots:
|
|||||||
jwa: 1.4.1
|
jwa: 1.4.1
|
||||||
safe-buffer: 5.2.1
|
safe-buffer: 5.2.1
|
||||||
|
|
||||||
|
jwt-decode@4.0.0: {}
|
||||||
|
|
||||||
katex@0.16.21:
|
katex@0.16.21:
|
||||||
dependencies:
|
dependencies:
|
||||||
commander: 8.3.0
|
commander: 8.3.0
|
||||||
|
|||||||
Reference in New Issue
Block a user