diff --git a/examples/gno.land/p/demo/boardsv2/draft1/boards.gno b/examples/gno.land/p/demo/boardsv2/draft1/boards.gno new file mode 100644 index 00000000000..287144a210a --- /dev/null +++ b/examples/gno.land/p/demo/boardsv2/draft1/boards.gno @@ -0,0 +1,26 @@ +package boardsv2 + +// NOTE: Boards type should be a realm type +type Boards struct { + // NOTE: Most of all types could be saved within the same AVL tree, prefixing the level + // NOTE: We provably want different AVL trees (stores) + // NOTE: Again, we could consider using Node instead of Post, and tree instead of posts (semantics) + posts avl.Tree // string(Post.Level + slug) -> *Post (post, comment, poll) +} + +// NOTE: Iterating only Post type is confusing semantically +// NOTE: Potential need cast/switch/type-check when iterating. +func (b Boards) Iterate(slug string, fn func(*Post) bool) bool {} +func (b Boards) IteratePosts(slug string, fn func(*Post) bool) bool {} +func (b Boards) IterateComments(slug string, fn func(*Post) bool) bool {} + +// How to map render paths to actual post instances? +// +// AVL KEYS BY LEVEL PREFIX (start/end) +// Boards => 0_ ... 1_ +// Posts => 1_BOARD/ ... 2_ +// Comments => 2_BOARD/POST/ ... 3_ +// +// HOW TO GUESS PREFIX FROM SLUG +// User enters a SLUG => (one part => 1_BOARD)(more than one part => 1_BOARD/POST) +// How to recognize comments? Should be URL accesible? We could use ":" as separator (not optimal) diff --git a/examples/gno.land/p/demo/boardsv2/draft1/content_board.gno b/examples/gno.land/p/demo/boardsv2/draft1/content_board.gno new file mode 100644 index 00000000000..415d52c46b8 --- /dev/null +++ b/examples/gno.land/p/demo/boardsv2/draft1/content_board.gno @@ -0,0 +1,27 @@ +package boardsv2 + +const ContentTypeBoard = "boards:board" + +var _ Content = (*BoardContent)(nil) + +type BoardContent struct { + Name string +} + +func NewBoard() *Post { + return &Post{ + // ... + Level: LevelBoard, + Content: &BoardContent{ + // ... + }, + } +} + +func (c BoardContent) Type() string { + return ContentTypeBoard +} + +func (c BoardContent) Render() string { + return "" +} diff --git a/examples/gno.land/p/demo/boardsv2/draft1/content_comment.gno b/examples/gno.land/p/demo/boardsv2/draft1/content_comment.gno new file mode 100644 index 00000000000..fcaac13c3e8 --- /dev/null +++ b/examples/gno.land/p/demo/boardsv2/draft1/content_comment.gno @@ -0,0 +1,27 @@ +package boardsv2 + +const ContentTypeComment = "boards:comment" + +var _ Content = (*CommentContent)(nil) + +type CommentContent struct { + Body string +} + +func NewComment() *Post { + return &Post{ + // ... + Level: LevelComment, + Content: &CommentContent{ + // ... + }, + } +} + +func (c CommentContent) Type() string { + return ContentTypeComment +} + +func (c CommentContent) Render() string { + return "" +} diff --git a/examples/gno.land/p/demo/boardsv2/draft1/content_poll.gno b/examples/gno.land/p/demo/boardsv2/draft1/content_poll.gno new file mode 100644 index 00000000000..9bc10e97617 --- /dev/null +++ b/examples/gno.land/p/demo/boardsv2/draft1/content_poll.gno @@ -0,0 +1,32 @@ +package boardsv2 + +const ContentTypePoll = "boards:poll" + +var _ Content = (*PollContent)(nil) + +type PollContent struct { + Question string + Options []string + Votes []struct { + Address std.Adress + Option string + } +} + +func NewPoll() *Post { + return &Post{ + // ... + Level: LevelPost, + Content: &PollContent{ + // ... + }, + } +} + +func (c PollContent) Type() string { + return ContentTypePoll +} + +func (c PollContent) Render() string { + return "" +} diff --git a/examples/gno.land/p/demo/boardsv2/draft1/content_post.gno b/examples/gno.land/p/demo/boardsv2/draft1/content_post.gno new file mode 100644 index 00000000000..289b5ba0099 --- /dev/null +++ b/examples/gno.land/p/demo/boardsv2/draft1/content_post.gno @@ -0,0 +1,29 @@ +package boardsv2 + +const ContentTypePost = "boards:post" + +var _ Content = (*TextContent)(nil) + +type TextContent struct { + Title string + Body string + Tags []string +} + +func NewPost() *Post { + return &Post{ + // ... + Level: LevelPost, + Content: &TextContent{ + // ... + }, + } +} + +func (c TextContent) Type() string { + return ContentTypePost +} + +func (c TextContent) Render() string { + return "" +} diff --git a/examples/gno.land/p/demo/boardsv2/draft1/post.gno b/examples/gno.land/p/demo/boardsv2/draft1/post.gno new file mode 100644 index 00000000000..70e9ed8b71e --- /dev/null +++ b/examples/gno.land/p/demo/boardsv2/draft1/post.gno @@ -0,0 +1,35 @@ +package boardsv2 + +import ( + "strconv" +) + +const ( + LevelBoard = iota + LevelPost + LevelComment +) + +type ( + Content interface { + Type() string + Render() string + } + + // TODO: Still have to consider how to add custom features like up/down voting, reputation, fork, lock, ... + Post struct { + ID string + Content Content // NOTE: Maybe should be Type (board as content is odd) + Level int + Base *Post + Children []*Post + Forks []*Post + UpdatedAt time.Time + CreatedAt time.Time + Creator std.Address + } +) + +func (p Post) NextIncrementalKey(baseKey string) string { + return baseKey + "/" + strconv.Itoa(len(p.Children)) +}