Skip to content

Commit cda84ef

Browse files
authored
feat: add code copy && format code (#157)
1 parent 577eee3 commit cda84ef

File tree

19 files changed

+303
-247
lines changed

19 files changed

+303
-247
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ yarn-error.log*
3030

3131
# golang bin
3232
/api-go/bin
33+
34+
.prettierignore

.prettierrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"endOfLine": "lf",
3+
"semi": true,
4+
"singleQuote": false,
5+
"tabWidth": 2,
6+
"trailingComma": "es5"
7+
}

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"react-dom": "16.14.0",
2020
"react-scripts": "5.0.0",
2121
"react-syntax-highlighter": "15.5.0",
22-
"react-toastify": "8.2.0"
22+
"react-toastify": "8.2.0",
23+
"react-use-clipboard": "^1.0.7"
2324
},
2425
"scripts": {
2526
"dev": "BROWSER=none react-scripts start",
@@ -32,5 +33,8 @@
3233
"not dead",
3334
"not ie <= 11",
3435
"not op_mini all"
35-
]
36+
],
37+
"devDependencies": {
38+
"prettier": "2.6.0"
39+
}
3640
}

public/icon/copy-done.svg

Lines changed: 1 addition & 0 deletions
Loading

public/icon/copy.svg

Lines changed: 1 addition & 0 deletions
Loading

renovate.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"extends": [
3-
"config:base"
4-
]
2+
"extends": ["config:base"]
53
}

src/App.js

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,39 @@ import { getParameterByName } from "./utils";
1919
import CompareComponent from "./components/compare";
2020
import { DEFAULT_CONTAINER_STYLE, DEFAULT_SEARCHBAR_STYLE } from "./constants";
2121

