diff --git a/lib/dialogues/full_post_view.dart b/lib/dialogues/full_post_view.dart index e7d4ee6..1317932 100644 --- a/lib/dialogues/full_post_view.dart +++ b/lib/dialogues/full_post_view.dart @@ -17,66 +17,15 @@ class FullPostView extends StatefulWidget { } class _FullPostViewState extends State { - bool loading = false; - @override - Widget build(BuildContext context) { - return SimpleDialog( - contentPadding: const EdgeInsets.all(24), - children: [ - Container( - constraints: global.getConstraints(context), - width: global.getWidth(context), - child: SingleChildScrollView( - child: SingleFullPostDisplay( - level: 0, - model: widget.originPostModel.reblog ?? widget.originPostModel, - ), - ), - ) - ], - ); - } -} - -class SingleFullPostDisplay extends StatefulWidget { - const SingleFullPostDisplay({ - super.key, - required this.level, - required this.model, - this.toBeDistributed, - }); - final int level; - final PostModel model; - final List? toBeDistributed; - - @override - State createState() => _SingleFullPostDisplayState(); -} - -class _SingleFullPostDisplayState extends State { - bool loading = true; List ancestors = []; List descendants = []; - @override - void initState() { - if (widget.level == 0) { - loadPosts(); - } else { - setState(() { - loading = false; - }); - } - super.initState(); - } - + bool loading = true; void loadPosts() async { - final r = await getContextForPost(widget.model); + final r = await getContextForPost(widget.originPostModel); if (r.value != null) { setState(() { - if (widget.level == 0) { - ancestors = r.value!.ancestors; - } + ancestors = r.value!.ancestors; descendants = r.value!.descendants; }); } @@ -87,9 +36,49 @@ class _SingleFullPostDisplayState extends State { } } + @override + void initState() { + loadPosts(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return SimpleDialog( + contentPadding: const EdgeInsets.all(24), + children: [ + Container( + constraints: global.getConstraints(context), + width: global.getWidth(context), + child: SingleChildScrollView( + child: SingleFullPostDisplay( + ancestors: ancestors, + descendants: descendants, + level: 0, + model: widget.originPostModel.reblog ?? widget.originPostModel, + ), + ), + ) + ], + ); + } +} + +class SingleFullPostDisplay extends StatelessWidget { + const SingleFullPostDisplay({ + super.key, + required this.level, + required this.model, + required this.ancestors, + required this.descendants, + }); + final int level; + final PostModel model; + final List ancestors; + final List descendants; + @override Widget build(BuildContext context) { - List toBeDistributed = widget.toBeDistributed ?? []; List ancestorWidgets = ancestors .map( (e) => Post(model: e), @@ -98,37 +87,33 @@ class _SingleFullPostDisplayState extends State { List descendantsWidgets = []; - if (widget.toBeDistributed == null) { - for (var element in descendants) { - toBeDistributed.add(element); - if (element.id == widget.model.id) {} - } - } - - for (var element in toBeDistributed) { - if (element.inReplyTo == widget.model.id) { + // seems most efficient + // considering that lists aren't v long + for (var element in descendants) { + if (element.inReplyTo == model.id) { descendantsWidgets.add(SingleFullPostDisplay( - level: widget.level + 1, + level: level + 1, model: element, - toBeDistributed: toBeDistributed, + ancestors: const [], + descendants: descendants, )); } } List c = []; c.addAll(ancestorWidgets); - c.add(Post(model: widget.model)); + c.add(Post(model: model)); c.addAll(descendantsWidgets); return Container( - padding: EdgeInsets.fromLTRB(widget.level == 0 ? 0 : 4, 0, 0, 0), + padding: EdgeInsets.fromLTRB(level == 0 ? 0 : 4, 0, 0, 0), decoration: BoxDecoration( - border: widget.level == 0 + border: level == 0 ? const Border() : Border( left: BorderSide( width: 4, - color: widget.level.isEven + color: level.isEven ? Theme.of(context).colorScheme.secondary : Theme.of(context).colorScheme.primary, ),