Skip to content

Commit

Permalink
Fix project initial state and bulk sync creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyjor committed Oct 13, 2024
1 parent 61adfbb commit 3b41834
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
12 changes: 10 additions & 2 deletions src/pages/ProjectPage/ProjectPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ class ProjectPage extends Component {
}

componentDidMount() {
ipcRenderer.invoke('api:initializeProjectState', this.projectName);
const newState = ipcRenderer.sendSync(
'api:initializeProjectState',
this.projectName,
);

this.setState({
...this.state,
...newState,
});

const self = this;
ipcRenderer.on('UpdateProjectPageState', function (e, newState) {
Expand Down Expand Up @@ -466,7 +474,6 @@ class ProjectPage extends Component {
})
.then(() => {
// refresh page
// window.location.reload();
fetch(
`https://api.trello.com/1/boards/${trello.id}/cards?key=${this.trelloKey}&token=${this.trelloToken}`,
{
Expand All @@ -491,6 +498,7 @@ class ProjectPage extends Component {

const nodeParentId = nodeParent.id;
if (!nodeExists) {
console.log('node doesnt exist');
NodeController.createNode(
'child',
card.name,
Expand Down
30 changes: 16 additions & 14 deletions src/services/NodeService.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ const NodeService = {
};

const parent = lokiService.parents.findOne({ id: { $eq: parentId } });
console.log('help me');
if (trelloData) {
// using trello data to create node
nodeData.trello = trelloData;
nodeData.description = trelloData.desc;
} else if (trelloAuth && parent?.trello) {
// create trello node
const url = `https://api.trello.com/1/cards?idList=${parent.trello.id}&key=${trelloAuth.key}&token=${trelloAuth.token}&name=${nodeTitle}`;

const newNodeResponse = await axios
.post(
url,
Expand All @@ -142,7 +144,7 @@ const NodeService = {
return response.data;
})
.then((data) => {
console.log(data);
console.log('node data: ', nodeData);
nodeData.trello = data;

const newNode = nodes.insert(nodeData);
Expand All @@ -160,20 +162,20 @@ const NodeService = {
.catch((err) => {
console.error(err);
});

console.log('trying to create new node');
return newNodeResponse;
} else {
const newNode = nodes.insert(nodeData);
parents
.chain()
.find({ id: parentId })
.update((parent) => {
parent.nodeIds = [...parent.nodeIds, `node-${nextId}`];
});

lokiService.saveDB();
return newNode;
}

const newNode = nodes.insert(nodeData);
parents
.chain()
.find({ id: parentId })
.update((parent) => {
parent.nodeIds = [...parent.nodeIds, `node-${nextId}`];
});

lokiService.saveDB();
return newNode;
},

deleteNode(lokiService, nodeId, parentId) {
Expand Down

0 comments on commit 3b41834

Please sign in to comment.