graph-js: create lib/post and refactor

This commit is contained in:
Liam Fitzgerald 2020-10-05 15:32:17 +10:00
parent fdbf225c66
commit fc2868abe7
3 changed files with 20 additions and 18 deletions

View File

@ -0,0 +1,18 @@
import { Post, GraphNode } from "~/types";
export const buntPost = (): Post => ({
author: '',
contents: [],
hash: null,
index: '',
signatures: [],
'time-sent': 0
});
export function makeNodeMap(posts: Post[]): Record<string, GraphNode> {
let nodes = {};
posts.forEach((p) => {
nodes[p.index] = { children: { empty: null }, post: p };
});
return nodes;
}

View File

@ -1,21 +1,5 @@
import { Post, GraphNode, TextContent, Graph, NodeMap } from "~/types";
const buntPost = (): Post => ({
author: '',
contents: [],
hash: null,
index: '',
signatures: [],
'time-sent': 0
});
export function makeNodeMap(posts: Post[]): Record<string, GraphNode> {
let nodes = {};
posts.forEach((p) => {
nodes[p.index] = { children: { empty: null }, post: p };
});
return nodes;
}
import { buntPost } from '~/logic/lib/post';
export function newPost(
title: string,

View File

@ -10,7 +10,7 @@ export type Content = TextContent | UrlContent | CodeContent | ReferenceContent
export interface Post {
author: Patp;
contents: Content[];
hash?: string;
hash: string | null;
index: string;
pending?: boolean;
signatures: string[];