@openpeepshq/react 0.2.4 → 0.2.5

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.
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { cn } from '@openpeepshq/react-ui';
3
3
  import { usePostViewRef } from '../../lib/postViewCounter.js';
4
- import { isUnreadPostForViewer } from '../../lib/postUnread.js';
4
+ import { isUnreadFeedActivityForViewer } from '../../lib/postUnread.js';
5
5
  import { useCurrentProfile } from '../layout/IdentityContext.js';
6
6
  import { FeedPostContent } from './FeedPostContent.js';
7
7
  import { PostInfoHeader } from './pieces/PostInfoHeader.js';
@@ -18,9 +18,9 @@ import { UnreadPostIndicator } from './pieces/UnreadPostIndicator.js';
18
18
  export function FeedPost({ post, deleteCallback, noReactionHeader = false, inGroup = false, showReplyTo = false, content, className, }) {
19
19
  const me = useCurrentProfile();
20
20
  const displayedPost = post.repost ?? post;
21
- const isUnread = isUnreadPostForViewer(displayedPost, me?.id);
22
- const postViewRef = usePostViewRef(displayedPost.id, {
23
- groupId: displayedPost.groupId,
21
+ const isUnread = isUnreadFeedActivityForViewer(post, me?.id);
22
+ const postViewRef = usePostViewRef(post.id, {
23
+ groupId: post.groupId,
24
24
  adjustUnread: isUnread,
25
25
  });
26
26
  const hasReactionHeader = !noReactionHeader &&
@@ -13,7 +13,7 @@ export function FeedPostStats({ post }) {
13
13
  e.stopPropagation();
14
14
  handler();
15
15
  };
16
- return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex justify-between pb-2 text-xs text-muted-foreground", children: [_jsx("div", { children: post?.reactions?.length ? (_jsx("button", { type: "button", title: t('posts.stats.viewReactions', {
16
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "text-muted-foreground flex justify-between pb-2 text-xs", children: [_jsx("div", { children: post?.reactions?.length ? (_jsx("button", { type: "button", title: t('posts.stats.viewReactions', {
17
17
  defaultValue: 'View reactions',
18
18
  }), className: "hover:underline", onClick: stop(() => setModal('reactions')), children: stats })) : null }), _jsxs("div", { className: "flex w-fit items-center gap-1", children: [post?.replyCount ? (_jsx("span", { children: t('posts.stats.repliesCount', {
19
19
  defaultValue: `${post.replyCount} replies`,
@@ -23,5 +23,5 @@ export function FeedPostStats({ post }) {
23
23
  }), className: "hover:underline", onClick: stop(() => setModal('reposts')), children: t('posts.stats.repostsCount', {
24
24
  defaultValue: `${post.repostCount} reposts`,
25
25
  count: post.repostCount,
26
- }) })) : null] })] }), _jsx(ReactionsModal, { reactions: post.reactions ?? [], open: modal === 'reactions', onClose: () => setModal(null) }), _jsx(RepostModal, { post: post, open: modal === 'reposts', onClose: () => setModal(null) })] }));
26
+ }) })) : null] })] }), _jsx(ReactionsModal, { reactions: post.reactions ?? [], open: modal === 'reactions', onClose: () => setModal(null) }), _jsx(RepostModal, { reposts: post.reposts ?? [], repostCount: post.repostCount ?? 0, open: modal === 'reposts', onClose: () => setModal(null) })] }));
27
27
  }
@@ -22,7 +22,7 @@ import { useAuthData, useCurrentProfile } from '../../layout/IdentityContext.js'
22
22
  import { useToast } from '../../layout/ToastProvider.js';
23
23
  import { useCapabilities } from '../../server-data/index.js';
24
24
  import { Avatar } from '../../profile/index.js';
