mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-12 02:35:42 +00:00
feat(Core): force map page reload after 30 mins of user inactivity (switched browser/tab)
Some checks failed
Build / 🚀 Deploy to test env (fly.io) (push) Has been cancelled
Build / Manual Approval (push) Has been cancelled
Build / 🛠 Build (1.17, 18.x, 27) (push) Has been cancelled
Build / 🛠 Build Docker Images (linux/amd64) (push) Has been cancelled
Build / 🛠 Build Docker Images (linux/arm64) (push) Has been cancelled
Build / merge (push) Has been cancelled
Build / 🏷 Create Release (push) Has been cancelled
Some checks failed
Build / 🚀 Deploy to test env (fly.io) (push) Has been cancelled
Build / Manual Approval (push) Has been cancelled
Build / 🛠 Build (1.17, 18.x, 27) (push) Has been cancelled
Build / 🛠 Build Docker Images (linux/amd64) (push) Has been cancelled
Build / 🛠 Build Docker Images (linux/arm64) (push) Has been cancelled
Build / merge (push) Has been cancelled
Build / 🏷 Create Release (push) Has been cancelled
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { RefObject, useCallback } from 'react';
|
||||
import { MapHandlers } from '@/hooks/Mapper/types/mapHandlers.ts';
|
||||
import { RefObject, useCallback } from 'react';
|
||||
|
||||
// Force reload the page after 30 minutes of inactivity
|
||||
const FORCE_PAGE_RELOAD_TIMEOUT = 1000 * 60 * 30;
|
||||
|
||||
export const useMapperHandlers = (handlerRefs: RefObject<MapHandlers>[], hooksRef: RefObject<any>) => {
|
||||
const handleCommand = useCallback(
|
||||
@@ -13,7 +16,13 @@ export const useMapperHandlers = (handlerRefs: RefObject<MapHandlers>[], hooksRe
|
||||
[hooksRef.current],
|
||||
);
|
||||
|
||||
const handleMapEvent = useCallback(({ type, body }) => {
|
||||
const handleMapEvent = useCallback(({ type, body, timestamp }) => {
|
||||
const timeDiff = Date.now() - Date.parse(timestamp);
|
||||
// If the event is older than the timeout, force reload the page
|
||||
if (timeDiff > FORCE_PAGE_RELOAD_TIMEOUT) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
handlerRefs.forEach(ref => {
|
||||
if (!ref.current) {
|
||||
return;
|
||||
@@ -23,14 +32,5 @@ export const useMapperHandlers = (handlerRefs: RefObject<MapHandlers>[], hooksRe
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleMapEvents = useCallback(
|
||||
events => {
|
||||
events.forEach(event => {
|
||||
handleMapEvent(event);
|
||||
});
|
||||
},
|
||||
[handleMapEvent],
|
||||
);
|
||||
|
||||
return { handleCommand, handleMapEvent, handleMapEvents };
|
||||
return { handleCommand, handleMapEvent };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user