From 113b99f475e35a2378f289067536f33ac87ef49b Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Tue, 30 Mar 2021 21:29:37 -0500 Subject: [PATCH] group-feed: tons of post item touch-ups --- .../src/logic/subscription/global.ts | 2 +- pkg/interface/src/views/components/Author.tsx | 53 +++++++--------- .../src/views/components/Timestamp.tsx | 38 +++++++++--- .../components/Home/Post/PostFeed.js | 10 +++- .../Home/Post/PostItem/PostContent.js | 2 + .../Home/Post/PostItem/PostFooter.js | 60 +++++++++++++++---- .../Home/Post/PostItem/PostHeader.js | 19 ++++-- .../components/Home/Post/PostItem/PostItem.js | 8 ++- pkg/interface/src/views/landscape/index.tsx | 23 +++++++ 9 files changed, 154 insertions(+), 61 deletions(-) diff --git a/pkg/interface/src/logic/subscription/global.ts b/pkg/interface/src/logic/subscription/global.ts index bbf1c41f6..a773549cf 100644 --- a/pkg/interface/src/logic/subscription/global.ts +++ b/pkg/interface/src/logic/subscription/global.ts @@ -52,7 +52,7 @@ export default class GlobalSubscription extends BaseSubscription { for (let key in Object.keys(this.openSubscriptions)) { let val = this.openSubscriptions[key]; - unsubscribe(val.id); + this.unsubscribe(val.id); } this.start(); diff --git a/pkg/interface/src/views/components/Author.tsx b/pkg/interface/src/views/components/Author.tsx index b3264d195..ff235e25e 100644 --- a/pkg/interface/src/views/components/Author.tsx +++ b/pkg/interface/src/views/components/Author.tsx @@ -36,10 +36,11 @@ export default function Author(props: AuthorProps & PropFunc): React children, unread, group, + isRelativeTime, + dontShowTime, ...rest } = props; - const showAsCol = props.showAsCol || false; const time = props.time || false; const size = props.size || 16; const sigilPadding = props.sigilPadding || 2; @@ -73,36 +74,6 @@ export default function Author(props: AuthorProps & PropFunc): React ); - const rowOrCol = showAsCol ? ( - - - {name} - - - - ) : ( - <> - - {name} - - - - ); - const img = contact?.avatar && !hideAvatars ? ( ): React )} - {rowOrCol} + + {name} + + { !dontShowTime && ( + + )} {children} ); diff --git a/pkg/interface/src/views/components/Timestamp.tsx b/pkg/interface/src/views/components/Timestamp.tsx index a73ce72eb..ec526b885 100644 --- a/pkg/interface/src/views/components/Timestamp.tsx +++ b/pkg/interface/src/views/components/Timestamp.tsx @@ -11,10 +11,20 @@ export type TimestampProps = BoxProps & { stamp: MomentType; date?: boolean; time?: boolean; + relative?: boolean; }; const Timestamp = (props: TimestampProps): ReactElement | null => { - const { stamp, date, time, color, fontSize, ...rest } = { + const { + stamp, + date, + time, + color, + relative, + dateNotRelative, + fontSize, + ...rest + } = { time: true, color: 'gray', fontSize: 0, @@ -24,14 +34,24 @@ const Timestamp = (props: TimestampProps): ReactElement | null => { const { hovering, bind } = date === true ? { hovering: true, bind: {} } : useHovering(); let datestamp = stamp.format(DateFormat); - if (stamp.format(DateFormat) === moment().format(DateFormat)) { - datestamp = 'Today'; - } else if ( - stamp.format(DateFormat) === moment().subtract(1, 'day').format(DateFormat) - ) { - datestamp = 'Yesterday'; + if (!dateNotRelative) { + if (stamp.format(DateFormat) === moment().format(DateFormat)) { + datestamp = 'Today'; + } else if ( + stamp.format(DateFormat) === moment().subtract(1, 'day').format(DateFormat) + ) { + datestamp = 'Yesterday'; + } + } else { + datestamp = `~${datestamp}`; + } + + let timestamp; + if (relative) { + timestamp = stamp.fromNow(); + } else { + timestamp = stamp.format(TimeFormat); } - const timestamp = stamp.format(TimeFormat); return ( { {timestamp} )} - {date !== false && ( + {date !== false && relative !== true && ( ); @@ -89,6 +91,7 @@ export class PostFeed extends React.Component { history={history} parentPost={parentNode?.post} isReply={!!parentNode} + isRelativeTime={true} /> ); }); @@ -131,7 +134,12 @@ export class PostFeed extends React.Component { } render() { - const { graph, pendingSize, parentNode, history } = this.props; + const { + graph, + pendingSize, + parentNode, + history + } = this.props; return ( diff --git a/pkg/interface/src/views/landscape/components/Home/Post/PostItem/PostContent.js b/pkg/interface/src/views/landscape/components/Home/Post/PostItem/PostContent.js index 6644029a3..97552367c 100644 --- a/pkg/interface/src/views/landscape/components/Home/Post/PostItem/PostContent.js +++ b/pkg/interface/src/views/landscape/components/Home/Post/PostItem/PostContent.js @@ -11,6 +11,8 @@ export function PostContent(props) { return ( - { - e.stopPropagation(); - toggleReplyMode(); - }}> - - { replyCount > 0 ? ( - {replyCount} - ) : null } - + + + { showTimestamp && ( + + { showTimestamp ? ( + {replyCount}{replyText} + ) : null } + + + )} + { + e.stopPropagation(); + toggleReplyMode(); + }}> + + { replyCount > 0 && !showTimestamp ? ( + {replyCount} + ) : null } + + ); } diff --git a/pkg/interface/src/views/landscape/components/Home/Post/PostItem/PostHeader.js b/pkg/interface/src/views/landscape/components/Home/Post/PostItem/PostHeader.js index 8a5db9fa5..fdf80d171 100644 --- a/pkg/interface/src/views/landscape/components/Home/Post/PostItem/PostHeader.js +++ b/pkg/interface/src/views/landscape/components/Home/Post/PostItem/PostHeader.js @@ -8,7 +8,13 @@ import useContactState from '~/logic/state/contact'; export function PostHeader(props) { - const { post, api, association, isReply } = props; + const { + post, + api, + association, + isReply, + showTimestamp + } = props; const contacts = useContactState(state => state.contacts); const mb = isReply ? "2" : "3"; @@ -22,8 +28,9 @@ export function PostHeader(props) { return ( { e.stopPropagation(); }}> { isReply ? ( - + Replying to @@ -100,7 +102,9 @@ class PostItem extends React.Component { isParent={isParent} api={api} /> { inReplyMode ? ( diff --git a/pkg/interface/src/views/landscape/index.tsx b/pkg/interface/src/views/landscape/index.tsx index f545a13c1..2dfd830f2 100644 --- a/pkg/interface/src/views/landscape/index.tsx +++ b/pkg/interface/src/views/landscape/index.tsx @@ -20,6 +20,29 @@ import GlobalSubscription from '~/logic/subscription/global'; import useGraphState from '~/logic/state/graph'; import useHarkState, { withHarkState } from '~/logic/state/hark'; import withState from '~/logic/lib/withState'; +import moment from 'moment'; + + +moment.updateLocale('en', { + relativeTime : { + future: "%s", + past: "%s", + s : "1s", + ss : "%ds", + m: "1m", + mm: "%dm", + h: "1h", + hh: "%dh", + d: "1d", + dd: "%dd", + w: "1w", + ww: "%dw", + M: "1mo", + MM: "%dmo", + y: "1y", + yy: "%dy" + } +}); type LandscapeProps = StoreState & {