25
- import { Button } from '@openpeepshq/react-ui';
25
+ import { Button, cn } from '@openpeepshq/react-ui';
26
26
  export function PollContent({ post }) {
27
27
  const t = useT();
28
28
  const { openpeepsApi } = useOpenpeeps();
@@ -38,9 +38,10 @@ export function PollContent({ post }) {
38
38
  const pollData = post.data;
39
39
  const { votes, voteCounts } = collectVotes(post);
40
40
  const hasPollEnded = !!(pollData.expiresAt && isPast(pollData.expiresAt));
41
- const hasVoted = !!(currentProfile &&
42
- (votes.find((v) => v?.profile?.id === currentProfile.id)?.selection
43
- ?.length ?? 0) > 0);
41
+ const ownSelection = currentProfile
42
+ ? (votes.find((v) => v?.profile?.id === currentProfile.id)?.selection ?? [])
43
+ : [];
44
+ const hasVoted = ownSelection.length > 0;
44
45
  const canVote = !!(currentProfile && !hasPollEnded && !hasVoted);
45
46
  const totalVotes = votes.length || 1;
46
47
  const handleVote = async () => {
@@ -90,18 +91,36 @@ export function PollContent({ post }) {
90
91
  }));
91
92
  }
92
93
  };
94
+ // The feed wraps each post in a link, so clicks inside the poll must not
95
+ // reach it. Clicks on the option controls are exempt: cancelling those
96
+ // reverts the checkbox/radio the browser just ticked, so a pending selection
97
+ // would never show. They are their own activation target, so the surrounding
98
+ // link does not navigate. Key events only stop propagation for the same
99
+ // reason — cancelling them swallows keyboard activation.
93
100
  const stopFeedNavigation = (e) => {
94
- e.preventDefault();
101
+ const target = e.target;
102
+ if (!target?.closest('input,label'))
103
+ e.preventDefault();
95
104
  e.stopPropagation();
96
105
  };
