@openpeepshq/react 0.8.4 → 0.8.6

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 (39) hide show
  1. package/dist/components/post/pieces/Attachments.js +3 -2
  2. package/dist/components/post/pieces/AudioAttachment.d.ts +3 -1
  3. package/dist/components/post/pieces/AudioAttachment.js +2 -2
  4. package/dist/components/post/pieces/GalleryModal.js +1 -1
  5. package/dist/components/post/pieces/modals/DeletePostModal.js +4 -4
  6. package/dist/components/post/post-form/ArticleForm.d.ts +4 -1
  7. package/dist/components/post/post-form/ArticleForm.js +8 -3
  8. package/dist/components/post/post-form/EventForm.d.ts +4 -1
  9. package/dist/components/post/post-form/EventForm.js +8 -4
  10. package/dist/components/post/post-form/NewPostModal.js +9 -6
  11. package/dist/components/post/post-form/OpenpeepsMarkdownInput.js +7 -1
  12. package/dist/components/post/post-form/OpenpeepsMarkdownInput.test.d.ts +1 -0
  13. package/dist/components/post/post-form/OpenpeepsMarkdownInput.test.js +64 -0
  14. package/dist/components/post/types/resource/FullResource.js +1 -1
  15. package/dist/components/resources/ResourceCard.js +9 -0
  16. package/dist/components/resources/ResourceCard.test.js +28 -0
  17. package/dist/hooks/events/useEventComposer.d.ts +3 -0
  18. package/dist/hooks/events/useEventComposer.js +24 -1
  19. package/dist/hooks/posts/useArticleComposer.d.ts +3 -0
  20. package/dist/hooks/posts/useArticleComposer.js +24 -1
  21. package/dist/pages/articles/New.js +2 -2
  22. package/dist/pages/events/New.js +2 -2
  23. package/dist/pages/groups/Index.js +1 -1
  24. package/package.json +1 -1
  25. package/src/components/post/pieces/Attachments.tsx +11 -0
  26. package/src/components/post/pieces/AudioAttachment.tsx +10 -0
  27. package/src/components/post/pieces/GalleryModal.tsx +1 -0
  28. package/src/components/post/pieces/modals/DeletePostModal.tsx +11 -9
  29. package/src/components/post/post-form/ArticleForm.tsx +28 -1
  30. package/src/components/post/post-form/EventForm.tsx +28 -2
  31. package/src/components/post/post-form/NewPostModal.tsx +10 -12
  32. package/src/components/post/post-form/OpenpeepsMarkdownInput.tsx +8 -1
  33. package/src/components/post/types/resource/FullResource.tsx +1 -0
  34. package/src/components/resources/ResourceCard.tsx +8 -0
  35. package/src/hooks/events/useEventComposer.ts +29 -1
  36. package/src/hooks/posts/useArticleComposer.ts +29 -1
  37. package/src/pages/articles/New.tsx +10 -1
  38. package/src/pages/events/New.tsx +10 -1
  39. package/src/pages/groups/Index.tsx +1 -1
@@ -10,6 +10,7 @@ const attachmentsOf = (post) => {
10
10
  };
11
11
  const isImage = (att) => att.type === 'image' || att.meta?.mimetype?.startsWith('image/');
12
12
  const isVideo = (att) => att.type === 'video' || att.meta?.mimetype?.startsWith('video/');
