@@ -10,6 +10,7 @@ const language = getLanguage()
1010let names : string [ ] = [ ]
1111let issuers : string [ ] = [ ]
1212let secrets : string [ ] = [ ]
13+ let uniqIds : string [ ] = [ ]
1314
1415/**
1516 * Generate the edit elements from the saved codes
@@ -31,33 +32,33 @@ const generateEditElements = () => {
3132
3233 <div>
3334 <h5>${ language . common . description } </h5>
34- <input id="name${ i } " class="input mt-1 w-96" type="text" value="${ names [ i ] } " readonly />
35+ <input id="name${ uniqIds [ i ] } " class="input mt-1 w-96" type="text" value="${ names [ i ] } " readonly />
3536 </div>
3637 </div>
3738 <div class="ml-10 flex gap-3 flex-wrap sm:mt-10 sm:w-full sm:ml-0">
38- <button id="editCode${ i } " class="button">
39+ <button id="editCode${ uniqIds [ i ] } " class="button">
3940 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z" /><path d="m15 5 4 4" /></svg>
4041 ${ language . common . edit }
4142 </button>
4243
43- <button id="deleteCode${ i } " class="button">
44+ <button id="deleteCode${ uniqIds [ i ] } " class="button">
4445 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/></svg>
4546 ${ language . common . delete }
4647 </button>
4748 </div>`
4849
4950 // add div
5051 element . classList . add ( "edit" )
51- element . setAttribute ( "id" , `edit${ i } ` )
52+ element . setAttribute ( "id" , `edit${ uniqIds [ i ] } ` )
5253
5354 document . querySelector ( ".content" ) . appendChild ( element )
5455
55- document . querySelector ( `#editCode${ i } ` ) . addEventListener ( "click" , ( ) => {
56- editCode ( i )
56+ document . querySelector ( `#editCode${ uniqIds [ i ] } ` ) . addEventListener ( "click" , ( ) => {
57+ editCode ( uniqIds [ i ] )
5758 } )
5859
59- document . querySelector ( `#deleteCode${ i } ` ) . addEventListener ( "click" , ( ) => {
60- deleteCode ( i )
60+ document . querySelector ( `#deleteCode${ uniqIds [ i ] } ` ) . addEventListener ( "click" , ( ) => {
61+ deleteCode ( uniqIds [ i ] )
6162 } )
6263 }
6364}
@@ -80,6 +81,7 @@ export const loadSavedCodes = async () => {
8081 names = data . names
8182 issuers = data . issuers
8283 secrets = data . secrets
84+ uniqIds = data . uniqIds
8385
8486 generateEditElements ( )
8587}
@@ -104,7 +106,9 @@ export const saveChanges = async () => {
104106/**
105107 * Edit a specific code
106108 */
107- export const editCode = async ( id : number ) => {
109+ export const editCode = async ( uniqId : string ) => {
110+ const id = uniqIds . indexOf ( uniqId )
111+
108112 const issuer : HTMLInputElement = document . querySelector ( `#issuer${ id } ` )
109113 const name : HTMLInputElement = document . querySelector ( `#name${ id } ` )
110114
@@ -145,15 +149,17 @@ export const editCode = async (id: number) => {
145149/**
146150 * Delete a specific code
147151 */
148- export const deleteCode = async ( id : number ) => {
152+ export const deleteCode = async ( uniqId : string ) => {
153+ const id = uniqIds . indexOf ( uniqId )
154+
149155 const res = await dialog . ask ( language . edit . dialog . deleteCode , { type : "warning" } )
150156
151157 if ( res === true ) {
152158 names . splice ( id , 1 )
153159 secrets . splice ( id , 1 )
154160 issuers . splice ( id , 1 )
155161
156- document . querySelector ( `#edit${ id } ` ) . remove ( )
162+ document . querySelector ( `#edit${ uniqId } ` ) . remove ( )
157163
158164 saveChanges ( )
159165 }
0 commit comments