Files
yaak/src-web/components/responseViewers/ImageViewer.tsx
Gregory Schier c9b4e6181c Use new theme vars (#63)
This PR swaps the theme to use the new stuff from the Theme Studio
2024-08-13 07:44:28 -07:00

41 lines
1013 B
TypeScript

import { convertFileSrc } from '@tauri-apps/api/core';
import classNames from 'classnames';
import { useState } from 'react';
import type { HttpResponse } from '@yaakapp/api';
interface Props {
response: HttpResponse;
className?: string;
}
export function ImageViewer({ response, className }: Props) {
const bytes = response.contentLength ?? 0;
const [show, setShow] = useState(bytes < 3 * 1000 * 1000);
if (response.bodyPath === null) {
return <div>Empty response body</div>;
}
const src = convertFileSrc(response.bodyPath);
if (!show) {
return (
<>
<div className="italic text-text-subtlest">
Response body is too large to preview.{' '}
<button className="cursor-pointer underline hover:text" onClick={() => setShow(true)}>
Show anyway
</button>
</div>
</>
);
}
return (
<img
src={src}
alt="Response preview"
className={classNames(className, 'max-w-full max-h-full')}
/>
);
}