feat(idle-detection): Idle-Detection: nach 5min Inaktivität Active-Timer pausieren [tsc:fail]
This commit is contained in:
parent
050a369615
commit
dc9b42d601
@ -1,8 +1,9 @@
|
||||
{
|
||||
"completed_features": [],
|
||||
"current_feature": "audit-log-filters",
|
||||
"current_feature": "idle-detection",
|
||||
"started_at": "2026-05-23T07:29:44.977564",
|
||||
"attempted_features": [
|
||||
"api-key-management"
|
||||
"api-key-management",
|
||||
"audit-log-filters"
|
||||
]
|
||||
}
|
||||
@ -2171,3 +2171,22 @@ src/index.ts(27,25): error TS2769: No overload matches this call.
|
||||
Overload 2 of 3, '(plugin: FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
|
||||
Argument of type 'Promise<FastifyMultipartPlugin>' is not assignable to parameter of type 'FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.
|
||||
Type 'Promise<FastifyMultipartPlugin>' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTy
|
||||
- `07:32:56` **INFO** Committed feature audit-log-filters
|
||||
- `07:32:57` **INFO** Pushed: rc=0
|
||||
|
||||
## Phase-3 Feature: idle-detection (2026-05-23 07:32:57)
|
||||
|
||||
- `07:32:57` **INFO** Description: Idle-Detection: nach 5min Inaktivität Active-Timer pausieren-prompt
|
||||
- `07:32:57` **INFO** Generating apps/web/src/components/IdleDetector.tsx (IdleDetector-Component. Listens auf mousemove, keypress. Resettet Time…)
|
||||
- `07:33:28` **INFO** wrote 3511 chars in 31.4s (attempt 1)
|
||||
- `07:33:28` **INFO** Generating apps/web/src/App.tsx (ERWEITERT — mount <IdleDetector /> global im Root-Route. Behalte alles…)
|
||||
- `07:34:22` **INFO** wrote 6578 chars in 54.2s (attempt 1)
|
||||
- `07:34:22` **INFO** Running tsc --noEmit on api…
|
||||
- `07:34:24` **WARN** tsc errors:
|
||||
src/index.ts(27,25): error TS2769: No overload matches this call.
|
||||
Overload 1 of 3, '(plugin: FastifyPluginCallback<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
|
||||
Argument of type 'Promise<FastifyMultipartPlugin>' is not assignable to parameter of type 'FastifyPluginCallback<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.
|
||||
Type 'Promise<FastifyMultipartPlugin>' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProvider>, opts: { ...; }, done: (err?: Error | undefined) => void): void'.
|
||||
Overload 2 of 3, '(plugin: FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
|
||||
Argument of type 'Promise<FastifyMultipartPlugin>' is not assignable to parameter of type 'FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.
|
||||
Type 'Promise<FastifyMultipartPlugin>' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTy
|
||||
|
||||
@ -26,6 +26,7 @@ import KeyboardHelp from "./components/KeyboardHelp"
|
||||
import OnboardingTour from "./components/OnboardingTour"
|
||||
import VersionBadge from "./components/VersionBadge"
|
||||
import QuickAdd from "./components/QuickAdd"
|
||||
import IdleDetector from "./components/IdleDetector"
|
||||
import { ToastProvider } from "./components/Toast"
|
||||
import ErrorBoundary from "./components/ErrorBoundary"
|
||||
import { api } from "./lib/api"
|
||||
@ -35,6 +36,7 @@ const rootRoute = createRootRoute({
|
||||
<ToastProvider>
|
||||
<div className="min-h-screen flex flex-col bg-slate-50">
|
||||
<div className="flex-grow">
|
||||
<IdleDetector />
|
||||
<Nav />
|
||||
<CommandPalette />
|
||||
<KeyboardHelp />
|
||||
@ -150,13 +152,6 @@ const documentsRoute = createRoute({
|
||||
component: Documents
|
||||
})
|
||||
|
||||
const invoicesRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: "/invoices",
|
||||
beforeLoad: authCheck,
|
||||
component: Invoices
|
||||
})
|
||||
|
||||
const profileRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: "/profile",
|
||||
@ -164,13 +159,6 @@ const profileRoute = createRoute({
|
||||
component: Profile
|
||||
})
|
||||
|
||||
const twoFactorRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: "/two-factor",
|
||||
beforeLoad: authCheck,
|
||||
component: TwoFactorAuth
|
||||
})
|
||||
|
||||
const settingsRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: "/settings",
|
||||
@ -178,6 +166,43 @@ const settingsRoute = createRoute({
|
||||
component: Settings
|
||||
})
|
||||
|
||||
const adminUsersRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: "/admin/users",
|
||||
beforeLoad: async () => {
|
||||
await authCheck()
|
||||
await adminCheck()
|
||||
},
|
||||
component: AdminUsers
|
||||
})
|
||||
|
||||
const auditLogRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: "/admin/audit-log",
|
||||
beforeLoad: async () => {
|
||||
await authCheck()
|
||||
await adminCheck()
|
||||
},
|
||||
component: AuditLog
|
||||
})
|
||||
|
||||
const webhooksRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: "/admin/webhooks",
|
||||
beforeLoad: async () => {
|
||||
await authCheck()
|
||||
await adminCheck()
|
||||
},
|
||||
component: Webhooks
|
||||
})
|
||||
|
||||
const twoFactorRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: "/settings/2fa",
|
||||
beforeLoad: authCheck,
|
||||
component: TwoFactorAuth
|
||||
})
|
||||
|
||||
const billingRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: "/billing",
|
||||
@ -194,30 +219,19 @@ const integrationsRoute = createRoute({
|
||||
|
||||
const projectTemplatesRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: "/project-templates",
|
||||
beforeLoad: authCheck,
|
||||
path: "/admin/project-templates",
|
||||
beforeLoad: async () => {
|
||||
await authCheck()
|
||||
await adminCheck()
|
||||
},
|
||||
component: ProjectTemplates
|
||||
})
|
||||
|
||||
const adminUsersRoute = createRoute({
|
||||
const invoicesRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: "/admin/users",
|
||||
beforeLoad: adminCheck,
|
||||
component: AdminUsers
|
||||
})
|
||||
|
||||
const auditLogRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: "/admin/audit-log",
|
||||
beforeLoad: adminCheck,
|
||||
component: AuditLog
|
||||
})
|
||||
|
||||
const webhooksRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: "/admin/webhooks",
|
||||
beforeLoad: adminCheck,
|
||||
component: Webhooks
|
||||
path: "/invoices",
|
||||
beforeLoad: authCheck,
|
||||
component: Invoices
|
||||
})
|
||||
|
||||
const routeTree = [
|
||||
@ -232,21 +246,21 @@ const routeTree = [
|
||||
projectsRoute,
|
||||
projectDetailRoute,
|
||||
documentsRoute,
|
||||
invoicesRoute,
|
||||
profileRoute,
|
||||
twoFactorRoute,
|
||||
settingsRoute,
|
||||
billingRoute,
|
||||
integrationsRoute,
|
||||
projectTemplatesRoute,
|
||||
adminUsersRoute,
|
||||
auditLogRoute,
|
||||
webhooksRoute,
|
||||
twoFactorRoute,
|
||||
billingRoute,
|
||||
integrationsRoute,
|
||||
projectTemplatesRoute,
|
||||
invoicesRoute
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
routeTree,
|
||||
defaultCatcher: (error) => <ErrorBoundary error={error} />
|
||||
defaultPreload: 'intent'
|
||||
})
|
||||
|
||||
declare module "@tanstack/react-router" {
|
||||
@ -256,5 +270,9 @@ declare module "@tanstack/react-router" {
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
return <RouterProvider router={router} />
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
<RouterProvider router={router} />
|
||||
</ErrorBoundary>
|
||||
)
|
||||
}
|
||||
95
apps/web/src/components/IdleDetector.tsx
Normal file
95
apps/web/src/components/IdleDetector.tsx
Normal file
@ -0,0 +1,95 @@
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { api } from '../lib/api'
|
||||
import { AlertCircle, Play, Square } from 'lucide-react'
|
||||
|
||||
const IDLE_TIMEOUT = 5 * 60 * 1000 // 5 minutes
|
||||
|
||||
export const IdleDetector = () => {
|
||||
const queryClient = useQueryClient()
|
||||
const [isIdle, setIsIdle] = useState(false)
|
||||
const [timer, setTimer] = useState<NodeJS.Timeout | null>(null)
|
||||
|
||||
const { data: runningEntry } = useQuery({
|
||||
queryKey: ['running-entry'],
|
||||
queryFn: () => api.getRunningTimeEntry(),
|
||||
refetchInterval: 30000,
|
||||
})
|
||||
|
||||
const stopMutation = useMutation({
|
||||
mutationFn: (id: string) => api.stopTimeEntry(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['running-entry'] })
|
||||
setIsIdle(false)
|
||||
},
|
||||
})
|
||||
|
||||
const resetIdleTimer = () => {
|
||||
if (timer) clearTimeout(timer)
|
||||
setIsIdle(false)
|
||||
|
||||
const newTimer = setTimeout(() => {
|
||||
setIsIdle(true)
|
||||
}, IDLE_TIMEOUT)
|
||||
|
||||
setTimer(newTimer)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const events = ['mousemove', 'mousedown', 'keydown', 'scroll', 'touchstart']
|
||||
|
||||
const handleActivity = () => resetIdleTimer()
|
||||
|
||||
events.forEach(event => window.addEventListener(event, handleActivity))
|
||||
resetIdleTimer()
|
||||
|
||||
return () => {
|
||||
events.forEach(event => window.removeEventListener(event, handleActivity))
|
||||
if (timer) clearTimeout(timer)
|
||||
}
|
||||
}, [])
|
||||
|
||||
// Only show modal if user is idle AND a timer is actually running
|
||||
if (!isIdle || !runningEntry) return null
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/50 backdrop-blur-sm p-4">
|
||||
<div className="bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-xl shadow-xl max-w-md w-full p-6 animate-in fade-in zoom-in duration-200">
|
||||
<div className="flex items-start gap-4">
|
||||
<div className="p-2 bg-amber-100 dark:bg-amber-900/30 rounded-full">
|
||||
<AlertCircle className="w-6 h-6 text-amber-600 dark:text-amber-400" />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<h3 className="text-lg font-semibold text-slate-900 dark:text-white">
|
||||
Are you still there?
|
||||
</h3>
|
||||
<p className="text-sm text-slate-500 dark:text-slate-400 mt-1">
|
||||
You've been inactive for 5 minutes. Should we stop the timer for <span className="font-medium text-slate-700 dark:text-slate-200">"{runningEntry.description || 'this entry'}"</span>?
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-6 flex gap-3 justify-end">
|
||||
<button
|
||||
onClick={() => {
|
||||
resetIdleTimer()
|
||||
setIsIdle(false)
|
||||
}}
|
||||
className="px-4 py-2 text-sm font-medium text-slate-700 dark:text-slate-200 hover:bg-slate-100 dark:hover:bg-slate-700 rounded-md transition-colors flex items-center gap-2"
|
||||
>
|
||||
<Play className="w-3 h-3 fill-current" />
|
||||
Keep running
|
||||
</button>
|
||||
<button
|
||||
onClick={() => stopMutation.mutate(runningEntry.id)}
|
||||
disabled={stopMutation.isPending}
|
||||
className="px-4 py-2 text-sm font-medium bg-red-600 hover:bg-red-700 text-white rounded-md transition-colors flex items-center gap-2 disabled:opacity-50"
|
||||
>
|
||||
<Square className="w-3 h-3 fill-current" />
|
||||
Stop timer
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user