From 0ca385deaf00d905081c66d0e0164558531e0e70 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 3 Apr 2020 13:46:25 -0400 Subject: [PATCH] Adding a text body preview and icon for posts with a body. Fixes #617 --- ui/src/components/post-listing.tsx | 20 ++++++++++++++++++++ ui/src/components/symbols.tsx | 3 +++ ui/src/utils.ts | 8 ++++++++ 3 files changed, 31 insertions(+) diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index ff863dcb..101d1807 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -20,6 +20,7 @@ import { MomentTime } from './moment-time'; import { PostForm } from './post-form'; import { IFramelyCard } from './iframely-card'; import { + md, mdToHtml, canMod, isMod, @@ -30,6 +31,7 @@ import { showAvatars, pictshareImage, setupTippy, + previewLines, } from '../utils'; import { i18n } from '../i18next'; @@ -459,6 +461,24 @@ export class PostListing extends Component { + {post.body && ( + <> +
  • •
  • +
  • + {/* Using a link with tippy doesn't work on touch devices unfortunately */} + + + + + +
  • + + )}
  • •
  • {this.state.upvotes !== this.state.score && ( <> diff --git a/ui/src/components/symbols.tsx b/ui/src/components/symbols.tsx index 16deec3e..dae734a8 100644 --- a/ui/src/components/symbols.tsx +++ b/ui/src/components/symbols.tsx @@ -15,6 +15,9 @@ export class Symbols extends Component { xmlnsXlink="http://www.w3.org/1999/xlink" > + + + diff --git a/ui/src/utils.ts b/ui/src/utils.ts index 8ecef19b..d659509c 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -823,3 +823,11 @@ function hsl(num: number) { function randomHsl() { return `hsla(${Math.random() * 360}, 100%, 50%, 1)`; } + +export function previewLines(text: string, lines: number = 3): string { + // Use lines * 2 because markdown requires 2 lines + return text + .split('\n') + .slice(0, lines * 2) + .join('\n'); +} -- 2.44.1