remove buffer file delete whe user change route
This commit is contained in:
@@ -3,36 +3,12 @@
|
|||||||
|
|
||||||
import { useEffect, useRef, useCallback } from 'react';
|
import { useEffect, useRef, useCallback } from 'react';
|
||||||
import { tokenLifeExtension } from '@/app/actions/auth';
|
import { tokenLifeExtension } from '@/app/actions/auth';
|
||||||
import { usePathname, useSearchParams } from 'next/navigation';
|
|
||||||
import { removeUserFile } from '@/app/actions/fileEntity';
|
|
||||||
|
|
||||||
export default function ActivityTracker() {
|
export default function ActivityTracker() {
|
||||||
const lastRefreshTime = useRef(Date.now());
|
const lastRefreshTime = useRef(Date.now());
|
||||||
const activityTimeoutRef = useRef<NodeJS.Timeout>(null);
|
const activityTimeoutRef = useRef<NodeJS.Timeout>(null);
|
||||||
const isRefreshing = useRef(false);
|
const isRefreshing = useRef(false);
|
||||||
|
|
||||||
|
|
||||||
const pathname = usePathname();
|
|
||||||
const searchParams = useSearchParams();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const selectedId = document.cookie
|
|
||||||
.split('; ')
|
|
||||||
.find(row => row.startsWith('searchedFileId='))
|
|
||||||
?.split('=')[1];
|
|
||||||
|
|
||||||
const handleCookie = async () => {
|
|
||||||
if (selectedId) {
|
|
||||||
await removeUserFile(selectedId, 1);
|
|
||||||
document.cookie = 'searchedFileId=; path=/; max-age=0';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (selectedId) {
|
|
||||||
handleCookie();
|
|
||||||
}
|
|
||||||
}, [pathname, searchParams]);
|
|
||||||
|
|
||||||
// Debounce функция
|
// Debounce функция
|
||||||
const debounce = useCallback((func: () => void, delay: number) => {
|
const debounce = useCallback((func: () => void, delay: number) => {
|
||||||
if (activityTimeoutRef.current) {
|
if (activityTimeoutRef.current) {
|
||||||
|
|||||||
Reference in New Issue
Block a user