"use client"; import { useEffect, useRef } from "react"; import { Box, Group, Loader, ScrollArea, Stack, Text } from "@mantine/core"; import { clientApi } from "@homarr/api/client"; import { createModal } from "@homarr/modals"; import { useI18n } from "@homarr/translation/client"; interface DockerLogsModalInnerProps { id: string; name: string; tail?: number; } export const DockerLogsModal = createModal(({ innerProps }) => { const t = useI18n(); const viewportRef = useRef(null); const didInitialScrollRef = useRef(false); const { data, isPending, isError } = clientApi.docker.logs.useQuery( { id: innerProps.id, tail: innerProps.tail }, { refetchOnWindowFocus: false, retry: 0, refetchInterval: 1000, refetchIntervalInBackground: true, }, ); useEffect(() => { if (didInitialScrollRef.current) return; if (!data?.logs) return; const viewport = viewportRef.current; if (!viewport) return; viewport.scrollTop = viewport.scrollHeight; didInitialScrollRef.current = true; }, [data?.logs]); return ( {isPending ? ( ) : isError ? ( Failed to load logs ) : ( {data?.logs ? (
                {data.logs}
              
) : ( {t("common.state.empty")} )}
)}
); }).withOptions({ size: "95%", centered: true, defaultTitle: (t) => t("docker.action.logs.label"), });