11import { useState } from 'react' ;
22import { 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+ */
418export 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