13
+ const isAudio = (att) => isAudioAttachment(att);
13
14
  export function Attachments({ post }) {
14
15
  const { enabled: staticRender } = useStaticRender();
15
16
  const attachments = attachmentsOf(post);
@@ -24,7 +25,7 @@ export function Attachments({ post }) {
24
25
  return (_jsx("div", { className: "bg-surface mt-2 w-full overflow-hidden rounded-md", children: _jsx("video", { src: inline.url, poster: inline.previewUrl ?? undefined, controls: true, playsInline: true, preload: "metadata", className: "max-h-[70vh] w-full" }) }));
25
26
  }
26
27
  if (inline) {
27
- return (_jsx("div", { className: "mt-2", children: _jsx(AudioAttachment, { src: inline.url, label: inline.filename ?? inline.description, size: inline.meta?.size }) }));
28
+ return (_jsx("div", { className: "mt-2", children: _jsx(AudioAttachment, { src: inline.url, previewUrl: inline.previewUrl ?? undefined, label: inline.filename ?? inline.description, size: inline.meta?.size }) }));
28
29
  }
29
30
  const indexed = attachments.map((att, idx) => ({ att, idx }));
30
31
  const single = indexed.length === 1;
@@ -43,7 +44,7 @@ export function Attachments({ post }) {
43
44
  ? 'max-h-[600px] w-full object-contain'
44
45
  : 'h-full w-full object-cover';
45
46
  return (_jsxs(_Fragment, { children: [_jsx("div", { className: `mt-2 w-full gap-1 overflow-hidden rounded-md ${cols} ${height}`, children: indexed.map(({ att, idx }) => {
46
- const tile = (_jsx(_Fragment, { children: isImage(att) && (att.previewUrl || att.url) ? (_jsx("img", { src: att.previewUrl ?? att.url ?? '', alt: att.description ?? `attachment ${idx + 1}`, className: mediaClass })) : isVideo(att) && (att.previewUrl || att.url) ? (_jsxs("div", { className: "relative h-full w-full", children: [_jsx("img", { src: att.previewUrl ?? att.url ?? '', alt: att.description ?? `attachment ${idx + 1}`, className: mediaClass }), _jsx(VideoPlayOverlay, { video: true })] })) : (_jsxs("div", { className: "text-muted-foreground flex min-h-24 w-full flex-col items-center justify-center gap-1 p-4 text-center text-xs", children: [_jsx("span", { className: "text-foreground break-all font-medium", children: att.filename ?? att.description ?? `Attachment ${idx + 1}` }), att.meta?.mimetype ? (_jsx("span", { className: "uppercase", children: att.meta.mimetype })) : null] })) }));
47
+ const tile = (_jsx(_Fragment, { children: isImage(att) && (att.previewUrl || att.url) ? (_jsx("img", { src: att.previewUrl ?? att.url ?? '', alt: att.description ?? `attachment ${idx + 1}`, className: mediaClass })) : isVideo(att) && (att.previewUrl || att.url) ? (_jsxs("div", { className: "relative h-full w-full", children: [_jsx("img", { src: att.previewUrl ?? att.url ?? '', alt: att.description ?? `attachment ${idx + 1}`, className: mediaClass }), _jsx(VideoPlayOverlay, { video: true })] })) : isAudio(att) && att.previewUrl ? (_jsxs("div", { className: "relative h-full w-full", children: [_jsx("img", { src: att.previewUrl, alt: att.description ?? `attachment ${idx + 1}`, className: mediaClass }), _jsx(VideoPlayOverlay, { video: true })] })) : (_jsxs("div", { className: "text-muted-foreground flex min-h-24 w-full flex-col items-center justify-center gap-1 p-4 text-center text-xs", children: [_jsx("span", { className: "text-foreground break-all font-medium", children: att.filename ?? att.description ?? `Attachment ${idx + 1}` }), att.meta?.mimetype ? (_jsx("span", { className: "uppercase", children: att.meta.mimetype })) : null] })) }));
47
48
  if (staticRender) {
48
49
  return (_jsx("div", { className: `${tileClass} bg-surface overflow-hidden`, children: tile }, `${att.url ?? idx}-${idx}`));
49
50
  }
@@ -2,6 +2,8 @@ import type { MediaAttachmentData } from '@openpeepshq/common/types';
2
2
  export declare const isAudioAttachment: (att: Pick<MediaAttachmentData, "type" | "meta">) => boolean;
3
3
  export interface AudioAttachmentProps {
4
4
  src?: string;
5
+ /** Waveform/thumbnail image rendered above the controls when available. */
6
+ previewUrl?: string;
5
7
  /** File name shown above the controls. */
6
8
  label?: string;
7
9
  /** Byte size, shown next to the file name when known. */
@@ -10,4 +12,4 @@ export interface AudioAttachmentProps {
10
12
  reserveEnd?: boolean;
11
13
  className?: string;
12
14
  }
13
- export declare const AudioAttachment: ({ src, label, size, reserveEnd, className, }: AudioAttachmentProps) => import("react/jsx-runtime").JSX.Element;
15
+ export declare const AudioAttachment: ({ src, previewUrl, label, size, reserveEnd, className, }: AudioAttachmentProps) => import("react/jsx-runtime").JSX.Element;
@@ -25,7 +25,7 @@ const formatBytes = (bytes) => {
25
25
  const mb = bytes / (1024 * 1024);
26
26
  return `${mb >= 10 ? Math.round(mb) : mb.toFixed(1)} MB`;
27
27
  };
28
- export const AudioAttachment = ({ src, label, size, reserveEnd = false, className = '', }) => {
28
+ export const AudioAttachment = ({ src, previewUrl, label, size, reserveEnd = false, className = '', }) => {
29
29
  const t = useT();
30
30
  const audioRef = useRef(null);
31
31
  const [playing, setPlaying] = useState(false);
@@ -89,5 +89,5 @@ export const AudioAttachment = ({ src, label, size, reserveEnd = false, classNam
89
89
  setCurrent(value);
90
90
  };
91
91
  const canPlay = !!src;
92
- return (_jsxs("div", { role: "group", "aria-label": label ? `${playerLabel}: ${label}` : playerLabel, className: `border-border bg-surface flex w-full flex-col gap-1.5 rounded-md border px-3 py-2 ${className}`, onClick: (e) => e.stopPropagation(), children: [_jsxs("div", { className: `flex flex-col gap-1.5 ${reserveEnd ? 'pr-12' : ''}`, children: [label || fileSize ? (_jsxs("div", { className: "flex items-baseline justify-between gap-3", children: [label ? (_jsx("p", { className: "min-w-0 truncate text-sm font-medium", children: label })) : (_jsx("span", {})), fileSize ? (_jsx("span", { className: "text-muted-foreground shrink-0 text-xs", children: fileSize })) : null] })) : null, _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "button", title: playing ? pauseLabel : playLabel, "aria-label": playing ? pauseLabel : playLabel, disabled: !canPlay, onClick: togglePlay, className: "bg-primary text-primary-foreground flex size-8 shrink-0 items-center justify-center rounded-full disabled:opacity-50", children: playing ? (_jsx(Pause, { className: "size-3.5", "aria-hidden": "true" })) : (_jsx(Play, { className: "size-3.5 translate-x-px", "aria-hidden": "true" })) }), _jsx("span", { className: "text-muted-foreground w-12 shrink-0 text-xs tabular-nums", children: elapsed }), _jsx("input", { type: "range", min: 0, max: duration || 0, step: 0.1, value: Math.min(current, duration || 0), disabled: !canPlay || duration <= 0, "aria-label": seekLabel, onChange: (e) => seek(Number(e.target.value)), className: "accent-primary h-1 min-w-0 flex-1" }), _jsx("span", { className: "text-muted-foreground w-12 shrink-0 text-right text-xs tabular-nums", title: lengthLabel, children: length })] })] }), src ? (_jsx("audio", { ref: audioRef, src: src, preload: "metadata", className: "sr-only" })) : null] }));
92
+ return (_jsxs("div", { role: "group", "aria-label": label ? `${playerLabel}: ${label}` : playerLabel, className: `border-border bg-surface flex w-full flex-col gap-1.5 rounded-md border px-3 py-2 ${className}`, onClick: (e) => e.stopPropagation(), children: [_jsxs("div", { className: `flex flex-col gap-1.5 ${reserveEnd ? 'pr-12' : ''}`, children: [previewUrl ? (_jsx("img", { src: previewUrl, alt: "", className: "bg-muted h-40 w-full rounded-md object-cover" })) : null, label || fileSize ? (_jsxs("div", { className: "flex items-baseline justify-between gap-3", children: [label ? (_jsx("p", { className: "min-w-0 truncate text-sm font-medium", children: label })) : (_jsx("span", {})), fileSize ? (_jsx("span", { className: "text-muted-foreground shrink-0 text-xs", children: fileSize })) : null] })) : null, _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "button", title: playing ? pauseLabel : playLabel, "aria-label": playing ? pauseLabel : playLabel, disabled: !canPlay, onClick: togglePlay, className: "bg-primary text-primary-foreground flex size-8 shrink-0 items-center justify-center rounded-full disabled:opacity-50", children: playing ? (_jsx(Pause, { className: "size-3.5", "aria-hidden": "true" })) : (_jsx(Play, { className: "size-3.5 translate-x-px", "aria-hidden": "true" })) }), _jsx("span", { className: "text-muted-foreground w-12 shrink-0 text-xs tabular-nums", children: elapsed }), _jsx("input", { type: "range", min: 0, max: duration || 0, step: 0.1, value: Math.min(current, duration || 0), disabled: !canPlay || duration <= 0, "aria-label": seekLabel, onChange: (e) => seek(Number(e.target.value)), className: "accent-primary h-1 min-w-0 flex-1" }), _jsx("span", { className: "text-muted-foreground w-12 shrink-0 text-right text-xs tabular-nums", title: lengthLabel, children: length })] })] }), src ? (_jsx("audio", { ref: audioRef, src: src, preload: "metadata", className: "sr-only" })) : null] }));
93
93
  };
@@ -37,7 +37,7 @@ export function GalleryModal({ attachments, initialIndex = 0, onClose, }) {
37
37
  stop(e);
38
38
  onClose();
39
39
  }, children: [attachments.length > 1 ? (_jsxs("button", { type: "button", title: prevLabel, "aria-label": prevLabel, className: "rounded-button absolute left-2 top-1/2 z-50 -translate-y-1/2 bg-white/15 p-4 text-xl font-bold shadow-xl md:left-4", onClick: prev, children: [_jsx("span", { "aria-hidden": "true", children: "\u2190" }), _jsx("span", { className: "sr-only", children: prevLabel })] })) : null, _jsx("div", { className: "max-h-[90vh] max-w-[90vw] overflow-auto p-4", onClick: (e) => e.stopPropagation(), children: attachment.type === 'video' ||
40
- attachment.meta?.mimetype?.startsWith('video/') ? (_jsx(VideoPlayer, { attachment: attachment, className: "max-h-[85vh] max-w-full" }, attachment.url)) : isAudioAttachment(attachment) ? (_jsx(AudioAttachment, { src: attachment.url, label: attachment.filename ?? attachment.description, size: attachment.meta?.size, className: "w-full min-w-[280px] max-w-lg" }, attachment.url)) : attachment.type === 'image' ||
40
+ attachment.meta?.mimetype?.startsWith('video/') ? (_jsx(VideoPlayer, { attachment: attachment, className: "max-h-[85vh] max-w-full" }, attachment.url)) : isAudioAttachment(attachment) ? (_jsx(AudioAttachment, { src: attachment.url, previewUrl: attachment.previewUrl ?? undefined, label: attachment.filename ?? attachment.description, size: attachment.meta?.size, className: "w-full min-w-[280px] max-w-lg" }, attachment.url)) : attachment.type === 'image' ||
41
41
  attachment.meta?.mimetype?.startsWith('image/') ? (_jsx("img", { src: attachment.url ?? attachment.previewUrl ?? '', alt: attachment.description ?? '', className: "max-h-[85vh] max-w-full object-contain" })) : (_jsxs("div", { className: "bg-surface space-y-3 rounded-md p-6 text-center", children: [_jsx("p", { className: "font-medium", children: attachment.filename ?? attachment.description ?? 'Document' }), attachment.url ? (_jsx("a", { href: attachment.url, target: "_blank", rel: "noreferrer", className: "text-primary underline", children: t('posts.gallery.openDocument', {
42
42
  defaultValue: 'Open file',
43
43
  }) })) : null] })) }), attachments.length > 1 ? (_jsxs("button", { type: "button", title: nextLabel, "aria-label": nextLabel, className: "rounded-button absolute right-2 top-1/2 z-50 -translate-y-1/2 bg-white/15 p-4 text-xl font-bold shadow-xl md:right-4", onClick: next, children: [_jsx("span", { "aria-hidden": "true", children: "\u2192" }), _jsx("span", { className: "sr-only", children: nextLabel })] })) : null, _jsxs("button", { type: "button", title: closeLabel, "aria-label": closeLabel, className: "rounded-button bg-primary text-primary-foreground fixed right-4 top-4 z-50 px-3 py-2 text-lg font-bold shadow-xl", onClick: (e) => {
@@ -12,11 +12,11 @@ export function DeletePostModal({ post, open, onClose, deleteCallback, }) {
12
12
  deleteCallback?.();
13
13
  onClose();
14
14
  };
15
- return (_jsx(Dialog, { open: open, onOpenChange: (next) => !next && onClose(), children: _jsxs(DialogContent, { className: "max-w-lg overflow-x-hidden", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: t('posts.deleteModal.deletePostTitle', {
15
+ return (_jsx(Dialog, { open: open, onOpenChange: (next) => !next && onClose(), children: _jsxs(DialogContent, { className: "flex max-h-[90vh] max-w-lg flex-col overflow-x-hidden", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: t('posts.deleteModal.deletePostTitle', {
16
16
  defaultValue: 'Delete post',
17
- }) }) }), _jsxs("article", { className: "min-w-0 overflow-x-hidden", children: [_jsx(FeedPost, { post: post, noReactionHeader: true }), _jsx("p", { className: "my-4 text-sm", children: t('posts.delete.confirm', {
18
- defaultValue: 'Are you sure you want to delete this post?',
19
- }) })] }), _jsx(DialogActions, { cancelLabel: t('posts.deleteModal.cancel', {
17
+ }) }) }), _jsx("div", { className: "min-h-0 flex-1 overflow-y-auto", children: _jsxs("article", { className: "min-w-0 overflow-x-hidden", children: [_jsx(FeedPost, { post: post, noReactionHeader: true }), _jsx("p", { className: "my-4 text-sm", children: t('posts.delete.confirm', {
18
+ defaultValue: 'Are you sure you want to delete this post?',
19
+ }) })] }) }), _jsx(DialogActions, { cancelLabel: t('posts.deleteModal.cancel', {
20
20
  defaultValue: 'Cancel',
21
21
  }), onCancel: onClose, actionLabel: t('posts.deleteModal.delete', {
22
22
  defaultValue: 'Delete',
@@ -3,5 +3,8 @@ export interface ArticleFormProps {
3
3
  postData: PostCreationData;
4
4
  onChange: (data: PostCreationData) => void;
5
5
  isEdit?: boolean;
6
+ showNotify?: boolean;
7
+ notify?: boolean;
8
+ onNotifyChange?: (value: boolean) => void;
6
9
  }
7
- export declare function ArticleForm({ postData, onChange, isEdit, }: ArticleFormProps): import("react/jsx-runtime").JSX.Element;
10
+ export declare function ArticleForm({ postData, onChange, isEdit, showNotify, notify, onNotifyChange, }: ArticleFormProps): import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
- import { Input, Label } from '@openpeepshq/react-ui';
3
+ import { Megaphone } from 'lucide-react';
4
+ import { Input, Label, Switch } from '@openpeepshq/react-ui';
4
5
  import { useT } from '../../../i18n/index.js';
5
6
  import { useCurrentProfile } from '../../layout/IdentityContext.js';
6
7
  import { applyAudienceSetting } from '../../../lib/audienceSetting.js';
@@ -9,7 +10,7 @@ import { OpenpeepsMarkdownInput } from './OpenpeepsMarkdownInput.js';
9
10
  import { ComposePreviewLinks } from './ComposePreviewLinks.js';
10
11
  import { PostAudienceSelector } from './PostAudienceSelector.js';
11
12
  import { VisibilitySelector } from './VisibilitySelector.js';
12
- export function ArticleForm({ postData, onChange, isEdit = false, }) {
13
+ export function ArticleForm({ postData, onChange, isEdit = false, showNotify = false, notify = false, onNotifyChange, }) {
13
14
  const t = useT();
14
15
  const me = useCurrentProfile();
15
16
  const article = postData.data;
@@ -29,5 +30,9 @@ export function ArticleForm({ postData, onChange, isEdit = false, }) {
29
30
  defaultValue: 'Who can see this (Required)',
30
31
  }), description: t('articles.form.visibilityNotChangeable', {
31
32
  defaultValue: "Once you post your article, you can't change the visibility",
32
- }), children: _jsx(VisibilitySelector, { postData: postData, onClick: () => setAudienceOpen(true), disabled: isEdit, showDirect: true }) })] }), !isEdit ? (_jsx(PostAudienceSelector, { open: audienceOpen, onClose: () => setAudienceOpen(false), type: "article", visibility: postData.visibility, groupId: postData.groupId ?? undefined, audience: postData.audience ?? [], showDirect: true, onConfirm: setAudience })) : null] }));
33
+ }), children: _jsx(VisibilitySelector, { postData: postData, onClick: () => setAudienceOpen(true), disabled: isEdit, showDirect: true }) }), showNotify ? (_jsxs("div", { className: "flex w-full items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Megaphone, { className: "size-5" }), _jsx("p", { className: "text-base", children: t('posts.form.notifyEveryone', {
34
+ defaultValue: 'Notify everyone',
35
+ }) })] }), _jsx(Switch, { checked: notify, onCheckedChange: (checked) => onNotifyChange?.(checked), "aria-label": t('posts.form.notifyEveryone', {
36
+ defaultValue: 'Notify everyone',
37
+ }) })] })) : null] }), !isEdit ? (_jsx(PostAudienceSelector, { open: audienceOpen, onClose: () => setAudienceOpen(false), type: "article", visibility: postData.visibility, groupId: postData.groupId ?? undefined, audience: postData.audience ?? [], showDirect: true, onConfirm: setAudience })) : null] }));
33
38
  }
