1- import React , { useEffect , useState } from "react" ;
1+ import React , { useEffect , useState , useCallback } from "react" ;
22import { useTranslation } from "react-i18next" ;
33import { PromptItem } from "@sleek-types" ;
44
@@ -18,63 +18,69 @@ const ArchiveComponent: React.FC<ArchiveComponentProps> = ({
1818 number | undefined
1919 > ( undefined ) ;
2020
21- const handleArchiveAllConfirm = ( ) : void => {
21+ const handleArchiveAllConfirm = useCallback ( ( ) : void => {
2222 ipcRenderer . send ( "archiveTodos" ) ;
23- } ;
23+ } , [ ] ) ;
2424
25- const handleArchiveSingleConfirm = ( ) : void => {
25+ const handleArchiveSingleConfirm = useCallback ( ( ) : void => {
2626 ipcRenderer . send ( "archiveSingleTodo" , archiveLineNumber ) ;
27- } ;
27+ } , [ archiveLineNumber ] ) ;
2828
29- const handleOpenDoneFile = ( ) : void => {
29+ const handleOpenDoneFile = useCallback ( ( ) : void => {
3030 ipcRenderer . send ( "openFile" , true , archiveLineNumber ) ;
31- } ;
31+ } , [ archiveLineNumber ] ) ;
3232
33- const handleCreateDoneFile = ( ) : void => {
33+ const handleCreateDoneFile = useCallback ( ( ) : void => {
3434 ipcRenderer . send ( "createFile" , true , archiveLineNumber ) ;
35- } ;
36-
37- const handleTriggerArchiving = (
38- doneFileAvailable : boolean ,
39- lineNumber ?: number ,
40- ) : void => {
41- setArchiveLineNumber ( lineNumber ) ;
42-
43- // Define prompt items here to get fresh translations every time
44- const promptItemArchivingAll = {
45- id : "archive" ,
46- headline : t ( "prompt.archive.headline" ) ,
47- text : t ( "prompt.archive.text" ) ,
48- button1 : t ( "archive" ) ,
49- onButton1 : handleArchiveAllConfirm ,
50- } ;
51-
52- const promptItemArchivingSingle = {
53- id : "archive" ,
54- headline : t ( "prompt.archive.headline.single" ) ,
55- text : t ( "prompt.archive.text.single" ) ,
56- button1 : t ( "archive" ) ,
57- onButton1 : handleArchiveSingleConfirm ,
58- } ;
59-
60- const promptItemChooseChangeFile = {
61- id : "changeFile" ,
62- headline : t ( "prompt.archive.changeFile.headline" ) ,
63- text : t ( "prompt.archive.changeFile.text" ) ,
64- button1 : t ( "openFile" ) ,
65- onButton1 : handleOpenDoneFile ,
66- button2 : t ( "createFile" ) ,
67- onButton2 : handleCreateDoneFile ,
68- } ;
69-
70- setPromptItem (
71- doneFileAvailable
72- ? lineNumber
73- ? promptItemArchivingSingle
74- : promptItemArchivingAll
75- : promptItemChooseChangeFile ,
76- ) ;
77- } ;
35+ } , [ archiveLineNumber ] ) ;
36+
37+ const handleTriggerArchiving = useCallback (
38+ ( doneFileAvailable : boolean , lineNumber ?: number ) : void => {
39+ setArchiveLineNumber ( lineNumber ) ;
40+
41+ // Define prompt items here to get fresh translations every time
42+ const promptItemArchivingAll = {
43+ id : "archive" ,
44+ headline : t ( "prompt.archive.headline" ) ,
45+ text : t ( "prompt.archive.text" ) ,
46+ button1 : t ( "archive" ) ,
47+ onButton1 : handleArchiveAllConfirm ,
48+ } ;
49+
50+ const promptItemArchivingSingle = {
51+ id : "archive" ,
52+ headline : t ( "prompt.archive.headline.single" ) ,
53+ text : t ( "prompt.archive.text.single" ) ,
54+ button1 : t ( "archive" ) ,
55+ onButton1 : handleArchiveSingleConfirm ,
56+ } ;
57+
58+ const promptItemChooseChangeFile = {
59+ id : "changeFile" ,
60+ headline : t ( "prompt.archive.changeFile.headline" ) ,
61+ text : t ( "prompt.archive.changeFile.text" ) ,
62+ button1 : t ( "openFile" ) ,
63+ onButton1 : handleOpenDoneFile ,
64+ button2 : t ( "createFile" ) ,
65+ onButton2 : handleCreateDoneFile ,
66+ } ;
67+
68+ setPromptItem (
69+ doneFileAvailable
70+ ? lineNumber
71+ ? promptItemArchivingSingle
72+ : promptItemArchivingAll
73+ : promptItemChooseChangeFile ,
74+ ) ;
75+ } ,
76+ [
77+ t ,
78+ handleArchiveAllConfirm ,
79+ handleArchiveSingleConfirm ,
80+ handleOpenDoneFile ,
81+ handleCreateDoneFile ,
82+ ] ,
83+ ) ;
7884
7985 useEffect ( ( ) : void => {
8086 if ( triggerArchiving ) {
0 commit comments