Skip to content

Commit f19144f

Browse files
committed
fix: partially fix 'creating a new project clones the old one'
This bug stil occurs when when creating a project for the first time (The first clone is intentional although it will keep cloning and will presist until restarting the program). The current workaround is to create your first project then instantly restart the program. After this the bug should be gone forever. It's not perfect but it's all I can get working right now.
1 parent 58f742a commit f19144f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

app-src/scripts/main/global-services/projects-s.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
SimpleToast('ERROR', 'ERROR: There is already a project');
7474
return;
7575
}
76-
76+
7777
this.createNew(projectTitle, $rootScope.r);
7878
};
7979

@@ -100,12 +100,21 @@
100100

101101
this.createNew = (projectTitle, data) => {
102102
if (projectTitle && angular.isObject(data)) {
103+
data = $window._.omit(data, OMITTED_LS_FIELDS);
104+
103105
// save new project
104106
let newProject = {
105107
title: projectTitle,
106108
id: Uid(),
107-
data: $window._.omit(LS_DEFAULTS, OMITTED_LS_FIELDS)
109+
data: {}
108110
};
111+
112+
this.updateNewFields(newProject);
113+
114+
// update data for current new project from current data
115+
for (let field in data) {
116+
newProject.data[field] = data[field];
117+
}
109118

110119
// update $rootScope.r.projects
111120
$rootScope.r.projects.push(newProject);
@@ -115,9 +124,6 @@
115124
projects.push(newProject);
116125
AppStorage.saveProjects(projects);
117126

118-
// update data for current new project from current data
119-
this.updateProjectData(newProject.id, data);
120-
121127
// switch to new project
122128
this.changeCurrent(newProject);
123129
}
@@ -161,9 +167,9 @@
161167
this.removeOmittedFields(newCurrentProject);
162168

163169
// clean up $rootScope.r
164-
_.forOwn($rootScope, (val, property) => {
170+
_.forOwn($rootScope.r, (val, property) => {
165171
if (!angular.isFunction(val) && GLOBAL_LS_FIELDS.indexOf(property) === -1) {
166-
$rootScope.r[property] = undefined;
172+
delete $rootScope.r[property];
167173
}
168174
});
169175

@@ -173,7 +179,7 @@
173179
$rootScope.r[property] = newCurrentProject.data[property];
174180
}
175181
});
176-
182+
177183
// update ls current project
178184
$rootScope.r.currentProject = newCurrentProject;
179185
$rootScope.$broadcast(EV_PROJECT_CHANGED);

0 commit comments

Comments
 (0)