graph-view: use all of the proper types, get the API call working to send up the proper hashes

This commit is contained in:
Logan Allen 2021-03-01 17:24:21 -06:00
parent 7c18df399c
commit a9232d0df7
5 changed files with 38 additions and 34 deletions

View File

@ -1,4 +1,4 @@
/- sur=graph-view /- sur=graph-view, store=graph-store
/+ resource, group-store /+ resource, group-store
^? ^?
=< [sur .] =< [sur .]
@ -53,12 +53,7 @@
to+(uf ~ (mu dejs:resource)) to+(uf ~ (mu dejs:resource))
== ==
:: ::
++ pending-indices (op nu ;~(pfix fas (more fas dem))) ++ pending-indices (op hex (su ;~(pfix fas (more fas dem))))
:: NOTE: move these functions to zuse
++ nu :: parse number as hex
|= jon=json
?> ?=([%s *] jon)
(rash p.jon hex)
:: ::
++ invite !! ++ invite !!
:: ::
@ -69,24 +64,25 @@
== ==
-- --
-- --
::
++ enjs ++ enjs
=, enjs:format =, enjs:format
|% |%
++ action ++ action
|= act=action |= act=^action
^- json ^- json
?> ?=(%pending-indices -.act) ?> ?=(%pending-indices -.act)
%+ frond %pending-indices %+ frond %pending-indices
:- %a %- pairs
%+ turn ~(tap by pending.act) %+ turn ~(tap by pending.act)
|= [h=hash:store i=index:store] |= [h=hash:store i=index:store]
%- pairs ^- [@t json]
:~ [%index (index i)] =/ idx (index i)
[%hash s+(scot %ux h)] ?> ?=(%s -.idx)
== [p.idx s+(scot %ux h)]
:: ::
++ index ++ index
|= i=^index |= i=index:store
^- json ^- json
?: =(~ i) s+'/' ?: =(~ i) s+'/'
=/ j=^tape "" =/ j=^tape ""

View File

@ -192,14 +192,6 @@ export default class GraphApi extends BaseApi<StoreState> {
}); });
} }
addHashedNodes(action: Object) {
return this.spider(
'graph-update',
'graph-view-action',
'graph-add-nodes',
action
);
}
addGraph(ship: Patp, name: string, graph: any, mark: any) { addGraph(ship: Patp, name: string, graph: any, mark: any) {
return this.storeAction({ return this.storeAction({
@ -235,17 +227,30 @@ export default class GraphApi extends BaseApi<StoreState> {
} }
}; };
// TODO: send a request to the -graph-add-nodes thread and wait for its return const pendingPromise = this.spider(
// once it returns, it should give us a { pending: {'/1': '0x.239823'} } 'graph-update',
// then, mark those pending nodes with their corresponding hash 'graph-view-action',
// and store the pending map we were given 'graph-add-nodes',
//const promise = this.hookAction(ship, action); action
const promise = this.addHashedNodes(action); );
markPending(action['add-nodes'].nodes); markPending(action['add-nodes'].nodes);
action['add-nodes'].resource.ship = action['add-nodes'].resource.ship.slice(1); action['add-nodes'].resource.ship =
console.log(action); action['add-nodes'].resource.ship.slice(1);
this.store.handleEvent({ data: { 'graph-update': action } });
return promise; 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[]) { removeNodes(ship: Patp, name: string, indices: string[]) {

View File

@ -95,15 +95,18 @@ const mapifyChildren = (children) => {
}; };
const addNodes = (json, state) => { const addNodes = (json, state) => {
console.log(json);
const _addNode = (graph, index, node) => { const _addNode = (graph, index, node) => {
// set child of graph // set child of graph
if (index.length === 1) { if (index.length === 1) {
console.log(node.post);
graph.set(index[0], node); graph.set(index[0], node);
return graph; return graph;
} }
// set parent of graph // set parent of graph
let parNode = graph.get(index[0]); let parNode = graph.get(index[0]);
console.log(parNode.post);
if (!parNode) { if (!parNode) {
console.error('parent node does not exist, cannot add child'); console.error('parent node does not exist, cannot add child');
return; return;
@ -138,7 +141,6 @@ const addNodes = (json, state) => {
if (index.length === 0) { return; } if (index.length === 0) { return; }
node.children = mapifyChildren(node?.children || {}); node.children = mapifyChildren(node?.children || {});
state.graphs[resource] = _addNode( state.graphs[resource] = _addNode(
state.graphs[resource], state.graphs[resource],

View File

@ -96,6 +96,7 @@ export default class GlobalStore extends BaseStore<StoreState> {
notificationsCount: 0, notificationsCount: 0,
settings: {}, settings: {},
pendingJoin: {}, pendingJoin: {},
pendingIndices: {}
}; };
} }

View File

@ -78,7 +78,7 @@ class ChatInput extends Component<ChatInputProps, ChatInputState> {
props.deleteMessage(); props.deleteMessage();
props.api.graph.addPost(ship,name, post); props.api.graph.addPost(ship, name, post);
} }
uploadSuccess(url) { uploadSuccess(url) {