97
- return (_jsxs("div", { className: "bg-surface rounded-lg px-4 py-4", onClick: stopFeedNavigation, onKeyDown: stopFeedNavigation, role: "presentation", children: [_jsx("div", { className: "space-y-4", children: pollData.options.map((option, index) => (_jsxs("div", { className: "flex items-center gap-2 py-2", children: [canVote ? (pollData.multiple ? (_jsx("input", { type: "checkbox", checked: selectedPollOptions.includes(index), onChange: () => setSelectedPollOptions((prev) => prev.includes(index)
98
- ? prev.filter((i) => i !== index)
99
- : [...prev, index]) })) : (_jsx("input", { type: "radio", name: `poll-${post.id}`, checked: selectedPollOption === index, onChange: () => setSelectedPollOption(index) }))) : null, _jsxs("div", { className: "flex-1", children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx("span", { className: "text-base", children: option.content }), _jsxs("div", { className: "flex items-center gap-2", children: [pollData.votersVisible ? (_jsx("div", { className: "flex -space-x-2", children: votes
100
- .filter((v) => v.selection.includes(index))
101
- .slice(0, 2)
102
- .map((vote) => (_jsx(Avatar, { profile: vote.profile, size: 1.5 }, vote.profile.id))) })) : null, _jsx("span", { children: voteCounts?.[index] ?? 0 })] })] }), _jsx("div", { className: "bg-surface mt-2 h-2 overflow-hidden rounded-full", children: _jsx("div", { className: "bg-primary h-full rounded-full transition-all", style: {
103
- width: `${((voteCounts[index] ?? 0) / totalVotes) * 100}%`,
104
- } }) })] })] }, `${option.content}-${index}`))) }), canVote ? (_jsx(Button, { variant: "default", className: "mt-4", title: t('posts.poll.vote', { defaultValue: 'Vote' }), action: handleVote, children: t('posts.form.poll.submit', { defaultValue: 'Vote' }) })) : null, _jsxs("div", { className: "text-muted-foreground mt-4 flex flex-wrap items-center gap-3 text-sm", children: [_jsxs("span", { children: [votes.length || 0, " ", t('posts.vote.count', { defaultValue: 'votes' })] }), pollData.expiresAt ? (_jsx("span", { children: hasPollEnded
106
+ return (_jsxs("div", { className: "bg-surface rounded-lg px-4 py-4", onClick: stopFeedNavigation, onKeyDown: (e) => e.stopPropagation(), role: "presentation", children: [_jsx("div", { className: "space-y-4", children: pollData.options.map((option, index) => {
107
+ const optionId = `poll-${post.id}-option-${index}`;
108
+ const isOwnChoice = ownSelection.includes(index);
109
+ // Kept visible (checked, disabled) once the viewer has voted so their
110
+ // own selection stays readable while the results show.
111
+ const hasControl = canVote || hasVoted;
112
+ const labelClass = cn('text-base', isOwnChoice && 'font-medium', canVote && 'cursor-pointer');
113
+ return (_jsxs("div", { className: "flex items-center gap-2 py-2", children: [hasControl ? (pollData.multiple ? (_jsx("input", { type: "checkbox", id: optionId, disabled: !canVote, checked: canVote
114
+ ? selectedPollOptions.includes(index)
115
+ : isOwnChoice, onChange: () => setSelectedPollOptions((prev) => prev.includes(index)
116
+ ? prev.filter((i) => i !== index)
117
+ : [...prev, index]) })) : (_jsx("input", { type: "radio", id: optionId, name: `poll-${post.id}`, disabled: !canVote, checked: canVote ? selectedPollOption === index : isOwnChoice, onChange: () => setSelectedPollOption(index) }))) : null, _jsxs("div", { className: "flex-1", children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [hasControl ? (_jsx("label", { htmlFor: optionId, className: labelClass, children: option.content })) : (_jsx("span", { className: labelClass, children: option.content })), _jsxs("div", { className: "flex items-center gap-2", children: [pollData.votersVisible ? (_jsx("div", { className: "flex -space-x-2", children: votes
118
+ .filter((v) => v.selection.includes(index))
119
+ .slice(0, 2)
120
+ .map((vote) => (_jsx(Avatar, { profile: vote.profile, size: 1.5 }, vote.profile.id))) })) : null, _jsx("span", { children: voteCounts?.[index] ?? 0 })] })] }), _jsx("div", { className: "bg-surface mt-2 h-2 overflow-hidden rounded-full", children: _jsx("div", { className: "bg-primary h-full rounded-full transition-all", style: {
121
+ width: `${((voteCounts[index] ?? 0) / totalVotes) * 100}%`,
122
+ } }) })] })] }, `${option.content}-${index}`));
123
+ }) }), canVote ? (_jsx(Button, { variant: "default", className: "mt-4", title: t('posts.poll.vote', { defaultValue: 'Vote' }), action: handleVote, children: t('posts.form.poll.submit', { defaultValue: 'Vote' }) })) : null, _jsxs("div", { className: "text-muted-foreground mt-4 flex flex-wrap items-center gap-3 text-sm", children: [_jsxs("span", { children: [votes.length || 0, " ", t('posts.vote.count', { defaultValue: 'votes' })] }), pollData.expiresAt ? (_jsx("span", { children: hasPollEnded
105
124
  ? t('posts.poll.ended', { defaultValue: 'Poll ended' })
106
125
  : `${formatDistanceToNow(pollData.expiresAt)} ${t('posts.poll.timeLeft', { defaultValue: 'left' })}` })) : null, hasVoted && !hasPollEnded ? (_jsx(Button, { variant: "ghost", className: "h-auto min-h-0 px-0 font-semibold", title: t('posts.poll.undoVoteTitle', {
107
126
  defaultValue: 'Undo your vote',
@@ -99,5 +99,5 @@ export function PostMenu({ post, deleteCallback }) {
99
99
  }), text: t('common.actions.reportProfile', {
100
100
  defaultValue: 'Report @{{handle}}',
101
101
  handle: post.profile.handle,
102
- }), icon: FlagIcon, danger: true, action: () => setModal('reportProfile') })] })) : null] }), _jsx(ReactionsModal, { reactions: post.reactions ?? [], open: modal === 'reactions', onClose: () => setModal(null) }), _jsx(RepostModal, { post: post, open: modal === 'reposts', onClose: () => setModal(null) }), _jsx(DeletePostModal, { post: post, open: modal === 'delete', onClose: () => setModal(null), deleteCallback: deleteCallback }), _jsx(ReportProfileOrPostModal, { reportType: "post", post: post, open: modal === 'reportPost', onClose: () => setModal(null) }), _jsx(ReportProfileOrPostModal, { reportType: "profile", profile: post.profile, open: modal === 'reportProfile', onClose: () => setModal(null) })] }));
102
+ }), icon: FlagIcon, danger: true, action: () => setModal('reportProfile') })] })) : null] }), _jsx(ReactionsModal, { reactions: post.reactions ?? [], open: modal === 'reactions', onClose: () => setModal(null) }), _jsx(RepostModal, { reposts: post.reposts ?? [], repostCount: post.repostCount ?? 0, open: modal === 'reposts', onClose: () => setModal(null) }), _jsx(DeletePostModal, { post: post, open: modal === 'delete', onClose: () => setModal(null), deleteCallback: deleteCallback }), _jsx(ReportProfileOrPostModal, { reportType: "post", post: post, open: modal === 'reportPost', onClose: () => setModal(null) }), _jsx(ReportProfileOrPostModal, { reportType: "profile", profile: post.profile, open: modal === 'reportProfile', onClose: () => setModal(null) })] }));
103
103
  }