22-
const Alert = props => {
22+
const Alert = (props) => {
2323
return <MuiAlert elevation={6} variant="filled" {...props} />;
2424
};
2525

26-
const useStyles = makeStyles(theme => ({
26+
const useStyles = makeStyles((theme) => ({
2727
button: {
28-
margin: theme.spacing(1)
28+
margin: theme.spacing(1),
2929
},
3030
textField: {
3131
marginLeft: theme.spacing(1),
3232
marginRight: theme.spacing(1),
33-
width: "50ch"
33+
width: "50ch",
3434
},
3535
searchTextField: {
36-
margin: 0
36+
margin: 0,
3737
},
3838
root: {
3939
display: "flex",
4040
flexWrap: "wrap",
4141
alignItems: "center",
42-
width: "100%"
42+
width: "100%",
4343
},
4444
autocomplete: {
4545
flex: 1,
46-
paddingTop: "5px"
46+
paddingTop: "5px",
4747
},
4848
iconButton: {
49-
padding: 10
49+
padding: 10,
5050
},
5151
divider: {
5252
height: 28,
53-
margin: 4
54-
}
53+
margin: 4,
54+
},
5555
}));
5656

5757
function TabPanel(props) {
@@ -77,13 +77,13 @@ function TabPanel(props) {
7777
TabPanel.propTypes = {
7878
children: PropTypes.node,
7979
index: PropTypes.any.isRequired,
80-
value: PropTypes.any.isRequired
80+
value: PropTypes.any.isRequired,
8181
};
8282

8383
function a11yProps(index) {
8484
return {
8585
id: `scrollable-force-tab-${index}`,
86-
"aria-controls": `scrollable-force-tabpanel-${index}`
86+
"aria-controls": `scrollable-force-tabpanel-${index}`,
8787
};
8888
}
8989

@@ -130,8 +130,8 @@ const App = () => {
130130
const classes = useStyles();
131131

132132
const showAlert = (message = "", type = "success") => {
133-
if(typeof(message === 'object' && type === 'error')){
134-
message = 'Request Error'
133+
if (typeof (message === "object" && type === "error")) {
134+
message = "Request Error";
135135
}
136136
setMessage(message);
137137
setAlertType(type);
@@ -146,7 +146,7 @@ const App = () => {
146146
setOpen(false);
147147
};
148148

149-
const updateChart = repo => {
149+
const updateChart = (repo) => {
150150
if (!contributorRepoList.includes(repo)) {
151151
setContributorRepoList([...contributorRepoList, repo]);
152152
}
@@ -156,16 +156,16 @@ const App = () => {
156156
fetch(`https://contributor-overtime-api.apiseven.com/repos?`, {
157157
method: "GET",
158158
headers: {
159-
Accept: "application/vnd.github.v3+json"
160-
}
159+
Accept: "application/vnd.github.v3+json",
160+
},
161161
})
162162
.then(function (response) {
163163
return response.json();
164164
})
165-
.then(data => {
165+
.then((data) => {
166166
setSearchOption(data.Repos || []);
167167
})
168-
.catch(e => {
168+
.catch((e) => {
169169
console.log("e: ", e);
170170
});
171171
};
@@ -188,7 +188,7 @@ const App = () => {
188188
window.parent.postMessage(
189189
{
190190
chartType:
191-
value === 0 ? "contributorOverTime" : "contributorMonthlyActivity"
191+
value === 0 ? "contributorOverTime" : "contributorMonthlyActivity",
192192
},
193193
"*"
194194
);
@@ -213,7 +213,7 @@ const App = () => {
213213
display: "flex",
214214
flexDirection: "column",
215215
justifyContent: "center",
216-
alignItems: "center"
216+
alignItems: "center",
217217
}}
218218
>
219219
<div style={searchStyle}>
@@ -231,18 +231,18 @@ const App = () => {
231231
updateChart(value);
232232
}
233233
}}
234-
renderInput={params => (
234+
renderInput={(params) => (
235235
<TextField
236236
{...params}
237237
label="Search Github Repository Name"
238238
margin="normal"
239239
variant="outlined"
240240
helperText="Keep searching to complete the comparison"
241241
className={classes.searchTextField}
242-
onChange={e => {
242+
onChange={(e) => {
243243
setRepo(e.target.value);
244244
}}
245-
onKeyPress={ev => {
245+
onKeyPress={(ev) => {
246246
if (ev.key === "Enter") {
247247
updateChart(repo);
248248
ev.preventDefault();
@@ -260,7 +260,7 @@ const App = () => {
260260
<SearchIcon />
261261
</IconButton>
262262
</InputAdornment>
263-
)
263+
),
264264
}}
265265
/>
266266
)}
@@ -269,12 +269,11 @@ const App = () => {
269269
<div>
270270
<CompareComponent
271271
list={contributorRepoList}
272-
onDelete={e => {
273-
const clonedContributorRepoList = cloneDeep(
274-
contributorRepoList
275-
);
272+
onDelete={(e) => {
273+
const clonedContributorRepoList =
274+
cloneDeep(contributorRepoList);
276275
const newContributorRepoList = clonedContributorRepoList.filter(
277-
item => item !== e
276+
(item) => item !== e
278277
);
279278
setContributorRepoList(newContributorRepoList);
280279
}}
@@ -288,7 +287,7 @@ const App = () => {
288287
style={{
289288
display: "flex",
290289
justifyContent: "center",
291-
flexDirection: "column"
290+
flexDirection: "column",
292291
}}
293292
></div>
294293
</div>
@@ -299,7 +298,7 @@ const App = () => {
299298
width: "90%",
300299
display: "flex",
301300
justifyContent: "left",
302-
padding: "5px"
301+
padding: "5px",
303302
}}
304303
>
305304
<Paper color="default" elevation={0}>
@@ -331,12 +330,12 @@ const App = () => {
331330
<ContirbutorLineChart
332331
repoList={contributorRepoList}
333332
showAlert={showAlert}
334-
onLoading={e => {
333+
onLoading={(e) => {
335334
setTabDisabled(e);
336335
}}
337-
onDelete={e => {
336+
onDelete={(e) => {
338337
setContributorRepoList(
339-
contributorRepoList.filter(item => item !== e)
338+
contributorRepoList.filter((item) => item !== e)
340339
);
341340
}}
342341
/>
@@ -345,12 +344,12 @@ const App = () => {
345344
<ActivityChart
346345
repoList={contributorRepoList}
347346
showAlert={showAlert}
348-
onLoading={e => {
347+
onLoading={(e) => {
349348
setTabDisabled(e);
350349
}}
351-
onDelete={e => {
350+
onDelete={(e) => {
352351
setContributorRepoList(
353-
contributorRepoList.filter(item => item !== e)
352+
contributorRepoList.filter((item) => item !== e)
354353
);
355354
}}
356355
/>

src/App.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import App from './App';
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import App from "./App";
44

5-
it('renders without crashing', () => {
6-
const div = document.createElement('div');
5+
it("renders without crashing", () => {
6+
const div = document.createElement("div");
77
ReactDOM.render(<App />, div);
88
ReactDOM.unmountComponentAtNode(div);
99
});

src/api/service.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const cacheRepoList = {};
2-
export const getGithubRepoList = searchText => {
2+
export const getGithubRepoList = (searchText) => {
33
return new Promise((resolve, reject) => {
44
if (cacheRepoList[searchText]) {
55
resolve(cacheRepoList[searchText]);
@@ -8,17 +8,17 @@ export const getGithubRepoList = searchText => {
88
const queryString = "q=" + encodeURIComponent(`${searchText} org:apache`);
99

1010
fetch(`https://api.github.com/search/repositories?${queryString}`)
11-
.then(response => {
11+
.then((response) => {
1212
return response.json();
1313
})
14-
.then(myJson => {
15-
const filterdData = myJson.items.map(item => item.full_name);
14+
.then((myJson) => {
15+
const filterdData = myJson.items.map((item) => item.full_name);
1616
if (!cacheRepoList[searchText]) {
1717
cacheRepoList[searchText] = filterdData;
1818
}
1919
resolve(filterdData);
2020
})
21-
.catch(e => {
21+
.catch((e) => {
2222
reject();
2323
});
2424
});

0 commit comments

Comments
 (0)