Skip to content

Commit 11c466d

Browse files
authored
Merge pull request #126 from unfoldingWord/documenting_use_edit
LGTM
2 parents 1855cc1 + 5de1313 commit 11c466d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/components/file/useEdit.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import { useState } from 'react';
22
import { updateContent } from '../..';
33

4+
/**
5+
* Custom hook for editing content of translation helps resources
6+
* @param {string} sha
7+
* @param {string} repo
8+
* @param {string} owner
9+
* @param {string} token
10+
* @param {object} config - config settings for fetches (timeout, cache, etc.)
11+
* @param {string} branch - branch name.
12+
* @param {string} author - author of the edit.
13+
* @param {string} content - Edited/updated content.
14+
* @param {string} message - Optional commit message.
15+
* @param {string} filePath - file path, file path for the file being edited.
16+
* @return {{error: object, isError: boolean, isEditing: boolean, onSaveEdit: (function(_branch: string)), editResponse: object}}
17+
*/
418
export default function useEdit({
519
sha,
620
repo,
@@ -13,18 +27,21 @@ export default function useEdit({
1327
message,
1428
filepath,
1529
}) {
16-
const [{ isEditing, isError, error, editResponse }, setState] = useState({
30+
const initialState = {
1731
editResponse: null,
1832
isEditing: false,
1933
isError: false,
2034
error: null,
21-
})
35+
}
36+
const [{ isEditing, isError, error, editResponse }, setState] = useState(initialState)
2237
const { name: tokenid } = token || {}
2338
const _message = message || `Edit '${filepath}' using '${tokenid}'`;
2439

2540
async function onSaveEdit(_branch) {
2641
try {
42+
// content is the updated string or dirty content.
2743
if (content) {
44+
// clear state to remove left over state from a previous edit.
2845
setState((prevState) => ({
2946
...prevState,
3047
editResponse: null,

0 commit comments

Comments
 (0)