flatten app to repo root and update docker deployment for single-stack runtime
This commit is contained in:
16
hooks/use-auth-guard.ts
Normal file
16
hooks/use-auth-guard.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
'use client';
|
||||
|
||||
export function useAuthGuard() {
|
||||
return {
|
||||
session: {
|
||||
user: {
|
||||
id: 1,
|
||||
name: 'Local Operator',
|
||||
email: 'operator@local.fiscal',
|
||||
image: null
|
||||
}
|
||||
},
|
||||
isPending: false,
|
||||
isAuthenticated: true
|
||||
};
|
||||
}
|
||||
59
hooks/use-task-poller.ts
Normal file
59
hooks/use-task-poller.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { getTask } from '@/lib/api';
|
||||
import type { Task } from '@/lib/types';
|
||||
|
||||
type UseTaskPollerInput = {
|
||||
taskId: string | null;
|
||||
intervalMs?: number;
|
||||
onTerminalState?: (task: Task) => void;
|
||||
};
|
||||
|
||||
export function useTaskPoller({ taskId, intervalMs = 2200, onTerminalState }: UseTaskPollerInput) {
|
||||
const [task, setTask] = useState<Task | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!taskId) {
|
||||
setTask(null);
|
||||
return;
|
||||
}
|
||||
|
||||
let stopped = false;
|
||||
let timer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const poll = async () => {
|
||||
try {
|
||||
const { task: latest } = await getTask(taskId);
|
||||
|
||||
if (stopped) {
|
||||
return;
|
||||
}
|
||||
|
||||
setTask(latest);
|
||||
|
||||
if (latest.status === 'completed' || latest.status === 'failed') {
|
||||
onTerminalState?.(latest);
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
if (stopped) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
timer = setTimeout(poll, intervalMs);
|
||||
};
|
||||
|
||||
void poll();
|
||||
|
||||
return () => {
|
||||
stopped = true;
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
};
|
||||
}, [taskId, intervalMs, onTerminalState]);
|
||||
|
||||
return task;
|
||||
}
|
||||
Reference in New Issue
Block a user