2024-09-01 14:01:45 +02:00
|
|
|
import { translationAtom } from "@/atoms/translations-atom";
|
|
|
|
import { useAtomValue } from "jotai";
|
2024-04-17 18:18:45 +02:00
|
|
|
import React, { useEffect } from "react";
|
2023-07-22 13:07:53 +02:00
|
|
|
|
|
|
|
type LogAreaProps = {
|
|
|
|
copyOnClickHandler: () => void;
|
|
|
|
isCopied: boolean;
|
|
|
|
logData: string[];
|
|
|
|
};
|
|
|
|
|
2023-09-18 20:30:43 +02:00
|
|
|
export function LogArea({
|
|
|
|
copyOnClickHandler,
|
|
|
|
isCopied,
|
|
|
|
logData,
|
|
|
|
}: LogAreaProps) {
|
2024-04-17 18:18:45 +02:00
|
|
|
const ref = React.useRef<HTMLElement>(null);
|
2024-09-01 14:01:45 +02:00
|
|
|
const t = useAtomValue(translationAtom);
|
2024-04-17 18:18:45 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (ref.current) {
|
|
|
|
ref.current.scrollTop = ref.current.scrollHeight;
|
|
|
|
}
|
|
|
|
}, [logData]);
|
|
|
|
|
2023-07-22 13:07:53 +02:00
|
|
|
return (
|
|
|
|
<div className="relative flex flex-col gap-2">
|
2023-11-22 16:54:02 +01:00
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<p className="text-sm font-medium">LOGS</p>
|
2024-04-17 18:18:45 +02:00
|
|
|
<button className="btn btn-primary btn-xs" onClick={copyOnClickHandler}>
|
2024-09-01 14:01:45 +02:00
|
|
|
{isCopied ? (
|
2024-09-03 09:34:58 +02:00
|
|
|
<span>{t("SETTINGS.LOG_AREA.ON_COPY")}</span>
|
2024-09-01 14:01:45 +02:00
|
|
|
) : (
|
2024-09-03 09:34:58 +02:00
|
|
|
<span>{t("SETTINGS.LOG_AREA.BUTTON_TITLE")}</span>
|
2024-09-01 14:01:45 +02:00
|
|
|
)}
|
2023-11-22 16:54:02 +01:00
|
|
|
</button>
|
|
|
|
</div>
|
2024-04-17 18:18:45 +02:00
|
|
|
<code
|
2024-09-01 14:01:45 +02:00
|
|
|
className="relative flex h-52 max-h-52 flex-col gap-3 overflow-y-auto break-all rounded-btn rounded-r-none bg-base-200 p-4 text-xs"
|
2024-04-17 18:18:45 +02:00
|
|
|
ref={ref}
|
|
|
|
>
|
2023-07-22 13:07:53 +02:00
|
|
|
{logData.length === 0 && (
|
2024-09-01 14:01:45 +02:00
|
|
|
<p className="text-base-content/70">
|
2024-09-03 09:34:58 +02:00
|
|
|
{t("SETTINGS.LOG_AREA.NO_LOGS")}
|
2024-09-01 14:01:45 +02:00
|
|
|
</p>
|
2023-07-22 13:07:53 +02:00
|
|
|
)}
|
|
|
|
|
|
|
|
{logData.map((logLine: any) => {
|
|
|
|
return <p className="">{logLine}</p>;
|
|
|
|
})}
|
|
|
|
</code>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|