mirror of
https://github.com/urbit/shrub.git
synced 2024-12-30 07:35:19 +03:00
graph-view: use all of the proper types, get the API call working to send up the proper hashes
This commit is contained in:
parent
7c18df399c
commit
a9232d0df7
@ -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 ""
|
||||
|
@ -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) {
|
||||
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
|
||||
// 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[]) {
|
||||
|
@ -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;
|
||||
@ -139,7 +142,6 @@ const addNodes = (json, state) => {
|
||||
|
||||
node.children = mapifyChildren(node?.children || {});
|
||||
|
||||
|
||||
state.graphs[resource] = _addNode(
|
||||
state.graphs[resource],
|
||||
index,
|
||||
|
@ -96,6 +96,7 @@ export default class GlobalStore extends BaseStore<StoreState> {
|
||||
notificationsCount: 0,
|
||||
settings: {},
|
||||
pendingJoin: {},
|
||||
pendingIndices: {}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ class ChatInput extends Component<ChatInputProps, ChatInputState> {
|
||||
|
||||
props.deleteMessage();
|
||||
|
||||
props.api.graph.addPost(ship,name, post);
|
||||
props.api.graph.addPost(ship, name, post);
|
||||
}
|
||||
|
||||
uploadSuccess(url) {
|
||||
|
Loading…
Reference in New Issue
Block a user