fix: harden machine session fallback and clean lint
This commit is contained in:
parent
2607ca5ce3
commit
846e575637
6 changed files with 60 additions and 32 deletions
|
|
@ -994,16 +994,13 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
|
|||
const metrics = machine?.metrics ?? null
|
||||
const metricsCapturedAt = useMemo(() => getMetricsTimestamp(metrics), [metrics])
|
||||
// Live refresh the relative time label every second when we have a capture timestamp
|
||||
const [relativeTick, setRelativeTick] = useState(0)
|
||||
const [, setRelativeTick] = useState(0)
|
||||
useEffect(() => {
|
||||
if (!metricsCapturedAt) return
|
||||
const id = setInterval(() => setRelativeTick((t) => t + 1), 1000)
|
||||
return () => clearInterval(id)
|
||||
}, [metricsCapturedAt])
|
||||
const lastUpdateRelative = useMemo(
|
||||
() => (metricsCapturedAt ? formatRelativeTime(metricsCapturedAt) : null),
|
||||
[metricsCapturedAt, relativeTick]
|
||||
)
|
||||
const lastUpdateRelative = metricsCapturedAt ? formatRelativeTime(metricsCapturedAt) : null
|
||||
const hardware = metadata?.hardware
|
||||
const network = metadata?.network ?? null
|
||||
const networkInterfaces = Array.isArray(network) ? network : null
|
||||
|
|
|
|||
|
|
@ -635,7 +635,7 @@ function PortalCommentAttachmentCard({
|
|||
window.open(target, "_blank", "noopener,noreferrer")
|
||||
toast.error("Não foi possível baixar o anexo automaticamente.", { id: toastId })
|
||||
}
|
||||
}, [attachment.name, ensureUrl])
|
||||
}, [attachment.id, attachment.name, ensureUrl])
|
||||
|
||||
const resolvedUrl = url
|
||||
|
||||
|
|
|
|||
|
|
@ -650,7 +650,7 @@ function CommentAttachmentCard({
|
|||
window.open(target, "_blank", "noopener,noreferrer")
|
||||
toast.error("Não foi possível baixar o anexo automaticamente.", { id: toastId })
|
||||
}
|
||||
}, [attachment.name, ensureUrl, url])
|
||||
}, [attachment.id, attachment.name, ensureUrl, url])
|
||||
|
||||
const name = attachment.name ?? ""
|
||||
const urlLooksImage = url ? /\.(png|jpe?g|gif|webp|svg)$/i.test(url) : false
|
||||
|
|
|
|||
|
|
@ -109,6 +109,11 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|||
// carregar o contexto — se a API responder 200, assumimos que há sessão válida
|
||||
// do lado do servidor e populamos o contexto para o restante do app.
|
||||
useEffect(() => {
|
||||
if (isPending) {
|
||||
setMachineContextLoading(true)
|
||||
return
|
||||
}
|
||||
|
||||
const shouldFetch = Boolean(session?.user?.role === "machine") || !session?.user
|
||||
if (!shouldFetch) {
|
||||
setMachineContext(null)
|
||||
|
|
@ -215,7 +220,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [session?.user])
|
||||
}, [session?.user, isPending])
|
||||
|
||||
// Poll machine session periodically to reflect admin changes (e.g., deactivation)
|
||||
useEffect(() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue