Skip to content

Commit 3a654d1

Browse files
authored
feat(gsoc'24): Project file converted to typescript (CircuitVerse#324)
1 parent 1c06dba commit 3a654d1

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/simulator/src/data/project.js renamed to src/simulator/src/data/project.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import { confirmOption } from '#/components/helpers/confirmComponent/ConfirmComp
1717
*/
1818
export async function recoverProject() {
1919
if (localStorage.getItem('recover')) {
20-
var data = JSON.parse(localStorage.getItem('recover'))
20+
const recover = localStorage.getItem('recover')
21+
const data = recover ? JSON.parse(recover) : {}
2122
if (await confirmOption(`Would you like to recover: ${data.name}`)) {
2223
load(data)
2324
}
@@ -78,11 +79,10 @@ export function openOffline() {
7879
}
7980
/**
8081
* Flag for project saved or not
81-
* @type {boolean}
8282
* @category data
8383
*/
84-
var projectSaved = true
85-
export function projectSavedSet(param) {
84+
let projectSaved = true
85+
export function projectSavedSet(param: boolean) {
8686
projectSaved = param
8787
}
8888

@@ -91,10 +91,12 @@ export function projectSavedSet(param) {
9191
* @category data
9292
*/
9393
export async function saveOffline() {
94-
const data = await generateSaveData()
94+
const data = await generateSaveData('')
9595
if (data instanceof Error) return
96-
localStorage.setItem(projectId, data)
97-
const temp = JSON.parse(localStorage.getItem('projectList')) || {}
96+
const stringData = JSON.stringify(data)
97+
localStorage.setItem(projectId, stringData)
98+
const projectList = localStorage.getItem('projectList')
99+
const temp = projectList ? JSON.parse(projectList) : {}
98100
temp[projectId] = getProjectName()
99101
localStorage.setItem('projectList', JSON.stringify(temp))
100102
showMessage(
@@ -109,8 +111,8 @@ export async function saveOffline() {
109111
function checkToSave() {
110112
let saveFlag = false
111113
// eslint-disable-next-line no-restricted-syntax
112-
for (id in scopeList) {
113-
saveFlag |= checkIfBackup(scopeList[id])
114+
for (const id in scopeList) {
115+
saveFlag = saveFlag || checkIfBackup(scopeList[id])
114116
}
115117
return saveFlag
116118
}
@@ -131,14 +133,14 @@ window.onbeforeunload = async function () {
131133
// 'You have unsaved changes on this page. Do you want to leave this page and discard your changes or stay on this page?'
132134
// )
133135
const data = await generateSaveData('Untitled')
134-
localStorage.setItem('recover', await data)
136+
const stringData = JSON.stringify(data)
137+
localStorage.setItem('recover', stringData)
135138
// eslint-disable-next-line consistent-return
136139
return 'Are u sure u want to leave? Any unsaved changes may not be recoverable'
137140
}
138141

139142
/**
140143
* Function to clear project
141-
* @category data
142144
*/
143145
export async function clearProject() {
144146
if (await confirmOption('Would you like to clear the project?')) {
@@ -152,10 +154,8 @@ export async function clearProject() {
152154

153155
/**
154156
Function used to start a new project while prompting confirmation from the user
155-
* @param {boolean} verify - flag to verify a new project
156-
* @category data
157157
*/
158-
export async function newProject(verify) {
158+
export async function newProject(verify: boolean) {
159159
if (
160160
verify ||
161161
projectSaved ||
@@ -166,7 +166,7 @@ export async function newProject(verify) {
166166
) {
167167
clearProject()
168168
localStorage.removeItem('recover')
169-
window.location = '/simulator'
169+
window.location = '/simulatorvue/'
170170

171171
setProjectName(undefined)
172172
projectId = generateId()

0 commit comments

Comments
 (0)