Skip to content

Commit 5b449a4

Browse files
committed
Improve UI of a post
1 parent d08baa5 commit 5b449a4

6 files changed

Lines changed: 47 additions & 42 deletions

File tree

apps/polycentric/src/common/components/primitives/Text.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ const VARIANT_CONFIG: Record<
7777
title: { size: 'xl', defaultWeight: 'bold' },
7878
subtitle: { size: 'lg', defaultWeight: 'semibold' },
7979
body: { size: 'md', defaultWeight: 'regular' },
80-
secondary: { size: 'sm', defaultWeight: 'regular' },
80+
secondary: { size: 'md', defaultWeight: 'regular' },
8181
small: { size: 'xs', defaultWeight: 'semibold' },
8282
} as const;

apps/polycentric/src/common/lib/polycentric-hooks/helpers.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,15 @@ export function timeAgo(unixMs: number): string {
126126
if (mins < 60) return `${mins}m`;
127127
const hours = Math.floor(mins / 60);
128128
if (hours < 24) return `${hours}h`;
129-
return `${Math.floor(hours / 24)}d`;
129+
const days = Math.floor(hours / 24);
130+
if (days < 7) return `${days}d`;
131+
const date = new Date(unixMs);
132+
const sameYear = date.getFullYear() === new Date().getFullYear();
133+
return date.toLocaleDateString(undefined, {
134+
month: 'short',
135+
day: 'numeric',
136+
year: sameYear ? undefined : 'numeric',
137+
});
130138
}
131139

