1- import React , { useState , useEffect } from 'react'
1+ import React , { useState , useEffect , useCallback } from 'react'
22import styled from 'styled-components'
33import { Alert } from 'antd'
44import { parseDiff , withChangeSelect } from 'react-diff-view'
@@ -8,7 +8,6 @@ import DiffSection from './Diff/DiffSection'
88import DiffLoading from './Diff/DiffLoading'
99import UsefulContentSection from './UsefulContentSection'
1010import ViewStyleOptions from './Diff/DiffViewStyleOptions'
11-
1211import CompletedFilesCounter from './CompletedFilesCounter'
1312import { AppNameWarning } from './AppNameWarning'
1413
@@ -24,7 +23,8 @@ const DiffViewer = ({
2423 fromVersion,
2524 toVersion,
2625 selectedChanges,
27- onToggleChangeSelection
26+ onToggleChangeSelection,
27+ appName
2828} ) => {
2929 const [ isLoading , setLoading ] = useState ( true )
3030 const [ diff , setDiff ] = useState ( null )
@@ -62,6 +62,16 @@ const DiffViewer = ({
6262 localStorage . setItem ( 'viewStyle' , newViewStyle )
6363 }
6464
65+ const replaceAppName = useCallback (
66+ text => {
67+ if ( ! appName ) return text
68+ return text
69+ . replace ( / R n D i f f A p p / g, appName )
70+ . replace ( / r n d i f f a p p / g, appName . toLowerCase ( ) )
71+ } ,
72+ [ appName ]
73+ )
74+
6575 useEffect ( ( ) => {
6676 if ( ! showDiff ) {
6777 return
@@ -75,7 +85,7 @@ const DiffViewer = ({
7585 ) . text ( )
7686
7787 setDiff (
78- parseDiff ( response ) . sort ( ( { newPath } ) =>
88+ parseDiff ( replaceAppName ( response ) ) . sort ( ( { newPath } ) =>
7989 newPath . includes ( 'package.json' ) ? - 1 : 1
8090 )
8191 )
@@ -85,8 +95,13 @@ const DiffViewer = ({
8595 setLoading ( false )
8696 }
8797
88- fetchDiff ( )
89- } , [ fromVersion , showDiff , toVersion ] )
98+ const debounce = setTimeout ( ( ) => {
99+ fetchDiff ( )
100+ } , 750 )
101+ return ( ) => {
102+ clearTimeout ( debounce )
103+ }
104+ } , [ appName , fromVersion , replaceAppName , showDiff , toVersion ] )
90105
91106 if ( ! showDiff ) {
92107 return null
0 commit comments