Skip to content

Commit 7a64bb5

Browse files
vincent trangvincent trang
authored andcommitted
beginning to fix save functionality where queries concated to save file
Co-authored-by: jwagner988 jwagner988@gmail.com Co-authored-by: JuiceBawks betasnetwork@gmail.com
1 parent 98aa861 commit 7a64bb5

File tree

2 files changed

+64
-17
lines changed

2 files changed

+64
-17
lines changed

frontend/components/sidebar/QueryList.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,19 @@ const globalAny: any = global;
230230
if (!show) return null;
231231
return (
232232
<>
233-
<span>
234-
<Tooltip title="New Query">
235-
<IconButton onClick={createQuery}>
236-
<AddIcon fontSize="large" />
237-
</IconButton>
238-
</Tooltip>
233+
<span>
234+
<Tooltip title="New Query">
235+
<IconButton onClick={createQuery}>
236+
<AddIcon fontSize="large" />
237+
</IconButton>
238+
</Tooltip>
239239

240-
<Tooltip title="Import Query">
241-
<IconButton onClick={loadQueryHandler}>
242-
<BathtubIcon fontSize="large"/>
243-
</IconButton>
244-
</Tooltip>
245-
</span>
240+
<Tooltip title="Import Query">
241+
<IconButton onClick={loadQueryHandler}>
242+
<BathtubIcon fontSize="large" />
243+
</IconButton>
244+
</Tooltip>
245+
</span>
246246

247247
<StyledSidebarList>
248248
{Object.values(queries).map((query: QueryData) => (

frontend/lib/queries.ts

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)