@openpeepshq/react 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/components/markdown/compileMarkdown.js +1 -0
  2. package/dist/components/navigation/FooterMobile.js +4 -3
  3. package/dist/components/navigation/HeaderMobile.js +5 -2
  4. package/dist/components/navigation/MobileMenuItem.d.ts +3 -1
  5. package/dist/components/navigation/MobileMenuItem.js +7 -2
  6. package/dist/components/navigation/NavWithTooltip.d.ts +9 -0
  7. package/dist/components/navigation/NavWithTooltip.js +4 -0
  8. package/dist/components/navigation/index.d.ts +2 -0
  9. package/dist/components/navigation/index.js +1 -0
  10. package/dist/components/navigation/sideBarNavLinkClass.d.ts +6 -4
  11. package/dist/components/navigation/sideBarNavLinkClass.js +6 -2
  12. package/dist/components/post/CompactReplyParent.js +5 -6
  13. package/dist/components/post/TruncatedMarkdown.d.ts +27 -0
  14. package/dist/components/post/TruncatedMarkdown.js +37 -0
  15. package/dist/components/post/helpers.d.ts +2 -2
  16. package/dist/components/post/helpers.js +3 -16
  17. package/dist/components/post/index.d.ts +2 -0
  18. package/dist/components/post/index.js +1 -0
  19. package/dist/components/post/pieces/EventLocation.js +14 -0
  20. package/dist/components/post/pieces/EventRsvpButton.js +3 -1
  21. package/dist/components/post/pieces/PollContent.js +8 -2
  22. package/dist/components/post/post-form/ArticleForm.js +1 -1
  23. package/dist/components/post/post-form/EventForm.js +23 -3
  24. package/dist/components/post/post-form/ResourceForm.d.ts +3 -1
  25. package/dist/components/post/post-form/ResourceForm.js +48 -7
  26. package/dist/components/post/post-form/VisibilitySelector.js +9 -3
  27. package/dist/components/post/types/Article.js +2 -3
  28. package/dist/components/post/types/Event.js +10 -1
  29. package/dist/components/post/types/resource/FullResource.js +3 -3
  30. package/dist/components/preview-link/local/WelcomePreview.js +4 -2
  31. package/dist/components/resources/ResourceCard.d.ts +5 -1
  32. package/dist/components/resources/ResourceCard.js +29 -5
  33. package/dist/components/resources/ResourceCard.test.d.ts +1 -0
  34. package/dist/components/resources/ResourceCard.test.js +75 -0
  35. package/dist/components/resources/ResourceLibrary.js +1 -1
  36. package/dist/hooks/events/useEventRsvp.d.ts +1 -0
  37. package/dist/hooks/events/useEventRsvp.js +15 -7
  38. package/dist/hooks/posts/useResourceComposer.d.ts +2 -0
  39. package/dist/hooks/posts/useResourceComposer.js +131 -25
  40. package/dist/hooks/resources/useResourceLibrary.d.ts +1 -1
  41. package/dist/hooks/resources/useResourceLibrary.js +6 -2
  42. package/dist/hooks/useWelcomePreview.d.ts +3 -0
  43. package/dist/hooks/useWelcomePreview.js +1 -0
  44. package/dist/navigation/menuItems.js +15 -0
  45. package/dist/navigation/targets.d.ts +2 -0
  46. package/dist/pages/admin/community/CommunityMarkdownPage.js +2 -1
  47. package/dist/pages/auth/Register.js +3 -1
  48. package/dist/pages/resources/Edit.js +3 -3
  49. package/dist/pages/resources/New.js +2 -2
  50. package/dist/pages/settings/Account.js +30 -2
  51. package/package.json +2 -2
  52. package/src/components/markdown/compileMarkdown.ts +1 -0
  53. package/src/components/navigation/FooterMobile.tsx +41 -33
  54. package/src/components/navigation/HeaderMobile.tsx +55 -41
  55. package/src/components/navigation/MobileMenuItem.tsx +15 -2
  56. package/src/components/navigation/NavWithTooltip.tsx +26 -0
  57. package/src/components/navigation/index.ts +2 -0
  58. package/src/components/navigation/sideBarNavLinkClass.ts +9 -6
  59. package/src/components/post/CompactReplyParent.tsx +17 -10
  60. package/src/components/post/TruncatedMarkdown.tsx +91 -0
  61. package/src/components/post/helpers.ts +4 -18
  62. package/src/components/post/index.ts +2 -0
  63. package/src/components/post/pieces/EventLocation.tsx +27 -0
  64. package/src/components/post/pieces/EventRsvpButton.tsx +3 -0
  65. package/src/components/post/pieces/PollContent.tsx +8 -2
  66. package/src/components/post/post-form/ArticleForm.tsx +1 -1
  67. package/src/components/post/post-form/EventForm.tsx +43 -15
  68. package/src/components/post/post-form/ResourceForm.tsx +132 -4
  69. package/src/components/post/post-form/VisibilitySelector.tsx +11 -3
  70. package/src/components/post/types/Article.tsx +5 -5
  71. package/src/components/post/types/Event.tsx +68 -7
  72. package/src/components/post/types/resource/FullResource.tsx +9 -1
  73. package/src/components/preview-link/local/WelcomePreview.tsx +11 -2
  74. package/src/components/resources/ResourceCard.tsx +68 -10
  75. package/src/components/resources/ResourceLibrary.tsx +2 -2
  76. package/src/hooks/events/useEventRsvp.ts +19 -7
  77. package/src/hooks/posts/useResourceComposer.ts +157 -33
  78. package/src/hooks/resources/useResourceLibrary.ts +6 -2
  79. package/src/hooks/useWelcomePreview.ts +4 -0
  80. package/src/navigation/menuItems.ts +16 -0
  81. package/src/navigation/targets.ts +2 -0
  82. package/src/pages/admin/community/CommunityMarkdownPage.tsx +5 -1
  83. package/src/pages/auth/Register.tsx +12 -0
  84. package/src/pages/resources/Edit.tsx +3 -2
  85. package/src/pages/resources/New.tsx +6 -1
  86. package/src/pages/settings/Account.tsx +51 -1
