From dd4232bf18ee6804b71693533b52c65e202f6050 Mon Sep 17 00:00:00 2001 From: LeoLox <58687994+leo-lox@users.noreply.github.com> Date: Mon, 4 Nov 2024 10:54:47 +0100 Subject: [PATCH] comments component --- .../components/comments_section.dart | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 lib/presentation_layer/components/comments_section.dart diff --git a/lib/presentation_layer/components/comments_section.dart b/lib/presentation_layer/components/comments_section.dart new file mode 100644 index 00000000..5ec8343e --- /dev/null +++ b/lib/presentation_layer/components/comments_section.dart @@ -0,0 +1,75 @@ +import 'package:camelus/domain_layer/entities/user_metadata.dart'; +import 'package:flutter/material.dart'; + +import '../../domain_layer/entities/nostr_note.dart'; +import '../../domain_layer/entities/tree_node.dart'; +import 'note_card/note_card.dart'; + +class CommentSection extends StatelessWidget { + final TreeNode commentTree; + + const CommentSection({super.key, required this.commentTree}); + + @override + Widget build(BuildContext context) { + return SingleChildScrollView( + child: _buildCommentTree(commentTree, 0), + ); + } + + Widget _buildCommentTree(TreeNode node, int depth) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: EdgeInsets.only(left: depth * 16.0), + child: NoteCard( + note: node.value, + myMetadata: UserMetadata( + eventId: "eventId", pubkey: "pubkey", lastFetch: 0), + ), + ), + ...node.children.map((child) => _buildCommentTree(child, depth + 1)), + ], + ); + } +} + +/// use this as a widget +class CommentTreeBuilder extends StatefulWidget { + final TreeNode initialCommentTree; + + const CommentTreeBuilder({Key? key, required this.initialCommentTree}) + : super(key: key); + + @override + _CommentTreeBuilderState createState() => _CommentTreeBuilderState(); +} + +class _CommentTreeBuilderState extends State { + late TreeNode commentTree; + + @override + void initState() { + super.initState(); + commentTree = widget.initialCommentTree; + } + + void _addReply(TreeNode parentNode, NostrNote reply) { + setState(() { + parentNode.addChild(TreeNode(reply)); + }); + } + + @override + Widget build(BuildContext context) { + return CommentSection( + commentTree: commentTree, + // onReply: (TreeNode parentNode) { + // // Show a dialog or navigate to a new screen to get the reply content + // // For simplicity, we'll just add a dummy reply here + // _addReply(parentNode, NostrNote(content: "This is a reply")); + // }, + ); + } +}