mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-30 14:12:07 +02:00
Response Streaming (#124)
This commit is contained in:
@@ -1,40 +1,11 @@
|
||||
import { convertFileSrc } from '@tauri-apps/api/core';
|
||||
import classNames from 'classnames';
|
||||
import { useState } from 'react';
|
||||
import type { HttpResponse } from '@yaakapp-internal/models';
|
||||
import React from 'react';
|
||||
|
||||
interface Props {
|
||||
response: HttpResponse;
|
||||
className?: string;
|
||||
bodyPath: 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')}
|
||||
/>
|
||||
);
|
||||
export function ImageViewer({ bodyPath }: Props) {
|
||||
const src = convertFileSrc(bodyPath);
|
||||
return <img src={src} alt="Response preview" className="max-w-full max-h-full pb-2" />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user