From 7c18df399cb43d96bb8a54ecb65f35dd4ea60c82 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Fri, 26 Feb 2021 16:59:13 -0600 Subject: [PATCH] interface: beginnings of api/reducer integration --- pkg/arvo/lib/graph-view.hoon | 4 ++-- pkg/arvo/sur/graph-view.hoon | 2 +- pkg/arvo/ted/graph/add-nodes.hoon | 8 ++++---- pkg/interface/src/logic/api/graph.ts | 16 +++++++++++++++- pkg/interface/src/logic/reducers/graph-update.js | 4 ++++ 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/pkg/arvo/lib/graph-view.hoon b/pkg/arvo/lib/graph-view.hoon index a773df47b4..f6dbad7781 100644 --- a/pkg/arvo/lib/graph-view.hoon +++ b/pkg/arvo/lib/graph-view.hoon @@ -53,7 +53,7 @@ to+(uf ~ (mu dejs:resource)) == :: - ++ pending-indices (op ;~(pfix fas (more fas dem)) nu) + ++ pending-indices (op nu ;~(pfix fas (more fas dem))) :: NOTE: move these functions to zuse ++ nu :: parse number as hex |= jon=json @@ -79,7 +79,7 @@ %+ frond %pending-indices :- %a %+ turn ~(tap by pending.act) - |= [i=index:store h=hash:store] + |= [h=hash:store i=index:store] %- pairs :~ [%index (index i)] [%hash s+(scot %ux h)] diff --git a/pkg/arvo/sur/graph-view.hoon b/pkg/arvo/sur/graph-view.hoon index b5a72e7b2e..939ac433a7 100644 --- a/pkg/arvo/sur/graph-view.hoon +++ b/pkg/arvo/sur/graph-view.hoon @@ -42,7 +42,7 @@ [%groupify rid=resource to=(unit resource)] [%forward rid=resource =update:store] [%eval =cord] - [%pending-indices pending=(map index:store hash:store)] + [%pending-indices pending=(map hash:store index:store)] == -- diff --git a/pkg/arvo/ted/graph/add-nodes.hoon b/pkg/arvo/ted/graph/add-nodes.hoon index 463969c7a7..5f8d4f2be5 100644 --- a/pkg/arvo/ted/graph/add-nodes.hoon +++ b/pkg/arvo/ted/graph/add-nodes.hoon @@ -108,11 +108,11 @@ :: ++ nodes-to-pending-indices |= nodes=(map index:store node:store) - ^- (map index:store hash:store) - %- ~(gas by *(map index:store hash:store)) + ^- (map hash:store index:store) + %- ~(gas by *(map hash:store index:store)) %+ turn ~(tap by nodes) |= [=index:store =node:store] - ^- [index:store hash:store] + ^- [hash:store index:store] ?> ?=(^ hash.post.node) - [index u.hash.post.node] + [u.hash.post.node index] -- diff --git a/pkg/interface/src/logic/api/graph.ts b/pkg/interface/src/logic/api/graph.ts index 0606a2c1e8..642930f143 100644 --- a/pkg/interface/src/logic/api/graph.ts +++ b/pkg/interface/src/logic/api/graph.ts @@ -192,6 +192,15 @@ export default class GraphApi extends BaseApi { }); } + addHashedNodes(action: Object) { + return this.spider( + 'graph-update', + 'graph-view-action', + 'graph-add-nodes', + action + ); + } + addGraph(ship: Patp, name: string, graph: any, mark: any) { return this.storeAction({ 'add-graph': { @@ -226,7 +235,12 @@ export default class GraphApi extends BaseApi { } }; - const promise = this.hookAction(ship, action); + // TODO: send a request to the -graph-add-nodes thread and wait for its return + // once it returns, it should give us a { pending: {'/1': '0x.239823'} } + // then, mark those pending nodes with their corresponding hash + // and store the pending map we were given + //const promise = this.hookAction(ship, action); + const promise = this.addHashedNodes(action); markPending(action['add-nodes'].nodes); action['add-nodes'].resource.ship = action['add-nodes'].resource.ship.slice(1); console.log(action); diff --git a/pkg/interface/src/logic/reducers/graph-update.js b/pkg/interface/src/logic/reducers/graph-update.js index c1fe98fbea..66afdd45a3 100644 --- a/pkg/interface/src/logic/reducers/graph-update.js +++ b/pkg/interface/src/logic/reducers/graph-update.js @@ -123,6 +123,10 @@ const addNodes = (json, state) => { } state.graphKeys.add(resource); + // TODO: + // check if any of these hashes already exist. if they do, delete the + // old index before adding + for (let index in data.nodes) { let node = data.nodes[index]; if (index.split('/').length === 0) { return; }