132140
export function bytesToHex(bytes: Uint8Array): string {

apps/polycentric/src/common/theme/tokens.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { StyleSheet, TextStyle } from 'react-native';
22

33
export const Spacing = {
44
'0': 0,
5+
'2xs': 2,
56
xs: 4,
67
sm: 8,
78
md: 12,
@@ -31,7 +32,7 @@ export const typography = {
3132
fontSize: {
3233
xs: 12,
3334
sm: 14,
34-
md: 17,
35+
md: 15,
3536
lg: 20,
3637
xl: 24,
3738
} as const,
@@ -43,7 +44,7 @@ export const typography = {
4344
lineHeight: {
4445
xs: 16,
4546
sm: 20,
46-
md: 24,
47+
md: 20,
4748
lg: 28,
4849
xl: 32,
4950
} as const,
@@ -250,6 +251,9 @@ export const Atoms = StyleSheet.create({
250251
gap_0: {
251252
gap: Spacing['0'],
252253
},
254+
gap_2xs: {
255+
gap: Spacing['2xs'],
256+
},
253257
gap_xs: {
254258
gap: Spacing.xs,
255259
},

apps/polycentric/src/features/post/ConversationView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function ConversationView({ post }: ConversationViewProps) {
4040
<View style={[Atoms.w_full]}>
4141
<Post
4242
post={item}
43-
hideReplyingTo={false}
43+
hideReplyingTo={true}
4444
disablePress={item.id === post.id}
4545
showThreadLineAbove={lineAbove}
4646
showThreadLineBelow={lineBelow}

apps/polycentric/src/features/post/Post.tsx

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const Post = memo(function Post({
136136
disabled={disablePress}
137137
>
138138
{/* Top padding bar */}
139-
<View style={[Atoms.flex_row, Atoms.gap_lg]}>
139+
<View style={[Atoms.flex_row, Atoms.gap_md]}>
140140
<View
141141
style={[
142142
Atoms.align_center,
@@ -167,7 +167,7 @@ export const Post = memo(function Post({
167167
</View>
168168

169169
{/* Main post body */}
170-
<View style={[Atoms.flex_row, Atoms.gap_lg]}>
170+
<View style={[Atoms.flex_row, Atoms.gap_md]}>
171171
{/* Left side (avatar and thread line) */}
172172
<View style={[Atoms.align_center]}>
173173
{authorIdentity ? (
@@ -195,52 +195,48 @@ export const Post = memo(function Post({
195195
</View>
196196

197197
{/* Main post content */}
198-
<View style={[Atoms.flex_1, Atoms.pb_md]}>
198+
<View style={[Atoms.flex_1, Atoms.pb_md, Atoms.gap_2xs]}>
199199
{/* Author name and other topbar items */}
200-
<View
201-
style={[
202-
Atoms.flex_row,
203-
Atoms.justify_between,
204-
{ alignItems: 'baseline', marginTop: -1 },
205-
]}
206-
>
200+
<View style={[Atoms.flex_row, Atoms.align_center]}>
207201
<View
208202
style={[
209203
Atoms.flex_1,
210204
Atoms.flex_row,
211205
Atoms.gap_xs,
212-
{ alignItems: 'baseline' },
206+
Atoms.align_center,
213207
]}
214208
>
215209
<PostAuthorName
216210
name={authorName || '...'}
217211
onPress={handleAuthorPress}
218212
/>
219213
{authorIdentity ? (
220-
<IdentityTag
221-
identity={authorIdentity}
222-
style={{ transform: [{ translateY: 1 }] }}
223-
/>
214+
<IdentityTag identity={authorIdentity} />
224215
) : null}
225-
</View>
226216

227-
{time ? (
228-
<Text
229-
variant="small"
230-
color="neutral_500"
231-
style={{ lineHeight: 18, marginLeft: 8 }}
232-
>
233-
{time}
234-
</Text>
235-
) : null}
217+
{time ? (
218+
<>
219+
<Text
220+
variant="secondary"
221+
color="neutral_500"
222+
fontWeight="bold"
223+
>
224+
·
225+
</Text>
226+
<Text variant="secondary" color="neutral_500">
227+
{time}
228+
</Text>
229+
</>
230+
) : null}
231+
</View>
236232
</View>
237233

238234
{!hideReplyingTo && post.reply?.parentId ? (
239235
<ReplyingToSubheader parentId={post.reply.parentId} />
240236
) : null}
241237

242238
{displayContent ? (
243-
<Text variant="secondary" style={[Atoms.mt_xs]}>
239+
<Text variant="secondary">
244240
{displayContent}
245241
{isTruncatedPreview ? '...' : ''}
246242
</Text>
@@ -251,7 +247,7 @@ export const Post = memo(function Post({
251247
onPress={toggleContentExpanded}
252248
onHoverIn={onExpandHoverIn}
253249
onHoverOut={onExpandHoverOut}
254-
style={{ marginTop: 2, alignSelf: 'flex-start' }}
250+
style={[Atoms.self_start]}
255251
>
256252
<Text
257253
variant="small"
@@ -272,7 +268,7 @@ export const Post = memo(function Post({
272268
onDislike={handleDislike}
273269
liked={liked}
274270
disliked={disliked}
275-
style={{ marginTop: 8 }}
271+
style={[Atoms.mt_sm]}
276272
/>
277273
</View>
278274
</View>
@@ -302,12 +298,12 @@ function ReplyingToSubheader({ parentId }: { parentId: string }) {
302298
return (
303299
<Pressable
304300
onPress={handlePress}
305-
style={[Atoms.flex_row, Atoms.mt_xs, { alignItems: 'baseline' }]}
301+
style={[Atoms.flex_row, Atoms.align_center]}
306302
>
307-
<Text variant="small" color="neutral_500" fontWeight="regular">
308-
Reply to{' '}
303+
<Text variant="secondary" color="neutral_500" fontWeight="regular">
304+
Replying to{' '}
309305
</Text>
310-
<Text variant="small" color="primary_500">
306+
<Text variant="secondary" color="primary_500">
311307
{truncateName(parentName || '…', 24)}
312308
</Text>
313309
</Pressable>
@@ -328,10 +324,7 @@ function PostAuthorName({
328324
<Text
329325
variant="secondary"
330326
fontWeight="bold"
331-
style={[
332-
{ lineHeight: 18 },
333-
hovered && { textDecorationLine: 'underline' },
334-
]}
327+
style={[hovered && { textDecorationLine: 'underline' }]}
335328
>
336329
{truncateName(name, 16)}
337330
</Text>

packages/js-node/examples/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
7-
"dev": "tsx src/index.ts"
7+
"examples": "tsx src/index.ts"
88
},
99
"dependencies": {
1010
"@polycentric/js-node": "workspace:*",

0 commit comments

Comments
 (0)