@openpeepshq/react 0.8.6 → 0.9.1
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.
- package/dist/components/conversations/DirectMessageSearch.d.ts +7 -0
- package/dist/components/conversations/DirectMessageSearch.js +46 -0
- package/dist/components/conversations/MessageInThread.d.ts +2 -1
- package/dist/components/conversations/MessageInThread.js +3 -3
- package/dist/components/conversations/index.d.ts +1 -0
- package/dist/components/conversations/index.js +1 -0
- package/dist/components/post/post-form/ReplyModal.js +5 -4
- package/dist/contexts/openpeeps/hooks/conversations.d.ts +3 -2
- package/dist/contexts/openpeeps/hooks/conversations.js +8 -1
- package/dist/hooks/events/useEventComposer.d.ts +1 -0
- package/dist/hooks/events/useEventComposer.js +8 -4
- package/dist/pages/admin/ConfigurationCommunity.js +1 -1
- package/dist/pages/admin/community/CommunityAccess.d.ts +6 -0
- package/dist/pages/admin/community/CommunityAccess.js +60 -0
- package/dist/pages/conversations/Index.js +17 -11
- package/dist/pages/conversations/Show.js +67 -15
- package/dist/pages/events/New.js +15 -4
- package/dist/pages/events/New.test.d.ts +1 -0
- package/dist/pages/events/New.test.js +69 -0
- package/dist/pages/index.d.ts +1 -0
- package/dist/pages/index.js +1 -0
- package/dist/pages/resources/Index.js +2 -2
- package/package.json +5 -5
- package/src/components/conversations/DirectMessageSearch.tsx +130 -0
- package/src/components/conversations/MessageInThread.tsx +9 -2
- package/src/components/conversations/index.ts +1 -0
- package/src/components/post/post-form/ReplyModal.tsx +9 -4
- package/src/contexts/openpeeps/hooks/conversations.ts +16 -3
- package/src/hooks/events/useEventComposer.ts +12 -3
- package/src/pages/admin/ConfigurationCommunity.tsx +4 -0
- package/src/pages/admin/community/CommunityAccess.tsx +129 -0
- package/src/pages/conversations/Index.tsx +51 -32
- package/src/pages/conversations/Show.tsx +106 -22
- package/src/pages/events/New.tsx +28 -5
- package/src/pages/index.ts +1 -0
- package/src/pages/resources/Index.tsx +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import { useParams } from 'react-router-dom';
|
|
3
|
-
import type { PostCreationData } from '@openpeepshq/common/types';
|
|
4
|
-
import { Info } from 'lucide-react';
|
|
2
|
+
import { useParams, useSearchParams } from 'react-router-dom';
|
|
3
|
+
import type { PostCreationData, PublicPost } from '@openpeepshq/common/types';
|
|
4
|
+
import { Info, Search } from 'lucide-react';
|
|
5
5
|
import {
|
|
6
6
|
useT,
|
|
7
7
|
useOpenpeeps,
|
|
@@ -14,6 +14,7 @@ import { canCreatePost } from '@openpeepshq/common';
|
|
|
14
14
|
import {
|
|
15
15
|
Avatar,
|
|
16
16
|
ConversationParticipantsModal,
|
|
17
|
+
DirectMessageSearch,
|
|
17
18
|
MessageInThread,
|
|
18
19
|
OpenpeepsMarkdownInput,
|
|
19
20
|
ProfileCard,
|
|
@@ -21,25 +22,48 @@ import {
|
|
|
21
22
|
useCurrentProfile,
|
|
22
23
|
useToast,
|
|
23
24
|
} from '../../components';
|
|
25
|
+
import { apiErrorMessage } from '../../lib/apiErrorMessage';
|
|
24
26
|
import { Button, LoadingSpinner } from '@openpeepshq/react-ui';
|
|
25
27
|
|
|
26
28
|
const MAX_LENGTH = 500;
|
|
27
29
|
|
|
30
|
+
const isMessageId = (value: string | null): value is string =>
|
|
31
|
+
!!value &&
|
|
32
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
33
|
+
|
|
28
34
|
export function ConversationShow() {
|
|
29
35
|
const t = useT();
|
|
30
36
|
const { id = '' } = useParams<{ id: string }>();
|
|
37
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
38
|
+
const messageParam = searchParams.get('message');
|
|
39
|
+
const focusId = isMessageId(messageParam) ? messageParam : undefined;
|
|
31
40
|
const { openpeepsApi, queryClient, client } = useOpenpeeps();
|
|
32
41
|
const me = useCurrentProfile();
|
|
33
42
|
const authData = useAuthData();
|
|
34
43
|
const toast = useToast();
|
|
35
44
|
const endRef = useRef<HTMLDivElement | null>(null);
|
|
36
45
|
|
|
37
|
-
const conversationQuery = openpeepsApi.useConversation(id);
|
|
46
|
+
const conversationQuery = openpeepsApi.useConversation(id, focusId);
|
|
38
47
|
const createMessage = openpeepsApi.createConversationPostAction({ id });
|
|
39
48
|
const markPostsSeen = openpeepsApi.markPostsSeenAction();
|
|
40
49
|
const flushPostViews = usePostViewFlush();
|
|
41
50
|
|
|
42
|
-
|
|
51
|
+
// Keep the open thread visible while a search hit refetches an older
|
|
52
|
+
// message. Switching conversations clears it so the previous thread
|
|
53
|
+
// does not linger.
|
|
54
|
+
const [shownMessages, setShownMessages] = useState<PublicPost[]>([]);
|
|
55
|
+
const [shownFor, setShownFor] = useState(id);
|
|
56
|
+
const [searchOpen, setSearchOpen] = useState(false);
|
|
57
|
+
if (shownFor !== id) {
|
|
58
|
+
setShownFor(id);
|
|
59
|
+
setShownMessages([]);
|
|
60
|
+
setSearchOpen(false);
|
|
61
|
+
}
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (conversationQuery.data) setShownMessages(conversationQuery.data);
|
|
64
|
+
}, [conversationQuery.data]);
|
|
65
|
+
|
|
66
|
+
const messages = shownMessages;
|
|
43
67
|
const lastMessage = messages[messages.length - 1];
|
|
44
68
|
const participants =
|
|
45
69
|
lastMessage?.audience?.filter((a) => a.id !== me?.id) ?? [];
|
|
@@ -77,20 +101,44 @@ export function ConversationShow() {
|
|
|
77
101
|
|
|
78
102
|
const navigate = useNavigate();
|
|
79
103
|
|
|
104
|
+
const searchLabel = searchOpen
|
|
105
|
+
? t('common.close', { defaultValue: 'Close' })
|
|
106
|
+
: t('conversations.search.toggle', {
|
|
107
|
+
defaultValue: 'Search this conversation',
|
|
108
|
+
});
|
|
109
|
+
|
|
80
110
|
const headerActions = useMemo(
|
|
81
111
|
() => (
|
|
82
|
-
<
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
112
|
+
<div className="flex items-center">
|
|
113
|
+
<button
|
|
114
|
+
type="button"
|
|
115
|
+
onClick={() => setSearchOpen((open) => !open)}
|
|
116
|
+
title={searchLabel}
|
|
117
|
+
aria-label={searchLabel}
|
|
118
|
+
aria-expanded={searchOpen}
|
|
119
|
+
aria-controls={searchOpen ? 'conversation-message-search' : undefined}
|
|
120
|
+
data-testid="conversation-search-toggle"
|
|
121
|
+
className={`rounded-md p-1.5 ${
|
|
122
|
+
searchOpen
|
|
123
|
+
? 'bg-muted text-foreground'
|
|
124
|
+
: 'text-muted-foreground hover:text-foreground'
|
|
125
|
+
}`}
|
|
126
|
+
>
|
|
127
|
+
<Search size={18} />
|
|
128
|
+
</button>
|
|
129
|
+
<button
|
|
130
|
+
type="button"
|
|
131
|
+
onClick={() => navigate({ type: 'conversation', id, view: 'info' })}
|
|
132
|
+
title={t('conversations.info.title', {
|
|
133
|
+
defaultValue: 'Conversation info',
|
|
134
|
+
})}
|
|
135
|
+
className="text-muted-foreground hover:text-foreground rounded-md p-1.5"
|
|
136
|
+
>
|
|
137
|
+
<Info size={18} />
|
|
138
|
+
</button>
|
|
139
|
+
</div>
|
|
92
140
|
),
|
|
93
|
-
[id, navigate, t],
|
|
141
|
+
[id, navigate, searchLabel, searchOpen, t],
|
|
94
142
|
);
|
|
95
143
|
|
|
96
144
|
useSetPageHeader(headerTitle, headerActions);
|
|
@@ -115,11 +163,15 @@ export function ConversationShow() {
|
|
|
115
163
|
queryKey: client.conversations.list.queryKey({}),
|
|
116
164
|
refetchType: 'all',
|
|
117
165
|
});
|
|
118
|
-
} catch {
|
|
166
|
+
} catch (err) {
|
|
119
167
|
toast.error(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
168
|
+
apiErrorMessage(
|
|
169
|
+
err,
|
|
170
|
+
t,
|
|
171
|
+
t('conversations.sendError', {
|
|
172
|
+
defaultValue: 'Failed to send message',
|
|
173
|
+
}),
|
|
174
|
+
),
|
|
123
175
|
);
|
|
124
176
|
} finally {
|
|
125
177
|
setSending(false);
|
|
@@ -127,8 +179,25 @@ export function ConversationShow() {
|
|
|
127
179
|
};
|
|
128
180
|
|
|
129
181
|
useEffect(() => {
|
|
182
|
+
if (focusId) return;
|
|
130
183
|
endRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
131
|
-
}, [messages.length]);
|
|
184
|
+
}, [messages.length, focusId]);
|
|
185
|
+
|
|
186
|
+
// The ?message= param sticks around after focusing, so scroll only the
|
|
187
|
+
// first time the message renders — re-scrolling on every messages change
|
|
188
|
+
// would fight the user while they read.
|
|
189
|
+
const scrolledToMessageRef = useRef<string | null>(null);
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
if (!focusId) {
|
|
192
|
+
scrolledToMessageRef.current = null;
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (scrolledToMessageRef.current === focusId) return;
|
|
196
|
+
const element = document.querySelector(`[data-message-id="${focusId}"]`);
|
|
197
|
+
if (!element) return;
|
|
198
|
+
scrolledToMessageRef.current = focusId;
|
|
199
|
+
element.scrollIntoView({ block: 'center' });
|
|
200
|
+
}, [focusId, messages]);
|
|
132
201
|
|
|
133
202
|
useEffect(() => {
|
|
134
203
|
if (!id) return;
|
|
@@ -159,7 +228,7 @@ export function ConversationShow() {
|
|
|
159
228
|
void markPostsSeen({ postIds: unseenIds });
|
|
160
229
|
}, [id, me, messages, conversationQuery.isLoading, markPostsSeen]);
|
|
161
230
|
|
|
162
|
-
if (conversationQuery.isLoading) {
|
|
231
|
+
if (conversationQuery.isLoading && messages.length === 0) {
|
|
163
232
|
return (
|
|
164
233
|
<div className="text-muted-foreground flex h-32 items-center justify-center text-sm">
|
|
165
234
|
<LoadingSpinner />
|
|
@@ -198,6 +267,20 @@ export function ConversationShow() {
|
|
|
198
267
|
onOpenChange={setParticipantsOpen}
|
|
199
268
|
participants={participants}
|
|
200
269
|
/>
|
|
270
|
+
{searchOpen ? (
|
|
271
|
+
<div id="conversation-message-search">
|
|
272
|
+
<DirectMessageSearch
|
|
273
|
+
conversationId={id}
|
|
274
|
+
autoFocus
|
|
275
|
+
onSelect={(hit) => {
|
|
276
|
+
const next = new URLSearchParams(searchParams);
|
|
277
|
+
next.set('message', hit.message.id);
|
|
278
|
+
setSearchParams(next);
|
|
279
|
+
setSearchOpen(false);
|
|
280
|
+
}}
|
|
281
|
+
/>
|
|
282
|
+
</div>
|
|
283
|
+
) : null}
|
|
201
284
|
|
|
202
285
|
<div
|
|
203
286
|
role="log"
|
|
@@ -214,6 +297,7 @@ export function ConversationShow() {
|
|
|
214
297
|
message={m}
|
|
215
298
|
multipleParticipants={multipleParticipants}
|
|
216
299
|
conversationRootId={id}
|
|
300
|
+
highlighted={m.id === focusId}
|
|
217
301
|
/>
|
|
218
302
|
))}
|
|
219
303
|
<div ref={endRef} />
|
package/src/pages/events/New.tsx
CHANGED
|
@@ -9,6 +9,7 @@ export function NewEvent() {
|
|
|
9
9
|
const {
|
|
10
10
|
postData,
|
|
11
11
|
setPostData,
|
|
12
|
+
canCreate,
|
|
12
13
|
canSubmit,
|
|
13
14
|
submitting,
|
|
14
15
|
error,
|
|
@@ -19,8 +20,9 @@ export function NewEvent() {
|
|
|
19
20
|
submit,
|
|
20
21
|
} = useNewEvent();
|
|
21
22
|
|
|
22
|
-
const headerActions = useMemo(
|
|
23
|
-
()
|
|
23
|
+
const headerActions = useMemo(() => {
|
|
24
|
+
if (!canCreate) return null;
|
|
25
|
+
return (
|
|
24
26
|
<Button
|
|
25
27
|
title={t('events.create.title', { defaultValue: 'Create Event' })}
|
|
26
28
|
variant="default"
|
|
@@ -32,15 +34,36 @@ export function NewEvent() {
|
|
|
32
34
|
? t('common.submitting', { defaultValue: 'Creating…' })
|
|
33
35
|
: t('events.create.title', { defaultValue: 'Create Event' })}
|
|
34
36
|
</Button>
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
);
|
|
37
|
+
);
|
|
38
|
+
}, [canCreate, canSubmit, submit, submitting, t]);
|
|
38
39
|
|
|
39
40
|
useSetPageHeader(
|
|
40
41
|
t('events.create.title', { defaultValue: 'Create Event' }),
|
|
41
42
|
headerActions,
|
|
42
43
|
);
|
|
43
44
|
|
|
45
|
+
if (!canCreate) {
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
className="mx-auto flex max-w-md flex-col gap-2 px-6 py-16 text-center"
|
|
49
|
+
data-testid="events-create-not-allowed"
|
|
50
|
+
role="status"
|
|
51
|
+
>
|
|
52
|
+
<p className="text-xl font-semibold">
|
|
53
|
+
{t('events.create.notAllowed.title', {
|
|
54
|
+
defaultValue: "You can't create events",
|
|
55
|
+
})}
|
|
56
|
+
</p>
|
|
57
|
+
<p className="text-muted-foreground text-sm">
|
|
58
|
+
{t('events.create.notAllowed.description', {
|
|
59
|
+
defaultValue:
|
|
60
|
+
"Your role isn't allowed to create events. Ask a community owner or moderator if you need to host one.",
|
|
61
|
+
})}
|
|
62
|
+
</p>
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
44
67
|
return (
|
|
45
68
|
<div className="pb-12">
|
|
46
69
|
<EventForm
|
package/src/pages/index.ts
CHANGED
|
@@ -77,6 +77,7 @@ export { ConfigurationPluginPage } from './admin/ConfigurationPluginPage';
|
|
|
77
77
|
export { AdminConfigurationCommunity } from './admin/ConfigurationCommunity';
|
|
78
78
|
export { AdminConfigEditor } from './admin/ConfigEditor';
|
|
79
79
|
export { AdminConfigurationI18n } from './admin/ConfigurationI18n';
|
|
80
|
+
export { AdminConfigurationCommunityAccess } from './admin/community/CommunityAccess';
|
|
80
81
|
export { AdminConfigurationCommunityInfo } from './admin/community/CommunityInfo';
|
|
81
82
|
export { AdminConfigurationCommunityLinks } from './admin/community/CommunityLinks';
|
|
82
83
|
export { CommunityMarkdownPage } from './admin/community/CommunityMarkdownPage';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useMemo } from 'react';
|
|
2
2
|
import { FilePlus } from 'lucide-react';
|
|
3
|
-
import {
|
|
3
|
+
import { canCreatePostTypeIgnoringScopes } from '@openpeepshq/common/lib';
|
|
4
4
|
import {
|
|
5
5
|
useT,
|
|
6
6
|
useSetPageHeader,
|
|
@@ -15,7 +15,7 @@ export const ResourcesIndex = () => {
|
|
|
15
15
|
const t = useT();
|
|
16
16
|
const navigate = useNavigate();
|
|
17
17
|
const authData = useAuthData();
|
|
18
|
-
const canCreate =
|
|
18
|
+
const canCreate = canCreatePostTypeIgnoringScopes(authData, 'resource');
|
|
19
19
|
|
|
20
20
|
const openNew = useCallback(() => {
|
|
21
21
|
const stores = getNewPostStores();
|