From a21a0d29884dfa5a21f15a8a3684c48ecdf90b40 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Wed, 28 Sep 2022 15:03:16 -0500 Subject: Improve thread rendering (show reply lines) --- src/state/models/post-thread-view.ts | 21 +++++++--- src/state/models/session.ts | 1 - src/view/com/post-thread/PostThreadItem.tsx | 59 +++++++++++++++++++++++++++++ src/view/index.ts | 2 + 4 files changed, 77 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/state/models/post-thread-view.ts b/src/state/models/post-thread-view.ts index fab0eb895..923562c5a 100644 --- a/src/state/models/post-thread-view.ts +++ b/src/state/models/post-thread-view.ts @@ -43,6 +43,9 @@ export class PostThreadViewPostModel implements GetPostThread.Post { indexedAt: string = '' myState = new PostThreadViewPostMyStateModel() + // added data + replyingToAuthor?: string + constructor( public rootStore: RootStoreModel, reactKey: string, @@ -58,9 +61,14 @@ export class PostThreadViewPostModel implements GetPostThread.Post { } } - assignTreeModels(keyGen: Generator, v: GetPostThread.Post) { + assignTreeModels( + keyGen: Generator, + v: GetPostThread.Post, + includeParent = true, + includeChildren = true, + ) { // parents - if (v.parent) { + if (includeParent && v.parent) { // TODO: validate .record const parentModel = new PostThreadViewPostModel( this.rootStore, @@ -69,12 +77,15 @@ export class PostThreadViewPostModel implements GetPostThread.Post { ) parentModel._depth = this._depth - 1 if (v.parent.parent) { - parentModel.assignTreeModels(keyGen, v.parent) + parentModel.assignTreeModels(keyGen, v.parent, true, false) } this.parent = parentModel } + if (v.parent?.author.name) { + this.replyingToAuthor = v.parent.author.name + } // replies - if (v.replies) { + if (includeChildren && v.replies) { const replies = [] for (const item of v.replies) { // TODO: validate .record @@ -85,7 +96,7 @@ export class PostThreadViewPostModel implements GetPostThread.Post { ) itemModel._depth = this._depth + 1 if (item.replies) { - itemModel.assignTreeModels(keyGen, item) + itemModel.assignTreeModels(keyGen, item, false, true) } replies.push(itemModel) } diff --git a/src/state/models/session.ts b/src/state/models/session.ts index 494aed5d4..ec3a7fc03 100644 --- a/src/state/models/session.ts +++ b/src/state/models/session.ts @@ -88,7 +88,6 @@ export class SessionModel { } clear() { - console.log('clear()') this.data = null } diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx index 8a2034cc6..daba54b5a 100644 --- a/src/view/com/post-thread/PostThreadItem.tsx +++ b/src/view/com/post-thread/PostThreadItem.tsx @@ -1,6 +1,7 @@ import React, {useMemo} from 'react' import {observer} from 'mobx-react-lite' import {Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native' +import Svg, {Line, Circle} from 'react-native-svg' import {AdxUri} from '../../../third-party/uri' import * as PostType from '../../../third-party/api/src/types/todo/social/post' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' @@ -13,6 +14,8 @@ import {ago, pluralize} from '../../lib/strings' import {DEF_AVATER} from '../../lib/assets' import {useStores} from '../../../state' +const PARENT_REPLY_LINE_LENGTH = 8 + export const PostThreadItem = observer(function PostThreadItem({ item, onPressShare, @@ -185,11 +188,56 @@ export const PostThreadItem = observer(function PostThreadItem({ } else { return ( + {!!item.replyingToAuthor && ( + + + + + + )} + {item.replies?.length !== 0 && ( + + + + + + )} + {item.replyingToAuthor && + item.replyingToAuthor !== item.author.name && ( + + + + + @{item.replyingToAuthor} + + + + )}