@@ -1,7 +1,9 @@
1
- import type { PublicPost } from '@openpeepshq/common/types';
1
+ import type { RepostWithPublicProfile } from '@openpeepshq/common/types';
2
2
  export interface RepostModalProps {
3
- post: PublicPost;
3
+ reposts: RepostWithPublicProfile[];
4
+ /** Authoritative total; may exceed `reposts.length` when the list is capped. */
5
+ repostCount: number;
4
6
  open: boolean;
5
7
  onClose: () => void;
6
8
  }
7
- export declare function RepostModal({ post, open, onClose }: RepostModalProps): import("react/jsx-runtime").JSX.Element;
9
+ export declare function RepostModal({ reposts, repostCount, open, onClose, }: RepostModalProps): import("react/jsx-runtime").JSX.Element;
@@ -1,13 +1,14 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Dialog, DialogContent, DialogHeader, DialogTitle, LoadingSpinner, } from '@openpeepshq/react-ui';
3
- import { useOpenpeeps } from '../../../../contexts/openpeeps/index.js';
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Dialog, DialogContent, DialogHeader, DialogTitle, } from '@openpeepshq/react-ui';
4
3
  import { useT } from '../../../../i18n/index.js';
5
4
  import { ProfileWithActionCard } from '../../../profile/ProfileWithActionCard.js';
6
- export function RepostModal({ post, open, onClose }) {
5
+ export function RepostModal({ reposts, repostCount, open, onClose, }) {
7
6
  const t = useT();
8
- const { openpeepsApi } = useOpenpeeps();
9
- const repostsQuery = openpeepsApi.usePostReposts(post.id);
10
- return (_jsx(Dialog, { open: open, onOpenChange: (next) => !next && onClose(), children: _jsxs(DialogContent, { className: "max-h-[80vh] max-w-md overflow-y-auto", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: t('posts.repostModal.title', { defaultValue: 'Reposters' }) }) }), _jsx("article", { className: "pb-3", children: repostsQuery.isLoading ? (_jsx("div", { className: "p-5 text-center text-sm text-muted-foreground", children: _jsx(LoadingSpinner, {}) })) : repostsQuery.data?.length ? (repostsQuery.data.map((repost) => (_jsx(ProfileWithActionCard, { profile: repost.profile }, repost.profile.id)))) : (_jsx("p", { className: "p-5 text-center text-sm text-muted-foreground", children: t('posts.repostModal.empty', {
7
+ const moreCount = Math.max(0, repostCount - reposts.length);
8
+ return (_jsx(Dialog, { open: open, onOpenChange: (next) => !next && onClose(), children: _jsxs(DialogContent, { className: "max-h-[80vh] max-w-md overflow-y-auto", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: t('posts.repostModal.title', { defaultValue: 'Reposters' }) }) }), _jsx("article", { className: "pb-3", children: reposts.length ? (_jsxs(_Fragment, { children: [reposts.map((repost) => (_jsx(ProfileWithActionCard, { profile: repost.profile }, repost.profile.id))), moreCount > 0 ? (_jsx("p", { className: "text-muted-foreground px-5 pt-2 text-center text-sm", children: t('posts.repostModal.andMore', {
9
+ defaultValue: 'and {{count}} more',
10
+ count: moreCount,
11
+ }) })) : null] })) : (_jsx("p", { className: "text-muted-foreground p-5 text-center text-sm", children: t('posts.repostModal.empty', {
11
12
  defaultValue: 'No reposters yet',
12
13
  }) })) })] }) }));
13
14
  }