Skip to content

Commit 1991ed3

Browse files
committed
feat: allow entering app name
1 parent 3a978f2 commit 1991ed3

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/components/common/DiffViewer.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react'
1+
import React, { useState, useEffect, useCallback } from 'react'
22
import styled from 'styled-components'
33
import { Alert } from 'antd'
44
import { parseDiff, withChangeSelect } from 'react-diff-view'
@@ -23,7 +23,8 @@ const DiffViewer = ({
2323
fromVersion,
2424
toVersion,
2525
selectedChanges,
26-
onToggleChangeSelection
26+
onToggleChangeSelection,
27+
appName
2728
}) => {
2829
const [isLoading, setLoading] = useState(true)
2930
const [diff, setDiff] = useState(null)
@@ -61,6 +62,16 @@ const DiffViewer = ({
6162
localStorage.setItem('viewStyle', newViewStyle)
6263
}
6364

65+
const replaceAppName = useCallback(
66+
text => {
67+
if (!appName) return text
68+
return text
69+
.replace(/RnDiffApp/g, appName)
70+
.replace(/rndiffapp/g, appName.toLowerCase())
71+
},
72+
[appName]
73+
)
74+
6475
useEffect(() => {
6576
if (!showDiff) {
6677
return
@@ -74,7 +85,7 @@ const DiffViewer = ({
7485
)).text()
7586

7687
setDiff(
77-
parseDiff(response).sort(({ newPath }) =>
88+
parseDiff(replaceAppName(response)).sort(({ newPath }) =>
7889
newPath.includes('package.json') ? -1 : 1
7990
)
8091
)
@@ -85,7 +96,7 @@ const DiffViewer = ({
8596
}
8697

8798
fetchDiff()
88-
}, [fromVersion, showDiff, toVersion])
99+
}, [appName, fromVersion, replaceAppName, showDiff, toVersion])
89100

90101
if (!showDiff) {
91102
return null

src/components/pages/Home.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ const TitleHeader = styled.h1`
4444
margin-left: 15px;
4545
`
4646

47+
const AppNameInput = styled.input`
48+
border-radius: 5px;
49+
outline: none;
50+
border: solid 1px #ddd;
51+
padding: 8px;
52+
width: 50%;
53+
margin-bottom: 8px;
54+
`
55+
4756
const StarButton = styled(({ className, ...props }) => (
4857
<div className={className}>
4958
<GitHubButton {...props} />
@@ -61,6 +70,7 @@ const Home = () => {
6170
const [settings, setSettings] = useState({
6271
[`${SHOW_LATEST_RCS}`]: false
6372
})
73+
const [appName, setAppName] = useState('')
6474

6575
useEffect(() => {
6676
if (process.env.NODE_ENV === 'production') {
@@ -114,6 +124,14 @@ const Home = () => {
114124
<Settings handleSettingsChange={handleSettingsChange} />
115125
</TitleContainer>
116126

127+
<h4>Enter your App Name.</h4>
128+
<AppNameInput
129+
value={appName}
130+
onChange={e => {
131+
setAppName(e.target.value)
132+
}}
133+
/>
134+
117135
<VersionSelector
118136
showDiff={handleShowDiff}
119137
showReleaseCandidates={settings[SHOW_LATEST_RCS]}
@@ -130,6 +148,7 @@ const Home = () => {
130148
showDiff={showDiff}
131149
fromVersion={fromVersion}
132150
toVersion={toVersion}
151+
appName={appName}
133152
/>
134153
</Page>
135154
)

0 commit comments

Comments
 (0)