Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions app/components/CopySingleLineTextButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ClipboardIcon } from "@heroicons/react/outline";
import { useCallback, useState } from "react";
import { CopyText } from "./CopyText";
import { Body } from "./Primitives/Body";

export type CopySingleLineTextButtonProps = {
value: string;
className?: string;
};

export function CopySingleLineTextButton({ value, className }: CopySingleLineTextButtonProps) {
const [copied, setCopied] = useState(false);
const onCopied = useCallback(() => {
setCopied(true);
const timeout = setTimeout(() => {
setCopied(false);
}, 1500);
}, [value]);
return (
<CopyText className={`${className}`} value={value} onCopied={onCopied}>
{copied ? (
<Body>Copied!</Body>
) : (
<div className="flex items-center">
<ClipboardIcon className="h-4 w-4 mr-[2px]" />
<Body>Copy As Single Line</Body>
</div>
)}
</CopyText>
);
}
9 changes: 9 additions & 0 deletions app/components/JsonPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { CopyTextButton } from "./CopyTextButton";
import { useTheme } from "./ThemeProvider";
import {usePreferences} from '~/components/PreferencesProvider';
import { useHotkeys } from "react-hotkeys-hook";
import { CopySingleLineTextButton } from './CopySingleLineTextButton';

export type JsonPreviewProps = {
json: unknown;
Expand All @@ -31,6 +32,10 @@ export function JsonPreview({ json, highlightPath }: JsonPreviewProps) {
return jsonMap.stringify(json, null, preferences?.indent || 2);
}, [json, preferences]);

const jsonMappedSingleLine = useMemo(() => {
return jsonMap.stringify(json);
}, [json]);

const lines: LineRange | undefined = useMemo(() => {
if (!highlightPath) {
return;
Expand Down Expand Up @@ -116,6 +121,10 @@ export function JsonPreview({ json, highlightPath }: JsonPreviewProps) {
hovering ? "opacity-100" : "opacity-0"
}`}
>
<CopySingleLineTextButton
value={jsonMappedSingleLine.json}
className="bg-slate-200 hover:bg-slate-300 h-fit mr-1 px-2 py-0.5 rounded-sm transition hover:cursor-pointer dark:text-white dark:bg-slate-700 dark:hover:bg-slate-600"
></CopySingleLineTextButton>
<CopyTextButton
value={jsonMapped.json}
className="bg-slate-200 hover:bg-slate-300 h-fit mr-1 px-2 py-0.5 rounded-sm transition hover:cursor-pointer dark:text-white dark:bg-slate-700 dark:hover:bg-slate-600"
Expand Down