@@ -4,5 +4,8 @@ export interface EventFormProps {
4
4
  onChange: (data: PostCreationData) => void;
5
5
  isEdit?: boolean;
6
6
  occurrenceEdit?: boolean;
7
+ showNotify?: boolean;
8
+ notify?: boolean;
9
+ onNotifyChange?: (value: boolean) => void;
7
10
  }
8
- export declare const EventForm: ({ postData, onChange, isEdit, occurrenceEdit, }: EventFormProps) => import("react/jsx-runtime").JSX.Element;
11
+ export declare const EventForm: ({ postData, onChange, isEdit, occurrenceEdit, showNotify, notify, onNotifyChange, }: EventFormProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
- import { X } from 'lucide-react';
3
+ import { Megaphone, X } from 'lucide-react';
4
4
  import { EVENT_HEADER_ASPECT_RATIO, parseEventMaxAttendeesInput, parseEventWaitlistOfferMinutesInput, utcIsoToZonedDateTime, zonedDateTimeToUtcIso, } from '@openpeepshq/common/lib';
5
- import { Input, Label } from '@openpeepshq/react-ui';
5
+ import { Input, Label, Switch } from '@openpeepshq/react-ui';
6
6
  import { useT } from '../../../i18n/index.js';
7
7
  import { EVENT_WEEKDAYS, useEventForm, } from '../../../hooks/events/useEventForm.js';
8
8
  import { ImageInput } from '../../form/ImageInput.js';
@@ -16,7 +16,7 @@ const toIso = (value, timeZone) => zonedDateTimeToUtcIso(value, timeZone);
16
16
  const TIMEZONES = typeof Intl !== 'undefined' && 'supportedValuesOf' in Intl
17
17
  ? Intl.supportedValuesOf('timeZone')
18
18
  : [Intl.DateTimeFormat().resolvedOptions().timeZone];
19
- export const EventForm = ({ postData, onChange, isEdit = false, occurrenceEdit = false, }) => {
19
+ export const EventForm = ({ postData, onChange, isEdit = false, occurrenceEdit = false, showNotify = false, notify = false, onNotifyChange, }) => {
20
20
  const t = useT();
21
21
  const [audienceOpen, setAudienceOpen] = useState(false);
22
22
  const [endBeforeStart, setEndBeforeStart] = useState(false);
@@ -88,7 +88,11 @@ export const EventForm = ({ postData, onChange, isEdit = false, occurrenceEdit =
88
88
  .join(', '),
89
89
  }) })) : null] })) : null] })) : null, _jsx("h2", { className: "text-lg", children: t('events.form.location', { defaultValue: 'Location' }) }), _jsx(EventTypeSwitcher, { event: event, isEdit: isEdit, onChange: setEvent }), _jsx("h2", { className: "text-lg", children: t('events.form.people', { defaultValue: 'People' }) }), _jsx(Label, { title: t('events.form.visibility', { defaultValue: 'Visibility' }), description: t('events.form.visibilityNotChangeable', {
90
90
  defaultValue: "Note: The event visibility cannot be changed once the event is published. Make sure you're adding the right people or group.",
91
- }), children: _jsx(VisibilitySelector, { postData: postData, onClick: () => setAudienceOpen(true), disabled: isEdit, showDirect: true }) }), _jsx(Label, { description: t('events.form.attendeeListPublic', {
91
+ }), children: _jsx(VisibilitySelector, { postData: postData, onClick: () => setAudienceOpen(true), disabled: isEdit, showDirect: true }) }), showNotify ? (_jsxs("div", { className: "flex w-full items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Megaphone, { className: "size-5" }), _jsx("p", { className: "text-base", children: t('posts.form.notifyEveryone', {
92
+ defaultValue: 'Notify everyone',
93
+ }) })] }), _jsx(Switch, { checked: notify, onCheckedChange: (checked) => onNotifyChange?.(checked), "aria-label": t('posts.form.notifyEveryone', {
94
+ defaultValue: 'Notify everyone',
95
+ }) })] })) : null, _jsx(Label, { description: t('events.form.attendeeListPublic', {
92
96
  defaultValue: 'Let an attendee see others attending this event',
93
97
  }), forCheckbox: true, children: _jsx("input", { type: "checkbox", checked: event.attendeeListPublic ?? false, onChange: (e) => patchEvent({ attendeeListPublic: e.target.checked }) }) }), _jsx(Label, { title: t('events.form.maxAttendees', {
94
98
  defaultValue: 'Maximum attendees',
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useEffect, useMemo, useState } from 'react';
3
3
  import { AudioLines, ChevronDown, Image, Megaphone, Paperclip, } from 'lucide-react';
4
- import { checkRoleCapabilities, pollOptionsWithinLimit, resolvePollOptionContents, } from '@openpeepshq/common';
4
+ import { canAnnouncePosts, isCommunityWideVisibility, pollOptionsWithinLimit, resolvePollOptionContents, } from '@openpeepshq/common';
5
5
  import { Button, Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from '@openpeepshq/react-ui';
6
6
  import { useOpenpeeps } from '../../../contexts/openpeeps/index.js';
7
7
  import { useT } from '../../../i18n/index.js';
@@ -72,7 +72,11 @@ export function NewPostModal({ visibility: initialVisibility, group, initialCont
72
72
  const selectComposerType = (next) => {
73
73
  if (next === composerType)
74
74
  return;
75
- setContent(draftContent(next));
75
+ const stored = draftContent(next);
76
+ // The note body and poll question share one field. When the destination
77
+ // has no stored draft, keep the current text so note -> poll carries the
78
+ // typed note over as the poll question instead of erasing it.
79
+ setContent(stored || content);
76
80
  setComposerType(next);
77
81
  };
78
82
  // Persist the active draft so note/poll content survives a modal close,
@@ -126,8 +130,8 @@ export function NewPostModal({ visibility: initialVisibility, group, initialCont
126
130
  groupId,
127
131
  audience,
128
132
  ]);
129
- const canNotify = useMemo(() => checkRoleCapabilities(me?.roles ?? [], ['allpeep-core-admin-notify'])
130
- .success, [me?.roles]);
133
+ const canNotify = useMemo(() => canAnnouncePosts(me?.roles), [me?.roles]);
134
+ const showNotify = canNotify && isCommunityWideVisibility(visibility);
131
135
  const selectedGroupName = useMemo(() => {
132
136
  if (!groupId)
133
137
  return undefined;
@@ -220,7 +224,7 @@ export function NewPostModal({ visibility: initialVisibility, group, initialCont
220
224
  await joinGroup({ id: targetGroupId });
221
225
  }
222
226
  const response = await createPost(payload);
223
- if (notify && canNotify && response?.id) {
227
+ if (notify && showNotify && response?.id) {
224
228
  await announcePost({ id: response.id });
225
229
  }
226
230
  if (composerType === 'question') {
@@ -250,7 +254,6 @@ export function NewPostModal({ visibility: initialVisibility, group, initialCont
250
254
  setSubmitting(false);
251
255
  }
252
256
  };
253
- const showNotify = canNotify && (visibility === 'public' || visibility === 'local');
254
257
  return (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: true, onOpenChange: (open) => !open && onClose(), children: _jsxs(DialogContent, { className: "flex max-h-[90vh] max-w-xl flex-col gap-0 overflow-hidden p-0", children: [_jsxs("div", { className: "min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-6 pb-4 pt-6", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: t('posts.newPost.title', { defaultValue: 'New post' }) }) }), !group && me ? (_jsxs("button", { type: "button", title: t('posts.form.changeAudience', {
255
258
  defaultValue: 'Change audience',
256
259
  }), className: "hover:bg-surface rounded-button flex w-full items-center gap-3 border p-3 text-left", onClick: () => setAudienceOpen(true), children: [_jsx(Avatar, { profile: me, size: 3, borderless: true }), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col", children: [_jsxs("span", { className: "flex items-center gap-1 font-medium capitalize", children: [me.displayName ?? me.handle, _jsx(ChevronDown, { className: "text-muted-foreground size-4" })] }), _jsx("span", { className: "text-muted-foreground text-sm", children: visibility === 'direct' && audience.length > 0 ? (_jsx("span", { className: "flex flex-wrap gap-1", children: audience.map((profile) => (_jsx(ProfileBadge, { profile: profile }, profile.id))) })) : (audienceSummary(visibility, t, selectedGroupName, audience.length)) })] })] })) : null, _jsx(OpenpeepsMarkdownInput, { rows: 5, value: content, onChange: setContent, testId: "posts-composer-content", placeholder: composerType === 'question'
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useMemo, useRef, useState } from 'react';
2
+ import { useLayoutEffect, useMemo, useRef, useState } from 'react';
3
3
  import { Button, Popover, PopoverAnchor, PopoverContent, Textarea, cn, } from '@openpeepshq/react-ui';
4
4
  import { useT } from '../../../i18n/index.js';
5
5
  import { useOpenpeeps } from '../../../contexts/openpeeps/index.js';
@@ -17,6 +17,12 @@ export function OpenpeepsMarkdownInput({ value, onChange, maxLength = 500, place
17
17
  const [open, setOpen] = useState(false);
18
18
  const [showPreview, setShowPreview] = useState(false);
19
19
  const textareaRef = useRef(null);
20
+ // Preview is local state. Clearing the text after send has to leave an
21
+ // editable field, not the preview overlay.
22
+ useLayoutEffect(() => {
23
+ if (value.length === 0)
24
+ setShowPreview(false);
25
+ }, [value]);
20
26
  const anchorRef = useRef(null);
21
27
  const profilesQuery = openpeepsApi.useSearchProfiles(query);
22
28
  const profiles = useMemo(() => (profilesQuery.data?.pages ?? [])
@@ -0,0 +1,64 @@
1
+ /** @vitest-environment jsdom */
2
+ import { act, createElement } from 'react';
3
+ import { createRoot } from 'react-dom/client';
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
+ import { OpenpeepsMarkdownInput } from './OpenpeepsMarkdownInput.js';
6
+ vi.mock('../../../i18n', () => ({
7
+ useT: () => (key, opts) => opts?.defaultValue ?? key,
8
+ }));
9
+ vi.mock('../../../contexts/openpeeps', () => ({
10
+ useOpenpeeps: () => ({
11
+ openpeepsApi: {
12
+ useSearchProfiles: () => ({ data: undefined }),
13
+ },
14
+ }),
15
+ }));
16
+ vi.mock('../../markdown', () => ({
17
+ OpenpeepsMarkdown: ({ source }) => createElement('div', { 'data-testid': 'markdown-preview' }, source),
18
+ }));
19
+ vi.mock('../../profile', () => ({
20
+ ProfileCard: () => null,
21
+ }));
22
+ const renderInput = (root, props) => {
23
+ act(() => {
24
+ root.render(createElement(OpenpeepsMarkdownInput, props));
25
+ });
26
+ };
27
+ describe('OpenpeepsMarkdownInput', () => {
28
+ let root;
29
+ let container;
30
+ beforeEach(() => {
31
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
32
+ });
33
+ afterEach(() => {
34
+ act(() => {
35
+ root?.unmount();
36
+ });
37
+ container?.remove();
38
+ root = undefined;
39
+ container = undefined;
40
+ });
41
+ const mount = () => {
42
+ container = document.createElement('div');
43
+ document.body.appendChild(container);
44
+ root = createRoot(container);
45
+ return { container, root };
46
+ };
47
+ it('returns to the empty editor after the text is cleared from preview', async () => {
48
+ const { container, root } = mount();
49
+ const onChange = vi.fn();
50
+ renderInput(root, { value: '[TEST] `code` check', onChange });
51
+ const preview = [...container.querySelectorAll('button')].find((button) => button.textContent === 'Preview');
52
+ expect(preview).toBeTruthy();
53
+ await act(async () => {
54
+ preview?.click();
55
+ });
56
+ expect(container.textContent).toContain('Back to Editing');
57
+ expect(container.querySelector('[data-testid="markdown-preview"]')?.textContent).toBe('[TEST] `code` check');
58
+ renderInput(root, { value: '', onChange });
59
+ expect(container.textContent).not.toContain('Back to Editing');
60
+ const textarea = container.querySelector('textarea');
61
+ expect(textarea).toBeTruthy();
62
+ expect(textarea?.value).toBe('');
63
+ });
64
+ });
@@ -89,7 +89,7 @@ export const FullResource = ({ post }) => {
89
89
  if (resource.resourceKind === 'audio' && playerVisible) {
90
90
  const audioAtt = resource.attachments?.find((a) => attachmentMediaKind(a) === 'audio');
91
91
  if (audioAtt?.url) {
92
- return (_jsx(ResourceCard, { post: post, showDescription: false, inGroup: !!post.group, preview: _jsx(AudioAttachment, { src: audioAtt.url, label: audioAtt.filename ?? audioAtt.description, size: audioAtt.meta?.size }) }));
92
+ return (_jsx(ResourceCard, { post: post, showDescription: false, inGroup: !!post.group, preview: _jsx(AudioAttachment, { src: audioAtt.url, previewUrl: audioAtt.previewUrl ?? undefined, label: audioAtt.filename ?? audioAtt.description, size: audioAtt.meta?.size }) }));
93
93
  }
94
94
  }
95
95
  // All kinds: ResourceCard with click overlay
@@ -127,6 +127,15 @@ export const ResourceCard = ({ post, layout = 'card', preview, showDescription =
127
127
  const fileAtt = attachments.find((att) => attachmentMediaKind(att) === 'file' ||
128
128
  attachmentMediaKind(att) === 'video' ||
129
129
  attachmentMediaKind(att) === 'audio');
130
+ // File resources show their filename (with extension) so users can tell
131
+ // what they're about to download; other kinds show the size.
132
+ if (resource.resourceKind === 'file') {
133
+ const size = fileAtt?.meta?.size;
134
+ const filename = fileAtt?.filename;
135
+ if (filename && size)
136
+ return `${filename} · ${formatSize(size)}`;
137
+ return filename ?? (size ? formatSize(size) : null);
138
+ }
130
139
  const size = fileAtt?.meta?.size;
131
140
  if (size)
132
141
  return formatSize(size);
@@ -40,6 +40,23 @@ const resourcePost = (tags) => ({
40
40
  tags,
41
41
  },
42
42
  });
43
+ const filePost = () => ({
44
+ id: 'post-file',
45
+ type: 'resource',
46
+ data: {
47
+ type: 'resource',
48
+ title: 'Quarterly report',
49
+ resourceKind: 'file',
50
+ attachments: [
51
+ {
52
+ type: 'file',
53
+ url: 'https://cdn.example.com/report.pdf',
54
+ filename: 'report.pdf',
55
+ meta: { size: 2500000, mimetype: 'application/pdf' },
56
+ },
57
+ ],
58
+ },
59
+ });
43
60
  describe('ResourceCard', () => {
44
61
  let root;
45
62
  let container;
@@ -72,4 +89,15 @@ describe('ResourceCard', () => {
72
89
  hashtag: 'juneteenth',
73
90
  });
74
91
  });
92
+ it('shows the filename with its extension for a file resource', async () => {
93
+ container = document.createElement('div');
94
+ document.body.appendChild(container);
95
+ root = createRoot(container);
96
+ await act(async () => {
97
+ root?.render(createElement(ResourceCard, { post: filePost() }));
98
+ });
99
+ // filename + extension, followed by the formatted size
100
+ expect(container.textContent).toContain('report.pdf');
101
+ expect(container.textContent).toContain('2.4 MB');
102
+ });
75
103
  });
@@ -364,6 +364,9 @@ export declare const useNewEvent: () => {
364
364
  submitting: boolean;
365
365
  error: string | null;
366
366
  clearError: () => void;
367
+ notify: boolean;
368
+ setNotify: import("react").Dispatch<import("react").SetStateAction<boolean>>;
369
+ showNotify: boolean;
367
370
  submit: () => Promise<void>;
368
371
  };
369
372
  export declare const useEditEvent: (eventId: string, occurrence?: string) => {
@@ -1,21 +1,28 @@
1
1
  import { useCallback, useEffect, useMemo, useState } from 'react';
2
+ import { canAnnouncePosts, isCommunityWideVisibility, } from '@openpeepshq/common';
2
3
  import { effectiveEventTimes, normalizeEventDataForSave, upsertEventException, } from '@openpeepshq/common/lib';
3
4
  import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
4
5
  import { useNavigate } from '../../contexts/router/index.js';
5
6
  import { useT } from '../../i18n/context.js';
7
+ import { useCurrentProfile } from '../../components/layout/IdentityContext.js';
6
8
  import { useServerInfo } from '../../components/server-data/context.js';
7
9
  import { eventSanitizer, getNewPostStores } from '../../stores/newPosts.js';
8
10
  export const useNewEvent = () => {
9
11
  const t = useT();
10
12
  const navigate = useNavigate();
11
13
  const serverInfo = useServerInfo();
14
+ const me = useCurrentProfile();
12
15
  const { openpeepsApi } = useOpenpeeps();
13
16
  const createPost = openpeepsApi.createPostAction();
17
+ const announcePost = openpeepsApi.admin.announcePostAction();
14
18
  const stores = getNewPostStores();
15
19
  const sanitize = useMemo(() => eventSanitizer(serverInfo.publicContent), [serverInfo.publicContent]);
16
20
  const [postData, setPostDataState] = useState(() => sanitize(stores.event));
21
+ const [notify, setNotify] = useState(false);
17
22
  const [submitting, setSubmitting] = useState(false);
18
23
  const [error, setError] = useState(null);
24
+ const showNotify = canAnnouncePosts(me?.roles) &&
25
+ isCommunityWideVisibility(postData.visibility);
19
26
  const event = postData.data.type === 'event' ? postData.data : null;
20
27
  const canSubmit = !!event?.start &&
21
28
  !!event?.name?.trim() &&
@@ -49,6 +56,9 @@ export const useNewEvent = () => {
49
56
  type: 'event',
50
57
  data: normalizeEventDataForSave(event),
51
58
  });
59
+ if (notify && showNotify && created.id) {
60
+ await announcePost({ id: created.id });
61
+ }
52
62
  stores.resetNewEventState();
53
63
  navigate({ type: 'post', id: created.id });
54
64
  }
@@ -58,7 +68,17 @@ export const useNewEvent = () => {
58
68
  finally {
59
69
  setSubmitting(false);
60
70
  }
61
- }, [createPost, event, navigate, postData, stores, t]);
71
+ }, [
72
+ announcePost,
73
+ createPost,
74
+ event,
75
+ navigate,
76
+ notify,
77
+ postData,
78
+ showNotify,
79
+ stores,
80
+ t,
81
+ ]);
62
82
  return {
63
83
  postData,
64
84
  setPostData,
@@ -66,6 +86,9 @@ export const useNewEvent = () => {
66
86
  submitting,
67
87
  error,
68
88
  clearError: () => setError(null),
89
+ notify,
90
+ setNotify,
91
+ showNotify,
69
92
  submit,
70
93
  };
71
94
  };
@@ -364,6 +364,9 @@ export declare const useNewArticle: () => {
364
364
  submitting: boolean;
365
365
  error: string | null;
366
366
  clearError: () => void;
367
+ notify: boolean;
368
+ setNotify: import("react").Dispatch<import("react").SetStateAction<boolean>>;
369
+ showNotify: boolean;
367
370
  submit: () => Promise<void>;
368
371
  };
369
372
  export declare const useEditArticle: (articleId: string) => {
@@ -1,15 +1,19 @@
1
1
  import { useCallback, useEffect, useState } from 'react';
2
+ import { canAnnouncePosts, isCommunityWideVisibility, } from '@openpeepshq/common';
2
3
  import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
3
4
  import { useNavigate } from '../../contexts/router/index.js';
4
5
  import { useT } from '../../i18n/context.js';
6
+ import { useCurrentProfile } from '../../components/layout/IdentityContext.js';
5
7
  import { useServerInfo } from '../../components/server-data/index.js';
6
8
  import { defaultNewArticle, getNewPostStores } from '../../stores/index.js';
7
9
  export const useNewArticle = () => {
8
10
  const t = useT();
9
11
  const navigate = useNavigate();
10
12
  const serverInfo = useServerInfo();
13
+ const me = useCurrentProfile();
11
14
  const { openpeepsApi } = useOpenpeeps();
12
15
  const createPost = openpeepsApi.createPostAction();
16
+ const announcePost = openpeepsApi.admin.announcePostAction();
13
17
  const stores = getNewPostStores();
14
18
  const [postData, setPostDataState] = useState(() => {
15
19
  const stored = stores.article;
@@ -18,8 +22,11 @@ export const useNewArticle = () => {
18
22
  }
19
23
  return defaultNewArticle(serverInfo.publicContent);
20
24
  });
25
+ const [notify, setNotify] = useState(false);
21
26
  const [submitting, setSubmitting] = useState(false);
22
27
  const [error, setError] = useState(null);
28
+ const showNotify = canAnnouncePosts(me?.roles) &&
29
+ isCommunityWideVisibility(postData.visibility);
23
30
  const article = postData.data.type === 'article' ? postData.data : null;
24
31
  const canSubmit = !!article?.title?.trim() &&
25
32
  !(postData.visibility === 'direct' && !postData.audience?.length);
@@ -42,6 +49,9 @@ export const useNewArticle = () => {
42
49
  setSubmitting(true);
43
50
  try {
44
51
  const created = await createPost({ ...postData, type: 'article' });
52
+ if (notify && showNotify && created.id) {
53
+ await announcePost({ id: created.id });
54
+ }
45
55
  stores.resetNewArticleState();
46
56
  navigate({ type: 'post', id: created.id });
47
57
  }
@@ -51,7 +61,17 @@ export const useNewArticle = () => {
51
61
  finally {
52
62
  setSubmitting(false);
53
63
  }
54
- }, [article, createPost, navigate, postData, stores, t]);
64
+ }, [
65
+ announcePost,
66
+ article,
67
+ createPost,
68
+ navigate,
69
+ notify,
70
+ postData,
71
+ showNotify,
72
+ stores,
73
+ t,
74
+ ]);
55
75
  return {
56
76
  postData,
57
77
  setPostData,
@@ -59,6 +79,9 @@ export const useNewArticle = () => {
59
79
  submitting,
60
80
  error,
61
81
  clearError: () => setError(null),
82
+ notify,
83
+ setNotify,
84
+ showNotify,
62
85
  submit,
63
86
  };
64
87
  };
@@ -6,10 +6,10 @@ import { useNewArticle } from '../../hooks/index.js';
6
6
  import { Button, Toast } from '@openpeepshq/react-ui';
7
7
  export function NewArticle() {
8
8
  const t = useT();
9
- const { postData, setPostData, canSubmit, submitting, error, clearError, submit, } = useNewArticle();
9
+ const { postData, setPostData, canSubmit, submitting, error, clearError, notify, setNotify, showNotify, submit, } = useNewArticle();
10
10
  const headerActions = useMemo(() => (_jsx(Button, { title: t('articles.create.title', { defaultValue: 'Create article' }), variant: "default", action: submit, disabled: submitting || !canSubmit, children: submitting
11
11
  ? t('common.submitting', { defaultValue: 'Publishing…' })
12
12
  : t('articles.create.title', { defaultValue: 'Create article' }) })), [canSubmit, submit, submitting, t]);
13
13
  useSetPageHeader(t('articles.new', { defaultValue: 'New article' }), headerActions);
14
- return (_jsxs("div", { className: "pb-12", children: [_jsx(ArticleForm, { postData: postData, onChange: setPostData }), error ? (_jsx("div", { className: "px-3", children: _jsx(Toast, { variant: "error", onDismiss: clearError, children: error }) })) : null] }));
14
+ return (_jsxs("div", { className: "pb-12", children: [_jsx(ArticleForm, { postData: postData, onChange: setPostData, showNotify: showNotify, notify: notify, onNotifyChange: setNotify }), error ? (_jsx("div", { className: "px-3", children: _jsx(Toast, { variant: "error", onDismiss: clearError, children: error }) })) : null] }));
15
15
  }
@@ -6,10 +6,10 @@ import { EventForm } from '../../components/index.js';
6
6
  import { Button, Toast } from '@openpeepshq/react-ui';
7
7
  export function NewEvent() {
8
8
  const t = useT();
9
- const { postData, setPostData, canSubmit, submitting, error, clearError, submit, } = useNewEvent();
9
+ const { postData, setPostData, canSubmit, submitting, error, clearError, notify, setNotify, showNotify, submit, } = useNewEvent();
10
10
  const headerActions = useMemo(() => (_jsx(Button, { title: t('events.create.title', { defaultValue: 'Create Event' }), variant: "default", action: submit, disabled: submitting || !canSubmit, "data-testid": "events-create-submit", children: submitting
11
11
  ? t('common.submitting', { defaultValue: 'Creating…' })
12
12
  : t('events.create.title', { defaultValue: 'Create Event' }) })), [canSubmit, submit, submitting, t]);
13
13
  useSetPageHeader(t('events.create.title', { defaultValue: 'Create Event' }), headerActions);
14
- return (_jsxs("div", { className: "pb-12", children: [_jsx(EventForm, { postData: postData, onChange: setPostData }), error ? (_jsx("div", { className: "px-3", children: _jsx(Toast, { variant: "error", onDismiss: clearError, children: error }) })) : null] }));
14
+ return (_jsxs("div", { className: "pb-12", children: [_jsx(EventForm, { postData: postData, onChange: setPostData, showNotify: showNotify, notify: notify, onNotifyChange: setNotify }), error ? (_jsx("div", { className: "px-3", children: _jsx(Toast, { variant: "error", onDismiss: clearError, children: error }) })) : null] }));
15
15
  }
@@ -23,7 +23,7 @@ export function GroupsIndex() {
23
23
  const canCreate = canCreateGroup(currentProfile?.roles ?? []);
24
24
  const plusButton = useMemo(() => canCreate
25
25
  ? {
26
- title: t('groups.new', { defaultValue: 'New Group' }),
26
+ title: t('groups.new.label', { defaultValue: 'New Group' }),
27
27
  icon: Plus,
28
28
  action: '/groups/new',
29
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/react",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,6 +21,7 @@ const isImage = (att: MediaAttachmentData) =>
21
21
  att.type === 'image' || att.meta?.mimetype?.startsWith('image/');
22
22
  const isVideo = (att: MediaAttachmentData) =>
23
23
  att.type === 'video' || att.meta?.mimetype?.startsWith('video/');
24
+ const isAudio = (att: MediaAttachmentData) => isAudioAttachment(att);
24
25
 
25
26
  export function Attachments({ post }: AttachmentsProps) {
26
27
  const { enabled: staticRender } = useStaticRender();
@@ -55,6 +56,7 @@ export function Attachments({ post }: AttachmentsProps) {
55
56
  <div className="mt-2">
56
57
  <AudioAttachment
57
58
  src={inline.url}
59
+ previewUrl={inline.previewUrl ?? undefined}
58
60
  label={inline.filename ?? inline.description}
59
61
  size={inline.meta?.size}
60
62
  />
@@ -102,6 +104,15 @@ export function Attachments({ post }: AttachmentsProps) {
102
104
  />
103
105
  <VideoPlayOverlay video />
104
106
  </div>
107
+ ) : isAudio(att) && att.previewUrl ? (
108
+ <div className="relative h-full w-full">
109
+ <img
110
+ src={att.previewUrl}
111
+ alt={att.description ?? `attachment ${idx + 1}`}
112
+ className={mediaClass}
113
+ />
114
+ <VideoPlayOverlay video />
115
+ </div>
105
116
  ) : (
106
117
  <div className="text-muted-foreground flex min-h-24 w-full flex-col items-center justify-center gap-1 p-4 text-center text-xs">
107
118
  <span className="text-foreground break-all font-medium">
@@ -10,6 +10,8 @@ export const isAudioAttachment = (
10
10
 
11
11
  export interface AudioAttachmentProps {
12
12
  src?: string;
13
+ /** Waveform/thumbnail image rendered above the controls when available. */
14
+ previewUrl?: string;
13
15
  /** File name shown above the controls. */
14
16
  label?: string;
15
17
  /** Byte size, shown next to the file name when known. */
@@ -43,6 +45,7 @@ const formatBytes = (bytes?: number): string | undefined => {
43
45
 
44
46
  export const AudioAttachment = ({
45
47
  src,
48
+ previewUrl,
46
49
  label,
47
50
  size,
48
51
  reserveEnd = false,
@@ -122,6 +125,13 @@ export const AudioAttachment = ({
122
125
  onClick={(e) => e.stopPropagation()}
123
126
  >
124
127
  <div className={`flex flex-col gap-1.5 ${reserveEnd ? 'pr-12' : ''}`}>
128
+ {previewUrl ? (
129
+ <img
130
+ src={previewUrl}
131
+ alt=""
132
+ className="bg-muted h-40 w-full rounded-md object-cover"
133
+ />
134
+ ) : null}
125
135
  {label || fileSize ? (
126
136
  <div className="flex items-baseline justify-between gap-3">
127
137
  {label ? (
@@ -86,6 +86,7 @@ export function GalleryModal({
86
86
  <AudioAttachment
87
87
  key={attachment.url}
88
88
  src={attachment.url}
89
+ previewUrl={attachment.previewUrl ?? undefined}
89
90
  label={attachment.filename ?? attachment.description}
90
91
  size={attachment.meta?.size}
91
92
  className="w-full min-w-[280px] max-w-lg"
@@ -35,7 +35,7 @@ export function DeletePostModal({
35
35
 
36
36
  return (
37
37
  <Dialog open={open} onOpenChange={(next) => !next && onClose()}>
38
- <DialogContent className="max-w-lg overflow-x-hidden">
38
+ <DialogContent className="flex max-h-[90vh] max-w-lg flex-col overflow-x-hidden">
39
39
  <DialogHeader>
40
40
  <DialogTitle>
41
41
  {t('posts.deleteModal.deletePostTitle', {
@@ -43,14 +43,16 @@ export function DeletePostModal({
43
43
  })}
44
44
  </DialogTitle>
45
45
  </DialogHeader>
46
- <article className="min-w-0 overflow-x-hidden">
47
- <FeedPost post={post} noReactionHeader />
48
- <p className="my-4 text-sm">
49
- {t('posts.delete.confirm', {
50
- defaultValue: 'Are you sure you want to delete this post?',
51
- })}
52
- </p>
53
- </article>
46
+ <div className="min-h-0 flex-1 overflow-y-auto">
47
+ <article className="min-w-0 overflow-x-hidden">
48
+ <FeedPost post={post} noReactionHeader />
49
+ <p className="my-4 text-sm">
50
+ {t('posts.delete.confirm', {
51
+ defaultValue: 'Are you sure you want to delete this post?',
52
+ })}
53
+ </p>
54
+ </article>
55
+ </div>
54
56
  <DialogActions
55
57
  cancelLabel={t('posts.deleteModal.cancel', {
56
58
  defaultValue: 'Cancel',
@@ -1,10 +1,11 @@
1
1
  import { useState } from 'react';
2
+ import { Megaphone } from 'lucide-react';
2
3
  import type {
3
4
  Article,
4
5
  AudienceSetting,
5
6
  PostCreationData,
6
7
  } from '@openpeepshq/common/types';
7
- import { Input, Label } from '@openpeepshq/react-ui';
8
+ import { Input, Label, Switch } from '@openpeepshq/react-ui';
8
9
  import { useT } from '../../../i18n';
9
10
  import { useCurrentProfile } from '../../layout/IdentityContext';
10
11
  import { applyAudienceSetting } from '../../../lib/audienceSetting';
@@ -18,12 +19,18 @@ export interface ArticleFormProps {
18
19
  postData: PostCreationData;
19
20
  onChange: (data: PostCreationData) => void;
20
21
  isEdit?: boolean;
22
+ showNotify?: boolean;
23
+ notify?: boolean;
24
+ onNotifyChange?: (value: boolean) => void;
21
25
  }
22
26
 
23
27
  export function ArticleForm({
24
28
  postData,
25
29
  onChange,
26
30
  isEdit = false,
31
+ showNotify = false,
32
+ notify = false,
33
+ onNotifyChange,
27
34
  }: ArticleFormProps) {
28
35
  const t = useT();
29
36
  const me = useCurrentProfile();
@@ -100,6 +107,26 @@ export function ArticleForm({
100
107
  showDirect
101
108
  />
102
109
  </Label>
110
+
111
+ {showNotify ? (
112
+ <div className="flex w-full items-center justify-between">
113
+ <div className="flex items-center gap-2">
114
+ <Megaphone className="size-5" />
115
+ <p className="text-base">
116
+ {t('posts.form.notifyEveryone', {
117
+ defaultValue: 'Notify everyone',
118
+ })}
119
+ </p>
120
+ </div>
121
+ <Switch
122
+ checked={notify}
123
+ onCheckedChange={(checked) => onNotifyChange?.(checked)}
124
+ aria-label={t('posts.form.notifyEveryone', {
125
+ defaultValue: 'Notify everyone',
126
+ })}
127
+ />
128
+ </div>
129
+ ) : null}
103
130
  </div>
104
131
 
105
132
  {!isEdit ? (
@@ -1,5 +1,5 @@
1
1
  import { useState } from 'react';
2
- import { X } from 'lucide-react';
2
+ import { Megaphone, X } from 'lucide-react';
3
3
  import type {
4
4
  PostCreationData,
5
5
  RecurrenceFreq,
@@ -11,7 +11,7 @@ import {
11
11
  utcIsoToZonedDateTime,
12
12
  zonedDateTimeToUtcIso,
13
13
  } from '@openpeepshq/common/lib';
14
- import { Input, Label } from '@openpeepshq/react-ui';
14
+ import { Input, Label, Switch } from '@openpeepshq/react-ui';
15
15
  import { useT } from '../../../i18n';
16
16
  import {
17
17
  EVENT_WEEKDAYS,
@@ -30,6 +30,9 @@ export interface EventFormProps {
30
30
  onChange: (data: PostCreationData) => void;
31
31
  isEdit?: boolean;
32
32
  occurrenceEdit?: boolean;
33
+ showNotify?: boolean;
34
+ notify?: boolean;
35
+ onNotifyChange?: (value: boolean) => void;
33
36
  }
34
37
 
35
38
  const dateToInputValue = (value: string | undefined, timeZone: string) =>
@@ -48,6 +51,9 @@ export const EventForm = ({
48
51
  onChange,
49
52
  isEdit = false,
50
53
  occurrenceEdit = false,
54
+ showNotify = false,
55
+ notify = false,
56
+ onNotifyChange,
51
57
  }: EventFormProps) => {
52
58
  const t = useT();
53
59
  const [audienceOpen, setAudienceOpen] = useState(false);
@@ -402,6 +408,26 @@ export const EventForm = ({
402
408
  />
403
409
  </Label>
404
410
 
411
+ {showNotify ? (
412
+ <div className="flex w-full items-center justify-between">
413
+ <div className="flex items-center gap-2">
414
+ <Megaphone className="size-5" />
415
+ <p className="text-base">
416
+ {t('posts.form.notifyEveryone', {
417
+ defaultValue: 'Notify everyone',
418
+ })}
419
+ </p>
420
+ </div>
421
+ <Switch
422
+ checked={notify}
423
+ onCheckedChange={(checked) => onNotifyChange?.(checked)}
424
+ aria-label={t('posts.form.notifyEveryone', {
425
+ defaultValue: 'Notify everyone',
426
+ })}
427
+ />
428
+ </div>
429
+ ) : null}
430
+
405
431
  <Label
406
432
  description={t('events.form.attendeeListPublic', {
407
433
  defaultValue: 'Let an attendee see others attending this event',
@@ -7,7 +7,8 @@ import {
7
7
  Paperclip,
8
8
  } from 'lucide-react';
9
9
  import {
10
- checkRoleCapabilities,
10
+ canAnnouncePosts,
11
+ isCommunityWideVisibility,
11
12
  pollOptionsWithinLimit,
12
13
  resolvePollOptionContents,
13
14
  type GroupWithMeta,
@@ -135,7 +136,11 @@ export function NewPostModal({
135
136
 
136
137
  const selectComposerType = (next: ComposerType) => {
137
138
  if (next === composerType) return;
138
- setContent(draftContent(next));
139
+ const stored = draftContent(next);
140
+ // The note body and poll question share one field. When the destination
141
+ // has no stored draft, keep the current text so note -> poll carries the
142
+ // typed note over as the poll question instead of erasing it.
143
+ setContent(stored || content);
139
144
  setComposerType(next);
140
145
  };
141
146
 
@@ -190,12 +195,8 @@ export function NewPostModal({
190
195
  audience,
191
196
  ]);
192
197
 
193
- const canNotify = useMemo(
194
- () =>
195
- checkRoleCapabilities(me?.roles ?? [], ['allpeep-core-admin-notify'])
196
- .success,
197
- [me?.roles],
198
- );
198
+ const canNotify = useMemo(() => canAnnouncePosts(me?.roles), [me?.roles]);
199
+ const showNotify = canNotify && isCommunityWideVisibility(visibility);
199
200
 
200
201
  const selectedGroupName = useMemo(() => {
201
202
  if (!groupId) return undefined;
@@ -296,7 +297,7 @@ export function NewPostModal({
296
297
  }
297
298
 
298
299
  const response = await createPost(payload);
299
- if (notify && canNotify && response?.id) {
300
+ if (notify && showNotify && response?.id) {
300
301
  await announcePost({ id: response.id });
301
302
  }
302
303
  if (composerType === 'question') {
@@ -324,9 +325,6 @@ export function NewPostModal({
324
325
  }
325
326
  };
326
327
 
327
- const showNotify =
328
- canNotify && (visibility === 'public' || visibility === 'local');
329
-
330
328
  return (
331
329
  <>
332
330
  <Dialog open onOpenChange={(open) => !open && onClose()}>
@@ -1,4 +1,4 @@
1
- import { useMemo, useRef, useState } from 'react';
1
+ import { useLayoutEffect, useMemo, useRef, useState } from 'react';
2
2
  import type { PublicProfile } from '@openpeepshq/common/types';
3
3
  import {
4
4
  Button,
@@ -48,6 +48,13 @@ export function OpenpeepsMarkdownInput({
48
48
  const [open, setOpen] = useState(false);
49
49
  const [showPreview, setShowPreview] = useState(false);
50
50
  const textareaRef = useRef<HTMLTextAreaElement>(null);
51
+
52
+ // Preview is local state. Clearing the text after send has to leave an
53
+ // editable field, not the preview overlay.
54
+ useLayoutEffect(() => {
55
+ if (value.length === 0) setShowPreview(false);
56
+ }, [value]);
57
+
51
58
  const anchorRef = useRef<HTMLDivElement>(null);
52
59
 
53
60
  const profilesQuery = openpeepsApi.useSearchProfiles(query);
@@ -123,6 +123,7 @@ export const FullResource = ({ post }: FullResourceProps) => {
123
123
  preview={
124
124
  <AudioAttachment
125
125
  src={audioAtt.url}
126
+ previewUrl={audioAtt.previewUrl ?? undefined}
126
127
  label={audioAtt.filename ?? audioAtt.description}
127
128
  size={audioAtt.meta?.size}
128
129
  />
@@ -257,6 +257,14 @@ export const ResourceCard = ({
257
257
  attachmentMediaKind(att) === 'video' ||
258
258
  attachmentMediaKind(att) === 'audio',
259
259
  );
260
+ // File resources show their filename (with extension) so users can tell
261
+ // what they're about to download; other kinds show the size.
262
+ if (resource.resourceKind === 'file') {
263
+ const size = fileAtt?.meta?.size;
264
+ const filename = fileAtt?.filename;
265
+ if (filename && size) return `${filename} · ${formatSize(size)}`;
266
+ return filename ?? (size ? formatSize(size) : null);
267
+ }
260
268
  const size = fileAtt?.meta?.size;
261
269
  if (size) return formatSize(size);
262
270
  return null;
@@ -1,4 +1,8 @@
1
1
  import { useCallback, useEffect, useMemo, useState } from 'react';
2
+ import {
3
+ canAnnouncePosts,
4
+ isCommunityWideVisibility,
5
+ } from '@openpeepshq/common';
2
6
  import type {
3
7
  Event,
4
8
  PostCreationData,
@@ -12,6 +16,7 @@ import {
12
16
  import { useOpenpeeps } from '../../contexts/openpeeps';
13
17
  import { useNavigate } from '../../contexts/router';
14
18
  import { useT } from '../../i18n/context';
19
+ import { useCurrentProfile } from '../../components/layout/IdentityContext';
15
20
  import { useServerInfo } from '../../components/server-data/context';
16
21
  import { eventSanitizer, getNewPostStores } from '../../stores/newPosts';
17
22
 
@@ -19,8 +24,10 @@ export const useNewEvent = () => {
19
24
  const t = useT();
20
25
  const navigate = useNavigate();
21
26
  const serverInfo = useServerInfo();
27
+ const me = useCurrentProfile();
22
28
  const { openpeepsApi } = useOpenpeeps();
23
29
  const createPost = openpeepsApi.createPostAction();
30
+ const announcePost = openpeepsApi.admin.announcePostAction();
24
31
  const stores = getNewPostStores();
25
32
  const sanitize = useMemo(
26
33
  () => eventSanitizer(serverInfo.publicContent),
@@ -30,9 +37,14 @@ export const useNewEvent = () => {
30
37
  const [postData, setPostDataState] = useState<PostCreationData>(() =>
31
38
  sanitize(stores.event),
32
39
  );
40
+ const [notify, setNotify] = useState(false);
33
41
  const [submitting, setSubmitting] = useState(false);
34
42
  const [error, setError] = useState<string | null>(null);
35
43
 
44
+ const showNotify =
45
+ canAnnouncePosts(me?.roles) &&
46
+ isCommunityWideVisibility(postData.visibility);
47
+
36
48
  const event = postData.data.type === 'event' ? postData.data : null;
37
49
  const canSubmit =
38
50
  !!event?.start &&
@@ -73,6 +85,9 @@ export const useNewEvent = () => {
73
85
  type: 'event',
74
86
  data: normalizeEventDataForSave(event),
75
87
  });
88
+ if (notify && showNotify && created.id) {
89
+ await announcePost({ id: created.id });
90
+ }
76
91
  stores.resetNewEventState();
77
92
  navigate({ type: 'post', id: created.id });
78
93
  } catch (err) {
@@ -80,7 +95,17 @@ export const useNewEvent = () => {
80
95
  } finally {
81
96
  setSubmitting(false);
82
97
  }
83
- }, [createPost, event, navigate, postData, stores, t]);
98
+ }, [
99
+ announcePost,
100
+ createPost,
101
+ event,
102
+ navigate,
103
+ notify,
104
+ postData,
105
+ showNotify,
106
+ stores,
107
+ t,
108
+ ]);
84
109
 
85
110
  return {
86
111
  postData,
@@ -89,6 +114,9 @@ export const useNewEvent = () => {
89
114
  submitting,
90
115
  error,
91
116
  clearError: () => setError(null),
117
+ notify,
118
+ setNotify,
119
+ showNotify,
92
120
  submit,
93
121
  };
94
122
  };
@@ -1,4 +1,8 @@
1
1
  import { useCallback, useEffect, useState } from 'react';
2
+ import {
3
+ canAnnouncePosts,
4
+ isCommunityWideVisibility,
5
+ } from '@openpeepshq/common';
2
6
  import type {
3
7
  Article,
4
8
  PostCreationData,
@@ -7,6 +11,7 @@ import type {
7
11
  import { useOpenpeeps } from '../../contexts/openpeeps';
8
12
  import { useNavigate } from '../../contexts/router';
9
13
  import { useT } from '../../i18n/context';
14
+ import { useCurrentProfile } from '../../components/layout/IdentityContext';
10
15
  import { useServerInfo } from '../../components/server-data';
11
16
  import { defaultNewArticle, getNewPostStores } from '../../stores';
12
17
 
@@ -14,8 +19,10 @@ export const useNewArticle = () => {
14
19
  const t = useT();
15
20
  const navigate = useNavigate();
16
21
  const serverInfo = useServerInfo();
22
+ const me = useCurrentProfile();
17
23
  const { openpeepsApi } = useOpenpeeps();
18
24
  const createPost = openpeepsApi.createPostAction();
25
+ const announcePost = openpeepsApi.admin.announcePostAction();
19
26
  const stores = getNewPostStores();
20
27
 
21
28
  const [postData, setPostDataState] = useState<PostCreationData>(() => {
@@ -25,9 +32,14 @@ export const useNewArticle = () => {
25
32
  }
26
33
  return defaultNewArticle(serverInfo.publicContent);
27
34
  });
35
+ const [notify, setNotify] = useState(false);
28
36
  const [submitting, setSubmitting] = useState(false);
29
37
  const [error, setError] = useState<string | null>(null);
30
38
 
39
+ const showNotify =
40
+ canAnnouncePosts(me?.roles) &&
41
+ isCommunityWideVisibility(postData.visibility);
42
+
31
43
  const article = postData.data.type === 'article' ? postData.data : null;
32
44
  const canSubmit =
33
45
  !!article?.title?.trim() &&
@@ -55,6 +67,9 @@ export const useNewArticle = () => {
55
67
  setSubmitting(true);
56
68
  try {
57
69
  const created = await createPost({ ...postData, type: 'article' });
70
+ if (notify && showNotify && created.id) {
71
+ await announcePost({ id: created.id });
72
+ }
58
73
  stores.resetNewArticleState();
59
74
  navigate({ type: 'post', id: created.id });
60
75
  } catch (err) {
@@ -62,7 +77,17 @@ export const useNewArticle = () => {
62
77
  } finally {
63
78
  setSubmitting(false);
64
79
  }
65
- }, [article, createPost, navigate, postData, stores, t]);
80
+ }, [
81
+ announcePost,
82
+ article,
83
+ createPost,
84
+ navigate,
85
+ notify,
86
+ postData,
87
+ showNotify,
88
+ stores,
89
+ t,
90
+ ]);
66
91
 
67
92
  return {
68
93
  postData,
@@ -71,6 +96,9 @@ export const useNewArticle = () => {
71
96
  submitting,
72
97
  error,
73
98
  clearError: () => setError(null),
99
+ notify,
100
+ setNotify,
101
+ showNotify,
74
102
  submit,
75
103
  };
76
104
  };
@@ -13,6 +13,9 @@ export function NewArticle() {
13
13
  submitting,
14
14
  error,
15
15
  clearError,
16
+ notify,
17
+ setNotify,
18
+ showNotify,
16
19
  submit,
17
20
  } = useNewArticle();
18
21
 
@@ -39,7 +42,13 @@ export function NewArticle() {
39
42
 
40
43
  return (
41
44
  <div className="pb-12">
42
- <ArticleForm postData={postData} onChange={setPostData} />
45
+ <ArticleForm
46
+ postData={postData}
47
+ onChange={setPostData}
48
+ showNotify={showNotify}
49
+ notify={notify}
50
+ onNotifyChange={setNotify}
51
+ />
43
52
 
44
53
  {error ? (
45
54
  <div className="px-3">
@@ -13,6 +13,9 @@ export function NewEvent() {
13
13
  submitting,
14
14
  error,
15
15
  clearError,
16
+ notify,
17
+ setNotify,
18
+ showNotify,
16
19
  submit,
17
20
  } = useNewEvent();
18
21
 
@@ -40,7 +43,13 @@ export function NewEvent() {
40
43
 
41
44
  return (
42
45
  <div className="pb-12">
43
- <EventForm postData={postData} onChange={setPostData} />
46
+ <EventForm
47
+ postData={postData}
48
+ onChange={setPostData}
49
+ showNotify={showNotify}
50
+ notify={notify}
51
+ onNotifyChange={setNotify}
52
+ />
44
53
 
45
54
  {error ? (
46
55
  <div className="px-3">
@@ -48,7 +48,7 @@ export function GroupsIndex() {
48
48
  () =>
49
49
  canCreate
50
50
  ? {
51
- title: t('groups.new', { defaultValue: 'New Group' }),
51
+ title: t('groups.new.label', { defaultValue: 'New Group' }),
52
52
  icon: Plus,
53
53
  action: '/groups/new',
54
54
  }