mirror of
https://github.com/urbit/shrub.git
synced 2024-11-28 05:22:27 +03:00
publish interface: back up to old parity
This commit is contained in:
parent
125dd0d910
commit
5fb9d1f0fe
@ -6,6 +6,42 @@ import {makeResource, resourceFromPath} from '../lib/group';
|
||||
import {GroupPolicy, Enc, Post, NodeMap, Content} from '~/types';
|
||||
import { numToUd, unixToDa } from '~/logic/lib/util';
|
||||
|
||||
export const createBlankNodeWithChildPost = (
|
||||
parentIndex: string = '',
|
||||
childIndex: string = '',
|
||||
contents: Content[]
|
||||
) => {
|
||||
const date = unixToDa(Date.now()).toString();
|
||||
const nodeIndex = parentIndex + '/' + date;
|
||||
|
||||
const childGraph = {};
|
||||
childGraph[childIndex] = {
|
||||
post: {
|
||||
author: `~${window.ship}`,
|
||||
index: nodeIndex + '/' + childIndex,
|
||||
'time-sent': Date.now(),
|
||||
contents,
|
||||
hash: null,
|
||||
signatures: []
|
||||
},
|
||||
children: { empty: null }
|
||||
};
|
||||
|
||||
return {
|
||||
post: {
|
||||
author: `~${window.ship}`,
|
||||
index: nodeIndex,
|
||||
'time-sent': Date.now(),
|
||||
contents: [],
|
||||
hash: null,
|
||||
signatures: []
|
||||
},
|
||||
children: {
|
||||
graph: childGraph
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const createPost = (contents: Content[], parentIndex: string = '') => {
|
||||
return {
|
||||
author: `~${window.ship}`,
|
||||
@ -38,6 +74,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
private hookAction(ship: Patp, action: any): Promise<any> {
|
||||
console.log(action);
|
||||
return this.action('graph-push-hook', 'graph-update', action);
|
||||
}
|
||||
|
||||
@ -150,6 +187,19 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
});
|
||||
}
|
||||
|
||||
addNode(ship: Patp, name: string, node: Object) {
|
||||
let nodes = {};
|
||||
const resource = { ship, name };
|
||||
nodes[node.post.index] = node;
|
||||
|
||||
return this.hookAction(ship, {
|
||||
'add-nodes': {
|
||||
resource,
|
||||
nodes
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addNodes(ship: Patp, name: string, nodes: Object) {
|
||||
return this.hookAction(ship, {
|
||||
'add-nodes': {
|
||||
|
@ -84,12 +84,25 @@ export function getLatestRevision(node: GraphNode): [number, string, string, Pos
|
||||
}
|
||||
const [revNum, rev] = [...revs.children][0];
|
||||
if(!rev) {
|
||||
return empty
|
||||
return empty;
|
||||
}
|
||||
const [title, body] = rev.post.contents as TextContent[];
|
||||
return [revNum.toJSNumber(), title.text, body.text, rev.post];
|
||||
}
|
||||
|
||||
export function getLatestCommentRevision(node: GraphNode): [number, Post] {
|
||||
const empty = [1, buntPost()] as [number, Post];
|
||||
if (node.children.size <= 0) {
|
||||
return empty;
|
||||
}
|
||||
const [revNum, rev] = [...node.children][0];
|
||||
if(!rev) {
|
||||
return empty;
|
||||
}
|
||||
return [revNum.toJSNumber(), rev.post];
|
||||
}
|
||||
|
||||
|
||||
export function getComments(node: GraphNode): GraphNode {
|
||||
const comments = node.children.get(bigInt(2));
|
||||
if(!comments) {
|
||||
|
@ -8,6 +8,7 @@ import { GraphNode, TextContent } from '~/types/graph-update';
|
||||
import tokenizeMessage from '~/logic/lib/tokenizeMessage';
|
||||
import { LocalUpdateRemoteContentPolicy } from '~/types';
|
||||
import { MentionText } from '~/views/components/MentionText';
|
||||
import { getLatestCommentRevision } from '~/logic/lib/publish';
|
||||
|
||||
const ClickBox = styled(Box)`
|
||||
cursor: pointer;
|
||||
@ -27,24 +28,22 @@ interface CommentItemProps {
|
||||
}
|
||||
|
||||
export function CommentItem(props: CommentItemProps) {
|
||||
const { ship, contacts, name, api, remoteContentPolicy } = props;
|
||||
const commentData = props.comment?.post;
|
||||
const comment = commentData.contents;
|
||||
|
||||
const disabled = props.pending || window.ship !== commentData.author;
|
||||
const { ship, contacts, name, api, remoteContentPolicy, comment } = props;
|
||||
const [revNum, post] = getLatestCommentRevision(comment);
|
||||
const disabled = props.pending || window.ship !== post?.author;
|
||||
|
||||
const onDelete = async () => {
|
||||
await api.graph.removeNodes(ship, name, [commentData?.index]);
|
||||
await api.graph.removeNodes(ship, name, [comment.post?.index]);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box mb={4} opacity={commentData?.pending ? '60%' : '100%'}>
|
||||
<Box mb={4} opacity={post?.pending ? '60%' : '100%'}>
|
||||
<Row bg="white" my={3}>
|
||||
<Author
|
||||
showImage
|
||||
contacts={contacts}
|
||||
ship={commentData?.author}
|
||||
date={commentData?.['time-sent']}
|
||||
ship={post?.author}
|
||||
date={post?.['time-sent']}
|
||||
hideAvatars={props.hideAvatars}
|
||||
hideNicknames={props.hideNicknames}
|
||||
>
|
||||
@ -60,7 +59,7 @@ export function CommentItem(props: CommentItemProps) {
|
||||
<Box mb={2}>
|
||||
<MentionText
|
||||
contacts={contacts}
|
||||
content={comment}
|
||||
content={post?.contents}
|
||||
remoteContentPolicy={remoteContentPolicy}
|
||||
/>
|
||||
</Box>
|
||||
|
@ -6,7 +6,7 @@ import { Contacts } from '~/types/contact-update';
|
||||
import GlobalApi from '~/logic/api/global';
|
||||
import { FormikHelpers } from 'formik';
|
||||
import { GraphNode } from '~/types/graph-update';
|
||||
import { createPost } from '~/logic/api/graph';
|
||||
import { createPost, createBlankNodeWithChildPost } from '~/logic/api/graph';
|
||||
import { LocalUpdateRemoteContentPolicy } from '~/types';
|
||||
import { scanForMentions } from '~/logic/lib/graph';
|
||||
|
||||
@ -30,8 +30,12 @@ export function Comments(props: CommentsProps) {
|
||||
) => {
|
||||
try {
|
||||
const content = scanForMentions(comment);
|
||||
const post = createPost(content, comments?.post?.index);
|
||||
await api.graph.addPost(ship, name, post);
|
||||
const node = createBlankNodeWithChildPost(
|
||||
comments?.post?.index,
|
||||
'1',
|
||||
content
|
||||
);
|
||||
await api.graph.addNode(ship, name, node);
|
||||
actions.resetForm();
|
||||
actions.setStatus({ success: null });
|
||||
} catch (e) {
|
||||
|
Loading…
Reference in New Issue
Block a user