Fix CompareFunctions for mobile
This commit is contained in:
@@ -1,10 +1,21 @@
|
|||||||
import { HStack, VStack } from "@chakra-ui/react";
|
import { HStack, VStack, useBreakpointValue } from "@chakra-ui/react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import DiffViewer, { DiffMethod } from "react-diff-viewer";
|
import DiffViewer, { DiffMethod } from "react-diff-viewer";
|
||||||
import Prism from "prismjs";
|
import Prism from "prismjs";
|
||||||
import "prismjs/components/prism-javascript";
|
import "prismjs/components/prism-javascript";
|
||||||
import "prismjs/themes/prism.css"; // choose a theme you like
|
import "prismjs/themes/prism.css"; // choose a theme you like
|
||||||
|
|
||||||
|
const highlightSyntax = (str: string) => {
|
||||||
|
let highlighted;
|
||||||
|
try {
|
||||||
|
highlighted = Prism.highlight(str, Prism.languages.javascript as Prism.Grammar, "javascript");
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Error highlighting:", e);
|
||||||
|
highlighted = str;
|
||||||
|
}
|
||||||
|
return <pre style={{ display: "inline" }} dangerouslySetInnerHTML={{ __html: highlighted }} />;
|
||||||
|
};
|
||||||
|
|
||||||
const CompareFunctions = ({
|
const CompareFunctions = ({
|
||||||
originalFunction,
|
originalFunction,
|
||||||
newFunction = "",
|
newFunction = "",
|
||||||
@@ -12,23 +23,24 @@ const CompareFunctions = ({
|
|||||||
originalFunction: string;
|
originalFunction: string;
|
||||||
newFunction?: string;
|
newFunction?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const highlightSyntax = (str: string) => {
|
const showSplitView = useBreakpointValue(
|
||||||
let highlighted;
|
{
|
||||||
try {
|
base: false,
|
||||||
highlighted = Prism.highlight(str, Prism.languages.javascript as Prism.Grammar, "javascript");
|
md: true,
|
||||||
} catch (e) {
|
},
|
||||||
console.error("Error highlighting:", e);
|
{
|
||||||
highlighted = str;
|
fallback: "base",
|
||||||
}
|
},
|
||||||
return <pre style={{ display: "inline" }} dangerouslySetInnerHTML={{ __html: highlighted }} />;
|
);
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<HStack w="full" spacing={5}>
|
<HStack w="full" spacing={5}>
|
||||||
<VStack w="full" spacing={4} maxH="50vh" fontSize={12} lineHeight={1} overflowY="auto">
|
<VStack w="full" spacing={4} maxH="50vh" fontSize={12} lineHeight={1} overflowY="auto">
|
||||||
<DiffViewer
|
<DiffViewer
|
||||||
oldValue={originalFunction}
|
oldValue={originalFunction}
|
||||||
newValue={newFunction || originalFunction}
|
newValue={newFunction || originalFunction}
|
||||||
splitView={true}
|
splitView={showSplitView}
|
||||||
|
hideLineNumbers={!showSplitView}
|
||||||
leftTitle="Original"
|
leftTitle="Original"
|
||||||
rightTitle={newFunction ? "Modified" : "Unmodified"}
|
rightTitle={newFunction ? "Modified" : "Unmodified"}
|
||||||
disableWordDiff={true}
|
disableWordDiff={true}
|
||||||
|
|||||||
Reference in New Issue
Block a user