import { Copy07Icon } from '@expo/styleguide-icons'; import { useEffect, useState, PropsWithChildren } from 'react'; import { parseDiff, Diff, Hunk } from 'react-diff-view'; import { Snippet } from '../Snippet'; import { SnippetContent } from '../SnippetContent'; import { SnippetHeader } from '../SnippetHeader'; const randomCommitHash = () => Math.random().toString(36).slice(2, 9); // These types come from `react-diff-view` library type RenderLine = { oldRevision: string; newRevision: string; type: 'unified' | 'split'; hunks: object[]; newPath: string; oldPath: string; }; type Props = PropsWithChildren<{ source?: string; raw?: string; }>; export const DiffBlock = ({ source, raw }: Props) => { const [diff, setDiff] = useState(raw ? parseDiff(raw) : null); useEffect(() => { if (source) { const fetchDiffAsync = async () => { const response = await fetch(source); const result = await response.text(); setDiff(parseDiff(result)); }; fetchDiffAsync(); } }, [source]); if (!diff) { return null; } const renderFile = ({ oldRevision = randomCommitHash(), newRevision = randomCommitHash(), type, hunks, newPath, }: RenderLine) => ( {(hunks: any[]) => hunks.map(hunk => )} ); return <>{diff.map(renderFile)}; };