@@ -76,15 +76,62 @@ export const saveQuery = (
7676 queries : AppState [ 'queries' ] ,
7777 saveQuery : QueryData
7878) => {
79- const appDatatDirPath = getAppDataPath ( ) ;
80- const query = JSON . stringify ( queries ) ;
81- fs . appendFile ( appDatatDirPath , query , ( err ) => {
79+ const appDataDirPath = getAppDataPath ( ) ;
80+ // const query = JSON.stringify(queries);
81+ const query = queries
82+ // fs.appendFile(appDatatDirPath, query, (err) => {
83+ // if (err) console.log(err);
84+ // else console.log("file saved at:", appDatatDirPath)
85+ // })
86+ fs . readFile ( appDataDirPath , )
87+ fs . stat ( appDataDirPath , ( err , status ) => {
88+ // console.log(status.isDirectory());
89+ if ( status ) console . log ( status )
8290 if ( err ) console . log ( err ) ;
83- else console . log ( "file saved at:" , appDatatDirPath )
91+ else {
92+ fs . readFile ( appDataDirPath , "utf8" , ( err , data ) => {
93+ if ( err ) {
94+ console . log ( err )
95+ } else {
96+ //helper variables
97+ let helper = true ;
98+ const arr = Object . keys ( data ) ;
99+ const compared = Object . keys ( query ) [ 0 ]
100+ //checking if label is already inside data
101+ for ( let i = 0 ; i < arr . length ; i ++ ) {
102+ if ( arr [ i ] === compared ) helper = false ;
103+ }
104+ //if not already there then write it in
105+ if ( helper ) {
106+ const newData = data ;
107+ newData [ compared ] = query [ compared ]
108+ fs . writeFile ( newData , appDataDirPath )
109+ console . log ( 'file saved!' )
110+ }
111+ }
112+ } ) ;
113+ }
84114 } )
85115}
86116
87-
117+ /**
118+ fs.access(appDataDirPath, (err) => {
119+ if (err) {
120+ try {
121+ fs.writeFileSync('SeeQR Data.json', query);
122+ console.log('File saved successfully');
123+ } catch (err) {
124+ console.log(err);
125+ };
126+ } else {
127+ const data = JSON.parse(fs.readFileSync(appDataDirPath));
128+ const label = Object.keys(query)[0];
129+ data[label] = query[label];
130+ fs.writeFileSync('SeeQR Data.json', data);
131+ });
132+ };
133+ })
134+ */
88135
89136/**
90137 * Sets compare state for query
0 commit comments