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+ */
417export default function useEdit ( {
518 sha,
619 repo,
@@ -13,18 +26,21 @@ export default function useEdit({
1326 message,
1427 filepath,
1528} ) {
16- const [ { isEditing , isError , error , editResponse } , setState ] = useState ( {
29+ const initialState = {
1730 editResponse : null ,
1831 isEditing : false ,
1932 isError : false ,
2033 error : null ,
21- } )
34+ }
35+ const [ { isEditing, isError, error, editResponse } , setState ] = useState ( initialState )
2236 const { name : tokenid } = token || { }
2337 const _message = message || `Edit '${ filepath } ' using '${ tokenid } '` ;
2438
2539 async function onSaveEdit ( _branch ) {
2640 try {
41+ // content is the updated string or dirty content.
2742 if ( content ) {
43+ // clear state to remove left over state from a previous edit.
2844 setState ( ( prevState ) => ( {
2945 ...prevState ,
3046 editResponse : null ,
0 commit comments