This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Mail, RefreshCw, ShieldCheck } from 'lucide-react';
|
||||
import { api, type Mailboxes } from './api';
|
||||
import {hotelTime} from './time';
|
||||
type Run=(action:()=>Promise<void>)=>Promise<void>;
|
||||
const when=(value:string|null)=>value?new Date(value).toLocaleString():'Not yet';
|
||||
export function MailboxPanel({data,owner,preview,busy,run,onChange}:{data:Mailboxes;owner:boolean;preview:boolean;busy:boolean;run:Run;onChange:(value:Mailboxes)=>void}){
|
||||
const when=(value:string|null)=>value?hotelTime(value,data.timeZone||'UTC'):'Not yet';
|
||||
const [pollError,setPollError]=useState('');
|
||||
async function refresh(){onChange(await api<Mailboxes>('/mailboxes'));setPollError('');}
|
||||
useEffect(()=>{let active=true;const timer=setInterval(()=>{if(document.hidden)return;api<Mailboxes>('/mailboxes').then(value=>{if(active){onChange(value);setPollError('');}}).catch(()=>{if(active)setPollError('Status could not be refreshed. Use Refresh status to check again.');});},30000);return()=>{active=false;clearInterval(timer);};},[onChange]);
|
||||
|
||||
Reference in New Issue
Block a user