@@ -8,16 +8,13 @@ import type {
8
8
  PublicReplyPost,
9
9
  Question,
10
10
  } from '@openpeepshq/common/types';
11
- import {
12
- formatEventWhen,
13
- isHiddenPost,
14
- markdownPlainText,
15
- } from '@openpeepshq/common/lib';
11
+ import { formatEventWhen, isHiddenPost } from '@openpeepshq/common/lib';
16
12
  import { AudioLines, Calendar, CirclePlay, Paperclip } from 'lucide-react';
17
13
  import { cn } from '@openpeepshq/react-ui';
18
14
  import { useT } from '../../i18n';
19
15
  import { Avatar } from '../profile';
20
16
  import { isAudioAttachment } from './pieces/AudioAttachment';
17
+ import { TruncatedMarkdown } from './TruncatedMarkdown';
21
18
 
22
19
  export type CompactPost = Pick<
23
20
  PublicReplyPost,
@@ -119,7 +116,6 @@ const compactThumb = (post: CompactPost, t: TFunction): ReactNode => {
119
116
  const CompactNoteBody = ({ post, t }: { post: CompactPost; t: TFunction }) => {
120
117
  if (post.data?.type !== 'note') return null;
121
118
  const attachments = attachmentsOf(post);
122
- const text = markdownPlainText(post.data.content);
123
119
  const hasVisual = !!visualAttachment(attachments);
124
120
  const file = !hasVisual ? attachments[0] : undefined;
125
121
  const audio = !!file && isAudioAttachment(file);
@@ -129,10 +125,16 @@ const CompactNoteBody = ({ post, t }: { post: CompactPost; t: TFunction }) => {
129
125
  ? t('posts.compact.audio', { defaultValue: 'Audio' })
130
126
  : t('posts.compact.document', { defaultValue: 'Document' }))
131
127
  : undefined;
132
- if (!text && !docName) return null;
128
+ if (!post.data.content && !docName) return null;
133
129
  return (
134
130
  <>
135
- {text ? <p className="line-clamp-2 break-words text-sm">{text}</p> : null}
131
+ <TruncatedMarkdown
132
+ source={post.data.content ?? ''}
133
+ maxBlocks={1}
134
+ maxChars={80}
135
+ maxLines={1}
136
+ className="break-words text-sm text-muted-foreground"
137
+ />
136
138
  {docName ? (
137
139
  <p className="text-muted-foreground flex items-center gap-1 text-xs">
138
140
  {audio ? (
@@ -156,11 +158,16 @@ const CompactQuestionBody = ({
156
158
  }) => {
157
159
  if (post.data?.type !== 'question') return null;
158
160
  const data = post.data as Question;
159
- const text = markdownPlainText(data.content);
160
161
  const optionCount = data.options?.length ?? 0;
161
162
  return (
162
163
  <>
163
- {text ? <p className="line-clamp-2 break-words text-sm">{text}</p> : null}
164
+ <TruncatedMarkdown
165
+ source={data.content ?? ''}
166
+ maxBlocks={1}
167
+ maxChars={80}
168
+ maxLines={1}
169
+ className="break-words text-sm text-muted-foreground"
170
+ />
164
171
  {optionCount > 0 ? (
165
172
  <p className="text-muted-foreground truncate text-xs">
166
173
  {t('posts.compact.pollOptions', {
@@ -0,0 +1,91 @@
1
+ import { type ReactNode } from 'react';
2
+ import { truncateMarkdown } from '@openpeepshq/common/lib';
3
+ import { Popover, PopoverContent, PopoverTrigger } from '@openpeepshq/react-ui';
4
+ import { useT } from '../../i18n';
5
+ import { PostMarkdown } from './Markdown';
6
+ import { OPENPEEPS_POST_CAPTION_CLASS } from '../markdown/classes';
7
+
8
+ export interface TruncatedMarkdownProps {
9
+ /** Full markdown content; rendered in the popover when `interactive`. */
10
+ source: string;
11
+ /** Pre-truncated excerpt. When omitted, computed via `truncateMarkdown`. */
12
+ snippet?: string;
13
+ maxBlocks?: number;
14
+ maxChars?: number;
15
+ /** Lines the excerpt is clamped to (only when `interactive`). */
16
+ maxLines?: number;
17
+ /**
18
+ * When true, the excerpt is clamped and a "Show more" control reveals the
19
+ * full content in a popover (click/tap; hover on desktop via the popover).
20
+ * When false, the excerpt renders as-is — callers that own their own
21
+ * navigation keep it plain.
22
+ */
23
+ interactive?: boolean;
24
+ className?: string;
25
+ }
26
+
27
+ const clampClass = (n: number) => `line-clamp-${n as 1 | 2 | 3 | 4 | 5 | 6}`;
28
+
29
+ /**
30
+ * Single rendering surface for abbreviated markdown. The excerpt is always
31
+ * produced by the markdown-aware `truncateMarkdown` (links, images and
32
+ * emphasis are never severed), so every abbreviated preview renders as real
33
+ * markdown instead of raw text. Call sites with their own read-more navigation
34
+ * (e.g. Article) keep `interactive` off and render the link themselves.
35
+ */
36
+ export const TruncatedMarkdown = ({
37
+ source,
38
+ snippet: snippetProp,
39
+ maxBlocks = 2,
40
+ maxChars = 240,
41
+ maxLines = 2,
42
+ interactive = true,
43
+ className,
44
+ }: TruncatedMarkdownProps): ReactNode => {
45
+ const t = useT();
46
+ const excerpt = snippetProp ?? truncateMarkdown(source, maxBlocks, maxChars);
47
+ if (!excerpt) return null;
48
+
49
+ const excerptClass = [
50
+ OPENPEEPS_POST_CAPTION_CLASS,
51
+ interactive && maxLines > 0 ? clampClass(maxLines) : '',
52
+ className ?? '',
53
+ ]
54
+ .join(' ')
55
+ .trim();
56
+
57
+ const body = <PostMarkdown source={excerpt} className={excerptClass} />;
58
+
59
+ if (!interactive) return body;
60
+
61
+ return (
62
+ <div className="inline-block max-w-full align-baseline">
63
+ {body}
64
+ <Popover>
65
+ <PopoverTrigger asChild>
66
+ <button
67
+ type="button"
68
+ onClick={(e) => {
69
+ e.stopPropagation();
70
+ e.preventDefault();
71
+ }}
72
+ aria-label={t('posts.truncatedMarkdown.showHint', {
73
+ defaultValue: 'Show more',
74
+ })}
75
+ className="text-primary inline-flex items-center gap-1 text-xs font-medium underline decoration-transparent underline-offset-2 hover:decoration-inherit"
76
+ >
77
+ {t('posts.truncatedMarkdown.show', { defaultValue: 'Show more' })}
78
+ </button>
79
+ </PopoverTrigger>
80
+ <PopoverContent
81
+ side="top"
82
+ align="start"
83
+ sideOffset={8}
84
+ className="bg-popover text-popover-foreground z-50 max-w-xs rounded-md border p-3 shadow-md"
85
+ >
86
+ <PostMarkdown source={source} />
87
+ </PopoverContent>
88
+ </Popover>
89
+ </div>
90
+ );
91
+ };
@@ -1,4 +1,8 @@
1
1
  import type { PublicPost } from '@openpeepshq/common/types';
2
+ import { firstNWords as _firstNWords } from '@openpeepshq/common/lib';
3
+
4
+ /** @deprecated Use `firstNWords` from `@openpeepshq/common/lib` directly. */
5
+ export const firstNWords = _firstNWords;
2
6
 
3
7
  /** Splits a string into user-visible grapheme clusters (so emojis don't get chopped). */
4
8
  export const stringToSegments = (text: string) =>
@@ -12,21 +16,3 @@ export const postReactionStats = (post: PublicPost): string => {
12
16
  ].join('');
13
17
  return `${uniqueEmojis} ${post.reactions?.length ?? 0}`;
14
18
  };
15
-
16
- /** Truncates markdown to roughly the first N words, preserving links. */
17
- export const firstNWords = (
18
- markdown: string | undefined,
19
- n: number,
20
- ): string => {
21
- if (!markdown) return '';
22
- const regex = /\[.*?\]\(.*?\)|(\w+)/g;
23
- let wordCount = 0;
24
- const out: string[] = [];
25
- let match: RegExpExecArray | null;
26
- while ((match = regex.exec(markdown)) !== null) {
27
- if (wordCount >= n) break;
28
- out.push(match[0]);
29
- wordCount++;
30
- }
31
- return out.join(' ');
32
- };
@@ -6,6 +6,8 @@ export { FeedPostContent } from './FeedPostContent';
6
6
  export { PostDetail } from './PostDetail';
7
7
  export type { PostDetailProps } from './PostDetail';
8
8
  export { PostMarkdown, OpenpeepsMarkdown } from './Markdown';
9
+ export { TruncatedMarkdown } from './TruncatedMarkdown';
10
+ export type { TruncatedMarkdownProps } from './TruncatedMarkdown';
9
11
  export { PostMenu } from './pieces/PostMenu';
10
12
  export type { PostMenuProps } from './pieces/PostMenu';
11
13
  export { ShareMenu } from './pieces/ShareMenu';
@@ -44,6 +44,33 @@ export function EventLocation({
44
44
  : undefined;
45
45
  const jamLink = getJamUrl(post.id, origin, occurrence);
46
46
 
47
+ if (preview && staticRender) {
48
+ if (physicalLocation) {
49
+ return (
50
+ <span className="text-sm">
51
+ {truncate
52
+ ? truncateText(physicalLocation.text)
53
+ : physicalLocation.text}
54
+ </span>
55
+ );
56
+ }
57
+ if (event.jam) {
58
+ return (
59
+ <a href={jamLink} className="text-primary text-sm underline">
60
+ {t('events.location.jam', { defaultValue: 'Jam Event' })}
61
+ </a>
62
+ );
63
+ }
64
+ if (event.url) {
65
+ return (
66
+ <a href={event.url} className="text-primary text-sm underline">
67
+ {t('events.location.online', { defaultValue: 'Online' })}
68
+ </a>
69
+ );
70
+ }
71
+ return null;
72
+ }
73
+
47
74
  if (preview) {
48
75
  return (
49
76
  <div className="flex items-center gap-1 text-sm">
@@ -23,6 +23,7 @@ export const EventRsvpButton = ({
23
23
  myRsvp,
24
24
  canRsvp,
25
25
  rsvpClosed,
26
+ hideRsvpButton,
26
27
  recurring,
27
28
  defaultId,
28
29
  occurrences,
@@ -83,6 +84,8 @@ export const EventRsvpButton = ({
83
84
  );
84
85
  }
85
86
 
87
+ if (hideRsvpButton) return null;
88
+
86
89
  const scopeDialog =
87
90
  pending && recurring && !lockToOccurrence ? (
88
91
  <EventRsvpScopeDialog
@@ -247,13 +247,19 @@ export function PollContent({ post }: PollContentProps) {
247
247
 
248
248
  <div className="text-muted-foreground mt-4 flex flex-wrap items-center gap-3 text-sm">
249
249
  <span>
250
- {votes.length || 0} {t('posts.vote.count', { defaultValue: 'votes' })}
250
+ {t('posts.vote.count', {
251
+ count: votes.length || 0,
252
+ defaultValue: 'votes',
253
+ })}
251
254
  </span>
252
255
  {pollData.expiresAt ? (
253
256
  <span>
254
257
  {hasPollEnded
255
258
  ? t('posts.poll.ended', { defaultValue: 'Poll ended' })
256
- : `${formatDistanceToNow(pollData.expiresAt)} ${t('posts.poll.timeLeft', { defaultValue: 'left' })}`}
259
+ : t('posts.poll.timeLeft', {
260
+ time: formatDistanceToNow(pollData.expiresAt),
261
+ defaultValue: '{{time}} left',
262
+ })}
257
263
  </span>
258
264
  ) : null}
259
265
  {hasVoted && !hasPollEnded ? (
@@ -62,7 +62,7 @@ export function ArticleForm({
62
62
  </h2>
63
63
 
64
64
  <Label
65
- title={t('articles.form.title', { defaultValue: 'New Article' })}
65
+ title={t('articles.form.titleInput', { defaultValue: 'Title' })}
66
66
  htmlFor="article-title"
67
67
  >
68
68
  <Input
@@ -51,6 +51,7 @@ export const EventForm = ({
51
51
  }: EventFormProps) => {
52
52
  const t = useT();
53
53
  const [audienceOpen, setAudienceOpen] = useState(false);
54
+ const [endBeforeStart, setEndBeforeStart] = useState(false);
54
55
  const {
55
56
  event,
56
57
  eventTimeZone,
@@ -140,7 +141,14 @@ export const EventForm = ({
140
141
  value={dateToInputValue(event.start, eventTimeZone)}
141
142
  onChange={(e) => {
142
143
  const start = toIso(e.target.value, eventTimeZone);
143
- if (start) patchEvent({ start });
144
+ if (start) {
145
+ if (event.end && new Date(event.end) <= new Date(start)) {
146
+ setEndBeforeStart(true);
147
+ } else {
148
+ setEndBeforeStart(false);
149
+ }
150
+ patchEvent({ start });
151
+ }
144
152
  }}
145
153
  data-testid="events-start-input"
146
154
  />
@@ -160,20 +168,40 @@ export const EventForm = ({
160
168
  </Label>
161
169
 
162
170
  {showEndDate ? (
163
- <Label
164
- title={t('events.form.endDate', { defaultValue: 'End Date' })}
165
- htmlFor="event-end"
166
- >
167
- <Input
168
- id="event-end"
169
- type="datetime-local"
170
- step={60}
171
- value={dateToInputValue(event.end, eventTimeZone)}
172
- onChange={(e) =>
173
- patchEvent({ end: toIso(e.target.value, eventTimeZone) })
174
- }
175
- />
176
- </Label>
171
+ <>
172
+ <Label
173
+ title={t('events.form.endDate', { defaultValue: 'End Date' })}
174
+ htmlFor="event-end"
175
+ >
176
+ <Input
177
+ id="event-end"
178
+ type="datetime-local"
179
+ step={60}
180
+ value={dateToInputValue(event.end, eventTimeZone)}
181
+ onChange={(e) => {
182
+ const newEnd = toIso(e.target.value, eventTimeZone);
183
+ if (
184
+ newEnd &&
185
+ event.start &&
186
+ new Date(newEnd) <= new Date(event.start)
187
+ ) {
188
+ setEndBeforeStart(true);
189
+ return;
190
+ }
191
+ setEndBeforeStart(false);
192
+ patchEvent({ end: newEnd });
193
+ }}
194
+ />
195
+ </Label>
196
+ {endBeforeStart ? (
197
+ <p className="text-destructive text-sm">
198
+ {t('events.form.endBeforeStart', {
199
+ defaultValue:
200
+ 'The end date and time must be after the start date and time.',
201
+ })}
202
+ </p>
203
+ ) : null}
204
+ </>
177
205
  ) : null}
178
206
 
179
207
  <Label
@@ -5,7 +5,12 @@ import type {
5
5
  ResourceKind,
6
6
  ResourcePost,
7
7
  } from '@openpeepshq/common/types';
8
- import { RESOURCE_KINDS, normalizeResourceTags } from '@openpeepshq/common/lib';
8
+ import {
9
+ RESOURCE_KINDS,
10
+ RESOURCE_TITLE_MAX_LENGTH,
11
+ normalizeResourceTags,
12
+ resourceFormIssues,
13
+ } from '@openpeepshq/common/lib';
9
14
  import { Button, Input, Label } from '@openpeepshq/react-ui';
10
15
  import { useT } from '../../../i18n';
11
16
  import { useCurrentProfile } from '../../layout/IdentityContext';
@@ -21,19 +26,25 @@ export interface ResourceFormProps {
21
26
  postData: PostCreationData;
22
27
  onChange: (data: PostCreationData) => void;
23
28
  isEdit?: boolean;
29
+ /** Member can post this resource only to a group. */
30
+ groupOnly?: boolean;
24
31
  }
25
32
 
26
33
  export const ResourceForm = ({
27
34
  postData,
28
35
  onChange,
29
36
  isEdit = false,
37
+ groupOnly = false,
30
38
  }: ResourceFormProps) => {
31
39
  const t = useT();
32
40
  const me = useCurrentProfile();
33
41
  const resource = postData.data as ResourcePost;
34
42
  const [audienceOpen, setAudienceOpen] = useState(false);
35
43
  const [tagDraft, setTagDraft] = useState('');
36
- const library = useResourceLibrary(postData.groupId ?? undefined);
44
+ const library = useResourceLibrary(
45
+ postData.groupId ?? undefined,
46
+ !postData.groupId,
47
+ );
37
48
  const attachments = useComposeAttachments({
38
49
  attachments: resource.attachments ?? [],
39
50
  onChange: (next) => patchResource({ attachments: next }),
@@ -65,6 +76,26 @@ export const ResourceForm = ({
65
76
  }
66
77
  };
67
78
 
79
+ const issues = resourceFormIssues({
80
+ title: resource.title,
81
+ resourceKind: resource.resourceKind,
82
+ url: resource.url,
83
+ attachments: resource.attachments,
84
+ visibility: postData.visibility,
85
+ audience: postData.audience,
86
+ groupId: postData.groupId,
87
+ });
88
+ const titleMissing = issues.includes('title');
89
+ const titleTooLong = issues.includes('titleLength');
90
+ const urlIssue = issues.includes('url');
91
+ const urlInvalid = urlIssue && Boolean(resource.url?.trim());
92
+ const mediaMissing = issues.includes('media');
93
+ const audienceMissing = issues.includes('audience');
94
+ const groupMissing = issues.includes('group');
95
+ const urlMessage = t('resources.validation.url', {
96
+ defaultValue: 'Enter a real link, like https://example.com',
97
+ });
98
+
68
99
  const kindActions = useMemo(
69
100
  () => ({
70
101
  gallery: attachments.openImagePicker,
@@ -84,15 +115,51 @@ export const ResourceForm = ({
84
115
  </h2>
85
116
 
86
117
  <Label
87
- title={t('resources.form.name', { defaultValue: 'Title' })}
118
+ title={t('resources.form.nameRequired', {
119
+ defaultValue: 'Title (Required)',
120
+ })}
88
121
  htmlFor="resource-title"
89
122
  >
90
123
  <Input
91
124
  id="resource-title"
92
125
  data-testid="resources-title"
93
126
  value={resource.title}
127
+ maxLength={RESOURCE_TITLE_MAX_LENGTH}
128
+ aria-invalid={titleMissing || titleTooLong}
129
+ aria-describedby={
130
+ titleMissing
131
+ ? 'resource-title-error resource-title-count'
132
+ : 'resource-title-count'
133
+ }
94
134
  onChange={(event) => patchResource({ title: event.target.value })}
95
135
  />
136
+ {titleMissing ? (
137
+ <span
138
+ id="resource-title-error"
139
+ role="status"
140
+ className="text-muted-foreground mt-1 text-sm"
141
+ >
142
+ {t('resources.validation.titleRequired', {
143
+ defaultValue: 'Title is required',
144
+ })}
145
+ </span>
146
+ ) : null}
147
+ {titleTooLong ? (
148
+ <span role="alert" className="text-destructive mt-1 text-sm">
149
+ {t('resources.validation.titleTooLong', {
150
+ defaultValue: 'Title must be 200 characters or fewer',
151
+ })}
152
+ </span>
153
+ ) : null}
154
+ <span
155
+ id="resource-title-count"
156
+ className="block w-full px-2 text-right text-sm"
157
+ >
158
+ <span className={titleTooLong ? 'text-error' : undefined}>
159
+ {resource.title.length}
160
+ </span>{' '}
161
+ / {RESOURCE_TITLE_MAX_LENGTH}
162
+ </span>
96
163
  </Label>
97
164
 
98
165
  <div>
@@ -118,15 +185,39 @@ export const ResourceForm = ({
118
185
 
119
186
  {resource.resourceKind === 'link' ? (
120
187
  <Label
121
- title={t('resources.form.url', { defaultValue: 'URL' })}
188
+ title={t('resources.form.urlRequired', {
189
+ defaultValue: 'URL (Required)',
190
+ })}
122
191
  htmlFor="resource-url"
123
192
  >
124
193
  <Input
125
194
  id="resource-url"
126
195
  data-testid="resources-url"
127
196
  value={resource.url ?? ''}
197
+ placeholder={t('resources.form.urlPlaceholder', {
198
+ defaultValue: 'https://example.com',
199
+ })}
200
+ inputMode="url"
201
+ spellCheck={false}
202
+ error={urlInvalid}
203
+ aria-invalid={urlIssue}
204
+ aria-describedby={urlIssue ? 'resource-url-error' : undefined}
128
205
  onChange={(event) => patchResource({ url: event.target.value })}
129
206
  />
207
+ {urlIssue ? (
208
+ <span
209
+ id="resource-url-error"
210
+ role={urlInvalid ? 'alert' : 'status'}
211
+ data-testid="resources-url-error"
212
+ className={
213
+ urlInvalid
214
+ ? 'text-destructive mt-1 text-sm'
215
+ : 'text-muted-foreground mt-1 text-sm'
216
+ }
217
+ >
218
+ {urlMessage}
219
+ </span>
220
+ ) : null}
130
221
  </Label>
131
222
  ) : (
132
223
  <div className="space-y-2">
@@ -140,6 +231,13 @@ export const ResourceForm = ({
140
231
  </Button>
141
232
  {attachments.previews}
142
233
  {attachments.inputs}
234
+ {mediaMissing ? (
235
+ <p role="status" className="text-muted-foreground text-sm">
236
+ {t('resources.validation.mediaRequired', {
237
+ defaultValue: 'Add the media or link this resource needs',
238
+ })}
239
+ </p>
240
+ ) : null}
143
241
  </div>
144
242
  )}
145
243
 
@@ -217,6 +315,36 @@ export const ResourceForm = ({
217
315
  disabled={isEdit}
218
316
  showDirect
219
317
  />
318
+ {!isEdit && groupOnly ? (
319
+ <span role="status" className="text-muted-foreground mt-1 text-sm">
320
+ {t('resources.form.groupOnly', {
321
+ defaultValue: 'You can only share resources with a group.',
322
+ })}
323
+ </span>
324
+ ) : null}
325
+ {groupMissing ? (
326
+ <span
327
+ id="resource-group-error"
328
+ role="status"
329
+ className="text-muted-foreground mt-1 text-sm"
330
+ >
331
+ {t('resources.validation.groupRequired', {
332
+ defaultValue: 'Choose a group before creating this resource.',
333
+ })}
334
+ </span>
335
+ ) : null}
336
+ {audienceMissing ? (
337
+ <span
338
+ id="resource-audience-error"
339
+ role="status"
340
+ className="text-muted-foreground mt-1 text-sm"
341
+ >
342
+ {t('resources.validation.directAudience', {
343
+ defaultValue:
344
+ 'Choose at least one recipient for a direct resource.',
345
+ })}
346
+ </span>
347
+ ) : null}
220
348
  </Label>
221
349
  </div>
222
350
 
@@ -44,11 +44,19 @@ export const VisibilitySelector = ({
44
44
  const description = (visibility: string) =>
45
45
  audienceChoices.find((c) => c.value === visibility)?.description ?? '';
46
46
 
47
+ const choiceLabel = (visibility: string) =>
48
+ description(visibility) ||
49
+ (audienceChoices.length > 0
50
+ ? t('posts.form.chooseAudience', {
51
+ defaultValue: 'Choose who can see this',
52
+ })
53
+ : '');
54
+
47
55
  const content = () => {
48
56
  if (postData.visibility === 'group') {
49
57
  return (
50
58
  <span className="flex min-w-0 items-center gap-1 text-sm font-normal">
51
- <span className="shrink-0 pr-2">{description('group')}</span>
59
+ <span className="shrink-0 pr-2">{choiceLabel('group')}</span>
52
60
  {selectedGroup ? (
53
61
  <span className="flex min-w-0 items-center gap-1 truncate">
54
62
  <GroupAvatar group={selectedGroup} size={1.5} borderless />
@@ -63,7 +71,7 @@ export const VisibilitySelector = ({
63
71
  const audience = postData.audience ?? [];
64
72
  return (
65
73
  <span className="flex min-w-0 items-center gap-1 text-sm font-light">
66
- <span className="shrink-0 pr-2">{description('direct')}</span>
74
+ <span className="shrink-0 pr-2">{choiceLabel('direct')}</span>
67
75
  {audience.length ? (
68
76
  <span className="flex min-w-0 flex-wrap items-center gap-1">
69
77
  {audience.map((profile) => (
@@ -77,7 +85,7 @@ export const VisibilitySelector = ({
77
85
 
78
86
  return (
79
87
  <span className="text-sm font-light">
80
- {description(postData.visibility)}
88
+ {choiceLabel(postData.visibility)}
81
89
  </span>
82
90
  );
83
91
  };
@@ -2,8 +2,7 @@ import { ArrowRight } from 'lucide-react';
2
2
  import type { PublicPost } from '@openpeepshq/common/types';
3
3
  import { useT } from '../../../i18n';
4
4
  import { resolveStaticUrl, useStaticRender } from '../../markdown/staticRender';
5
- import { PostMarkdown } from '../Markdown';
6
- import { OPENPEEPS_POST_CAPTION_CLASS } from '../../markdown/classes';
5
+ import { TruncatedMarkdown } from '../TruncatedMarkdown';
7
6
  import { firstNWords } from '../helpers';
8
7
  import { minutesToRead } from '@openpeepshq/common/lib';
9
8
 
@@ -41,9 +40,10 @@ export function FeedArticle({ post }: FeedArticleProps) {
41
40
  </p>
42
41
  )}
43
42
  </div>
44
- <PostMarkdown
45
- source={`${previewContent}${showReadMore ? '...' : ''}`}
46
- className={OPENPEEPS_POST_CAPTION_CLASS}
43
+ <TruncatedMarkdown
44
+ source={article.content ?? ''}
45
+ snippet={previewContent}
46
+ interactive={false}
47
47
  />
48
48
  {showReadMore && (
49
49
  <div className="flex justify-end">