diff --git a/pkg/arvo/lib/graph-view.hoon b/pkg/arvo/lib/graph-view.hoon index f6dbad7781..22e876a713 100644 --- a/pkg/arvo/lib/graph-view.hoon +++ b/pkg/arvo/lib/graph-view.hoon @@ -1,4 +1,4 @@ -/- sur=graph-view +/- sur=graph-view, store=graph-store /+ resource, group-store ^? =< [sur .] @@ -53,12 +53,7 @@ to+(uf ~ (mu dejs:resource)) == :: - ++ pending-indices (op nu ;~(pfix fas (more fas dem))) - :: NOTE: move these functions to zuse - ++ nu :: parse number as hex - |= jon=json - ?> ?=([%s *] jon) - (rash p.jon hex) + ++ pending-indices (op hex (su ;~(pfix fas (more fas dem)))) :: ++ invite !! :: @@ -69,24 +64,25 @@ == -- -- +:: ++ enjs =, enjs:format |% ++ action - |= act=action + |= act=^action ^- json ?> ?=(%pending-indices -.act) %+ frond %pending-indices - :- %a + %- pairs %+ turn ~(tap by pending.act) |= [h=hash:store i=index:store] - %- pairs - :~ [%index (index i)] - [%hash s+(scot %ux h)] - == + ^- [@t json] + =/ idx (index i) + ?> ?=(%s -.idx) + [p.idx s+(scot %ux h)] :: ++ index - |= i=^index + |= i=index:store ^- json ?: =(~ i) s+'/' =/ j=^tape "" diff --git a/pkg/interface/src/logic/api/graph.ts b/pkg/interface/src/logic/api/graph.ts index 642930f143..597c371335 100644 --- a/pkg/interface/src/logic/api/graph.ts +++ b/pkg/interface/src/logic/api/graph.ts @@ -192,14 +192,6 @@ 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({ @@ -235,17 +227,30 @@ export default class GraphApi extends BaseApi { } }; - // 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); + const pendingPromise = this.spider( + 'graph-update', + 'graph-view-action', + 'graph-add-nodes', + action + ); + markPending(action['add-nodes'].nodes); - action['add-nodes'].resource.ship = action['add-nodes'].resource.ship.slice(1); - console.log(action); - this.store.handleEvent({ data: { 'graph-update': action } }); - return promise; + action['add-nodes'].resource.ship = + action['add-nodes'].resource.ship.slice(1); + + return pendingPromise.then((pendingHashes) => { + action['add-nodes'].nodes = + Object.keys(action['add-nodes'].nodes).map((ind) => { + action['add-nodes'].nodes[ind].post.hash = + pendingHashes['pending-indices'][ind] || null; + return action['add-nodes'].nodes[ind]; + }); + + this.store.handleEvent({ data: { + 'graph-update': action, + 'pending-indices': pendingHashes + } }); + }); } removeNodes(ship: Patp, name: string, indices: string[]) { diff --git a/pkg/interface/src/logic/reducers/graph-update.js b/pkg/interface/src/logic/reducers/graph-update.js index 66afdd45a3..11e319f2e3 100644 --- a/pkg/interface/src/logic/reducers/graph-update.js +++ b/pkg/interface/src/logic/reducers/graph-update.js @@ -95,15 +95,18 @@ const mapifyChildren = (children) => { }; const addNodes = (json, state) => { + console.log(json); const _addNode = (graph, index, node) => { // set child of graph if (index.length === 1) { + console.log(node.post); graph.set(index[0], node); return graph; } // set parent of graph let parNode = graph.get(index[0]); + console.log(parNode.post); if (!parNode) { console.error('parent node does not exist, cannot add child'); return; @@ -138,7 +141,6 @@ const addNodes = (json, state) => { if (index.length === 0) { return; } node.children = mapifyChildren(node?.children || {}); - state.graphs[resource] = _addNode( state.graphs[resource], diff --git a/pkg/interface/src/logic/store/store.ts b/pkg/interface/src/logic/store/store.ts index b2ab60c6c8..d6d5252107 100644 --- a/pkg/interface/src/logic/store/store.ts +++ b/pkg/interface/src/logic/store/store.ts @@ -96,6 +96,7 @@ export default class GlobalStore extends BaseStore { notificationsCount: 0, settings: {}, pendingJoin: {}, + pendingIndices: {} }; } diff --git a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx index 664e4e9ac5..1ce9f1ff1e 100644 --- a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx +++ b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx @@ -78,7 +78,7 @@ class ChatInput extends Component { props.deleteMessage(); - props.api.graph.addPost(ship,name, post); + props.api.graph.addPost(ship, name, post); } uploadSuccess(url) {