@openpeepshq/react 0.5.1 → 0.6.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/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/markdown/CompiledMarkdown.d.ts +3 -1
- package/dist/components/markdown/CompiledMarkdown.js +17 -1
- package/dist/components/markdown/OpenpeepsMarkdown.d.ts +3 -7
- package/dist/components/markdown/OpenpeepsMarkdown.js +11 -7
- package/dist/components/markdown/classes.d.ts +3 -3
- package/dist/components/markdown/classes.js +3 -3
- package/dist/components/markdown/compileMarkdown.d.ts +3 -1
- package/dist/components/markdown/compileMarkdown.js +29 -4
- package/dist/components/markdown/index.d.ts +3 -1
- package/dist/components/markdown/linkTargets.d.ts +2 -3
- package/dist/components/markdown/linkTargets.js +2 -27
- package/dist/components/post/CompactReplyParent.js +8 -0
- package/dist/components/post/FeedPostContent.js +3 -0
- package/dist/components/post/NewResourceButton.d.ts +8 -0
- package/dist/components/post/NewResourceButton.js +36 -0
- package/dist/components/post/PostDetail.js +3 -0
- package/dist/components/post/index.d.ts +5 -0
- package/dist/components/post/index.js +3 -0
- package/dist/components/post/pieces/PostMenu.js +4 -0
- package/dist/components/post/post-form/PostTypeSwitcher.js +12 -2
- package/dist/components/post/post-form/ResourceForm.d.ts +7 -0
- package/dist/components/post/post-form/ResourceForm.js +68 -0
- package/dist/components/post/types/resource/FullResource.d.ts +5 -0
- package/dist/components/post/types/resource/FullResource.js +99 -0
- package/dist/components/resources/CategoryPathPicker.d.ts +7 -0
- package/dist/components/resources/CategoryPathPicker.js +26 -0
- package/dist/components/resources/ResourceCard.d.ts +8 -0
- package/dist/components/resources/ResourceCard.js +121 -0
- package/dist/components/resources/ResourceLibrary.d.ts +4 -0
- package/dist/components/resources/ResourceLibrary.js +106 -0
- package/dist/components/resources/index.d.ts +6 -0
- package/dist/components/resources/index.js +3 -0
- package/dist/contexts/openpeeps/hooks/admin.d.ts +1064 -38
- package/dist/contexts/openpeeps/hooks/jams.d.ts +1064 -38
- package/dist/contexts/openpeeps/hooks/posts.d.ts +4508 -39936
- package/dist/hooks/events/useEventComposer.d.ts +1184 -44
- package/dist/hooks/events/useEventsCalendar.d.ts +2113 -61
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/jams/useCreateNewJamForm.d.ts +39 -1
- package/dist/hooks/jams/useJamDetails.d.ts +1064 -38
- package/dist/hooks/jams/useJamRoom.d.ts +2113 -61
- package/dist/hooks/posts/useArticleComposer.d.ts +1184 -44
- package/dist/hooks/posts/useFeedPostPresentation.d.ts +2113 -61
- package/dist/hooks/posts/usePostDetailTitle.d.ts +1064 -38
- package/dist/hooks/posts/useResourceComposer.d.ts +12019 -0
- package/dist/hooks/posts/useResourceComposer.js +139 -0
- package/dist/hooks/resources/useResourceLibrary.d.ts +21880 -0
- package/dist/hooks/resources/useResourceLibrary.js +130 -0
- package/dist/hooks/settings/useNotificationPreferences.d.ts +1 -1
- package/dist/lib/analyticsClicks.js +1 -1
- package/dist/navigation/menuItems.js +5 -0
- package/dist/navigation/targets.d.ts +4 -0
- package/dist/pages/admin/analytics/Content.js +2 -1
- package/dist/pages/admin/analytics/Overview.js +15 -3
- package/dist/pages/groups/Show.js +7 -3
- package/dist/pages/index.d.ts +3 -0
- package/dist/pages/index.js +3 -0
- package/dist/pages/resources/Edit.d.ts +1 -0
- package/dist/pages/resources/Edit.js +26 -0
- package/dist/pages/resources/Index.d.ts +1 -0
- package/dist/pages/resources/Index.js +29 -0
- package/dist/pages/resources/New.d.ts +1 -0
- package/dist/pages/resources/New.js +15 -0
- package/dist/react-native.d.ts +3 -1
- package/dist/react-native.js +2 -1
- package/dist/stores/index.d.ts +1 -1
- package/dist/stores/index.js +1 -1
- package/dist/stores/newPosts.d.ts +79 -2
- package/dist/stores/newPosts.js +26 -2
- package/dist/stores/types.d.ts +2 -0
- package/package.json +7 -6
- package/src/components/index.ts +1 -0
- package/src/components/markdown/CompiledMarkdown.tsx +36 -7
- package/src/components/markdown/OpenpeepsMarkdown.tsx +16 -16
- package/src/components/markdown/classes.ts +3 -3
- package/src/components/markdown/compileMarkdown.ts +45 -5
- package/src/components/markdown/index.ts +6 -1
- package/src/components/markdown/linkTargets.ts +2 -31
- package/src/components/post/CompactReplyParent.tsx +8 -0
- package/src/components/post/FeedPostContent.tsx +3 -0
- package/src/components/post/NewResourceButton.tsx +75 -0
- package/src/components/post/PostDetail.tsx +3 -0
- package/src/components/post/index.ts +5 -0
- package/src/components/post/pieces/PostMenu.tsx +4 -0
- package/src/components/post/post-form/PostTypeSwitcher.tsx +19 -1
- package/src/components/post/post-form/ResourceForm.tsx +237 -0
- package/src/components/post/types/resource/FullResource.tsx +173 -0
- package/src/components/resources/CategoryPathPicker.tsx +95 -0
- package/src/components/resources/ResourceCard.tsx +335 -0
- package/src/components/resources/ResourceLibrary.tsx +374 -0
- package/src/components/resources/index.ts +6 -0
- package/src/contexts/openpeeps/hooks/posts.ts +11 -2
- package/src/hooks/index.ts +2 -0
- package/src/hooks/posts/useResourceComposer.ts +165 -0
- package/src/hooks/resources/useResourceLibrary.ts +156 -0
- package/src/lib/analyticsClicks.ts +1 -1
- package/src/navigation/menuItems.ts +6 -0
- package/src/navigation/targets.ts +1 -0
- package/src/pages/admin/analytics/Content.tsx +2 -1
- package/src/pages/admin/analytics/Overview.tsx +15 -3
- package/src/pages/groups/Show.tsx +30 -1
- package/src/pages/index.ts +3 -0
- package/src/pages/resources/Edit.tsx +73 -0
- package/src/pages/resources/Index.tsx +45 -0
- package/src/pages/resources/New.tsx +53 -0
- package/src/react-native.ts +12 -0
- package/src/stores/index.ts +1 -0
- package/src/stores/newPosts.ts +33 -2
- package/src/stores/types.ts +2 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ResourceLibrary } from './ResourceLibrary';
|
|
2
|
+
export type { ResourceLibraryProps } from './ResourceLibrary';
|
|
3
|
+
export { ResourceCard } from './ResourceCard';
|
|
4
|
+
export type { ResourceCardProps } from './ResourceCard';
|
|
5
|
+
export { CategoryPathPicker } from './CategoryPathPicker';
|
|
6
|
+
export type { CategoryPathPickerProps } from './CategoryPathPicker';
|
|
@@ -88,7 +88,14 @@ type EventFeeds = ReturnType<typeof eventFeeds>;
|
|
|
88
88
|
*/
|
|
89
89
|
const DEFAULT_FEED_LIMIT = 15;
|
|
90
90
|
|
|
91
|
-
const jamFeeds = (
|
|
91
|
+
const jamFeeds = (
|
|
92
|
+
client: OpenpeepsClient,
|
|
93
|
+
): {
|
|
94
|
+
useUpcomingJamsFeed: (pageSize?: number) => EventFeedHook;
|
|
95
|
+
usePastJamsFeed: (pageSize?: number) => EventFeedHook;
|
|
96
|
+
useMyUpcomingJamsFeed: (pageSize?: number) => EventFeedHook;
|
|
97
|
+
useMyPastJamsFeed: (pageSize?: number) => EventFeedHook;
|
|
98
|
+
} => ({
|
|
92
99
|
useUpcomingJamsFeed: (pageSize: number | undefined = DEFAULT_FEED_LIMIT) =>
|
|
93
100
|
infiniteOffsetQueryApiHook(client.posts.feeds.jams.upcoming, { pageSize }),
|
|
94
101
|
usePastJamsFeed: (pageSize: number | undefined = DEFAULT_FEED_LIMIT) =>
|
|
@@ -235,7 +242,9 @@ const postMutators = (client: OpenpeepsClient) => ({
|
|
|
235
242
|
['profiles', 'current', 'bookmarkedIds'],
|
|
236
243
|
]),
|
|
237
244
|
markPostsSeenAction: payloadPostsReadMutation(client.posts.seen),
|
|
238
|
-
markGroupPostsSeenAction: noPayloadPostsReadMutation(
|
|
245
|
+
markGroupPostsSeenAction: noPayloadPostsReadMutation(
|
|
246
|
+
client.posts.seenByGroup,
|
|
247
|
+
),
|
|
239
248
|
repostPostAction: noPayloadMutation(client.posts.repost, [['posts']]),
|
|
240
249
|
voteOnPostAction: payloadMutation(client.posts.vote, [['posts']]),
|
|
241
250
|
rsvpToEventAction: payloadMutation(client.posts.rsvp, [['posts'], ['rsvp']]),
|
package/src/hooks/index.ts
CHANGED
|
@@ -80,6 +80,8 @@ export { useNewGroup } from './groups/useNewGroup';
|
|
|
80
80
|
export { useGroupTemplateSelection } from './groups/useGroupTemplateSelection';
|
|
81
81
|
export type { UseGroupTemplateSelectionArgs } from './groups/useGroupTemplateSelection';
|
|
82
82
|
export { useNewArticle, useEditArticle } from './posts/useArticleComposer';
|
|
83
|
+
export { useNewResource, useEditResource } from './posts/useResourceComposer';
|
|
84
|
+
export { useResourceLibrary } from './resources/useResourceLibrary';
|
|
83
85
|
export {
|
|
84
86
|
useEventsCalendar,
|
|
85
87
|
eventName as calendarEventName,
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
PostCreationData,
|
|
4
|
+
PostDataUnion,
|
|
5
|
+
ResourcePost,
|
|
6
|
+
} from '@openpeepshq/common/types';
|
|
7
|
+
import {
|
|
8
|
+
normalizeResourceTags,
|
|
9
|
+
resourceHasRequiredMedia,
|
|
10
|
+
} from '@openpeepshq/common/lib';
|
|
11
|
+
import { useOpenpeeps } from '../../contexts/openpeeps';
|
|
12
|
+
import { useNavigate } from '../../contexts/router';
|
|
13
|
+
import { useT } from '../../i18n/context';
|
|
14
|
+
import { useServerInfo } from '../../components/server-data';
|
|
15
|
+
import { defaultNewResource, getNewPostStores } from '../../stores';
|
|
16
|
+
|
|
17
|
+
const asResource = (data: PostDataUnion): ResourcePost | null =>
|
|
18
|
+
data.type === 'resource' ? data : null;
|
|
19
|
+
|
|
20
|
+
const preparedResource = (resource: ResourcePost): ResourcePost => ({
|
|
21
|
+
...resource,
|
|
22
|
+
title: resource.title.trim(),
|
|
23
|
+
tags: normalizeResourceTags(resource.tags),
|
|
24
|
+
categoryPath: (resource.categoryPath ?? [])
|
|
25
|
+
.map((segment) => segment.trim())
|
|
26
|
+
.filter(Boolean),
|
|
27
|
+
url: resource.url?.trim() || undefined,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const useNewResource = () => {
|
|
31
|
+
const t = useT();
|
|
32
|
+
const navigate = useNavigate();
|
|
33
|
+
const serverInfo = useServerInfo();
|
|
34
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
35
|
+
const createPost = openpeepsApi.createPostAction();
|
|
36
|
+
const stores = getNewPostStores();
|
|
37
|
+
|
|
38
|
+
const [postData, setPostDataState] = useState<PostCreationData>(() => {
|
|
39
|
+
const stored = stores.resource;
|
|
40
|
+
if (stored.type === 'resource' && stored.data.type === 'resource') {
|
|
41
|
+
return stored;
|
|
42
|
+
}
|
|
43
|
+
return defaultNewResource(serverInfo.publicContent);
|
|
44
|
+
});
|
|
45
|
+
const [submitting, setSubmitting] = useState(false);
|
|
46
|
+
const [error, setError] = useState<string | null>(null);
|
|
47
|
+
|
|
48
|
+
const resource = asResource(postData.data);
|
|
49
|
+
const canSubmit =
|
|
50
|
+
!!resource?.title.trim() &&
|
|
51
|
+
!!resource &&
|
|
52
|
+
resourceHasRequiredMedia(resource) &&
|
|
53
|
+
!(postData.visibility === 'direct' && !postData.audience?.length);
|
|
54
|
+
|
|
55
|
+
const setPostData = (data: PostCreationData) => {
|
|
56
|
+
setPostDataState(data);
|
|
57
|
+
stores.resource = data;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const submit = useCallback(async () => {
|
|
61
|
+
setError(null);
|
|
62
|
+
if (!resource?.title.trim()) {
|
|
63
|
+
setError(
|
|
64
|
+
t('resources.validation.titleRequired', {
|
|
65
|
+
defaultValue: 'Title is required',
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (!resourceHasRequiredMedia(resource)) {
|
|
71
|
+
setError(
|
|
72
|
+
t('resources.validation.mediaRequired', {
|
|
73
|
+
defaultValue: 'Add the media or link this resource needs',
|
|
74
|
+
}),
|
|
75
|
+
);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (postData.visibility === 'direct' && !postData.audience?.length) {
|
|
79
|
+
setError(
|
|
80
|
+
t('resources.validation.directAudience', {
|
|
81
|
+
defaultValue: 'Choose at least one recipient for a direct resource.',
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
setSubmitting(true);
|
|
87
|
+
try {
|
|
88
|
+
const created = await createPost({
|
|
89
|
+
...postData,
|
|
90
|
+
type: 'resource',
|
|
91
|
+
data: preparedResource(resource),
|
|
92
|
+
});
|
|
93
|
+
stores.resetNewResourceState();
|
|
94
|
+
navigate({ type: 'post', id: created.id });
|
|
95
|
+
} catch (err) {
|
|
96
|
+
setError((err as Error).message);
|
|
97
|
+
} finally {
|
|
98
|
+
setSubmitting(false);
|
|
99
|
+
}
|
|
100
|
+
}, [createPost, navigate, postData, resource, stores, t]);
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
postData,
|
|
104
|
+
setPostData,
|
|
105
|
+
canSubmit,
|
|
106
|
+
submitting,
|
|
107
|
+
error,
|
|
108
|
+
clearError: () => setError(null),
|
|
109
|
+
submit,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const useEditResource = (resourceId: string) => {
|
|
114
|
+
const navigate = useNavigate();
|
|
115
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
116
|
+
const postQuery = openpeepsApi.usePost(resourceId);
|
|
117
|
+
const updatePost = openpeepsApi.updatePostAction({ id: resourceId });
|
|
118
|
+
|
|
119
|
+
const [postData, setPostData] = useState<PostCreationData | null>(null);
|
|
120
|
+
const [submitting, setSubmitting] = useState(false);
|
|
121
|
+
const [error, setError] = useState<string | null>(null);
|
|
122
|
+
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (postQuery.data && postQuery.data.type === 'resource') {
|
|
125
|
+
setPostData({
|
|
126
|
+
visibility: postQuery.data.visibility,
|
|
127
|
+
type: 'resource',
|
|
128
|
+
groupId: postQuery.data.groupId ?? undefined,
|
|
129
|
+
audience: postQuery.data.audience ?? undefined,
|
|
130
|
+
data: postQuery.data.data as PostDataUnion & { type: 'resource' },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}, [postQuery.data]);
|
|
134
|
+
|
|
135
|
+
const resourceTitle = asResource(
|
|
136
|
+
postQuery.data?.data as PostDataUnion,
|
|
137
|
+
)?.title;
|
|
138
|
+
|
|
139
|
+
const submit = useCallback(async () => {
|
|
140
|
+
if (!postData) return;
|
|
141
|
+
const resource = asResource(postData.data);
|
|
142
|
+
if (!resource) return;
|
|
143
|
+
setError(null);
|
|
144
|
+
setSubmitting(true);
|
|
145
|
+
try {
|
|
146
|
+
await updatePost(preparedResource(resource));
|
|
147
|
+
navigate({ type: 'post', id: resourceId });
|
|
148
|
+
} catch (err) {
|
|
149
|
+
setError((err as Error).message);
|
|
150
|
+
} finally {
|
|
151
|
+
setSubmitting(false);
|
|
152
|
+
}
|
|
153
|
+
}, [navigate, postData, resourceId, updatePost]);
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
postQuery,
|
|
157
|
+
postData,
|
|
158
|
+
setPostData,
|
|
159
|
+
resourceTitle,
|
|
160
|
+
submitting,
|
|
161
|
+
error,
|
|
162
|
+
clearError: () => setError(null),
|
|
163
|
+
submit,
|
|
164
|
+
};
|
|
165
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
2
|
+
import type { PublicPost, ResourceKind } from '@openpeepshq/common/types';
|
|
3
|
+
import {
|
|
4
|
+
categoryTreeFromPaths,
|
|
5
|
+
normalizeResourceTags,
|
|
6
|
+
pathStartsWith,
|
|
7
|
+
} from '@openpeepshq/common/lib';
|
|
8
|
+
import { useOpenpeeps } from '../../contexts/openpeeps';
|
|
9
|
+
import { useFeedListParams } from '../useResolvedFeedFormat';
|
|
10
|
+
|
|
11
|
+
export const useResourceLibrary = (groupId?: string) => {
|
|
12
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
13
|
+
const params = useFeedListParams({ format: 'linear' });
|
|
14
|
+
const query = openpeepsApi.usePostsByType('resource', {
|
|
15
|
+
...params,
|
|
16
|
+
...(groupId ? { groupId } : { ungrouped: 'true' as const }),
|
|
17
|
+
});
|
|
18
|
+
const bookmarkedIds = openpeepsApi.useCurrentProfileBookmarkedIds();
|
|
19
|
+
|
|
20
|
+
const [search, setSearch] = useState('');
|
|
21
|
+
const [kind, setKind] = useState<ResourceKind | 'all'>('all');
|
|
22
|
+
const [selectedTags, setSelectedTags] = useState<string[]>([]);
|
|
23
|
+
const [pathPrefix, setPathPrefix] = useState<string[]>([]);
|
|
24
|
+
const [hierarchy, setHierarchy] = useState(false);
|
|
25
|
+
const [view, setView] = useState<'list' | 'cards'>('cards');
|
|
26
|
+
const [saved, setSaved] = useState(false);
|
|
27
|
+
|
|
28
|
+
const posts = useMemo(() => {
|
|
29
|
+
const flat = (query.data?.pages ?? []).flat();
|
|
30
|
+
const seen = new Set<string>();
|
|
31
|
+
const out: PublicPost[] = [];
|
|
32
|
+
for (const post of flat) {
|
|
33
|
+
if (seen.has(post.id) || post.type !== 'resource') continue;
|
|
34
|
+
seen.add(post.id);
|
|
35
|
+
out.push(post);
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}, [query.data]);
|
|
39
|
+
|
|
40
|
+
const tags = useMemo(() => {
|
|
41
|
+
const counts = new Map<string, number>();
|
|
42
|
+
for (const post of posts) {
|
|
43
|
+
if (post.data?.type !== 'resource') continue;
|
|
44
|
+
for (const value of normalizeResourceTags(post.data.tags)) {
|
|
45
|
+
counts.set(value, (counts.get(value) ?? 0) + 1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return [...counts.entries()]
|
|
49
|
+
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
50
|
+
.map(([name, count]) => ({ name, count }));
|
|
51
|
+
}, [posts]);
|
|
52
|
+
|
|
53
|
+
const tree = useMemo(
|
|
54
|
+
() =>
|
|
55
|
+
categoryTreeFromPaths(
|
|
56
|
+
posts.flatMap((post) =>
|
|
57
|
+
post.data?.type === 'resource' && post.data.categoryPath?.length
|
|
58
|
+
? [post.data.categoryPath]
|
|
59
|
+
: [],
|
|
60
|
+
),
|
|
61
|
+
),
|
|
62
|
+
[posts],
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const toggleTag = (tag: string) =>
|
|
66
|
+
setSelectedTags((prev) =>
|
|
67
|
+
prev.includes(tag) ? prev.filter((t) => t !== tag) : [...prev, tag],
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const filtered = useMemo(() => {
|
|
71
|
+
const q = search.trim().toLowerCase();
|
|
72
|
+
const bookmarked = new Set(bookmarkedIds.data ?? []);
|
|
73
|
+
return posts.filter((post) => {
|
|
74
|
+
if (post.data?.type !== 'resource') return false;
|
|
75
|
+
const resource = post.data;
|
|
76
|
+
if (kind !== 'all' && resource.resourceKind !== kind) return false;
|
|
77
|
+
if (selectedTags.length > 0) {
|
|
78
|
+
const resourceTagSet = new Set(normalizeResourceTags(resource.tags));
|
|
79
|
+
if (!selectedTags.every((t) => resourceTagSet.has(t))) return false;
|
|
80
|
+
}
|
|
81
|
+
if (
|
|
82
|
+
pathPrefix.length &&
|
|
83
|
+
!pathStartsWith(resource.categoryPath ?? [], pathPrefix)
|
|
84
|
+
) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (saved && !bookmarked.has(post.id)) return false;
|
|
88
|
+
if (!q) return true;
|
|
89
|
+
const hay = [
|
|
90
|
+
resource.title,
|
|
91
|
+
resource.content,
|
|
92
|
+
...(resource.tags ?? []),
|
|
93
|
+
...(resource.categoryPath ?? []),
|
|
94
|
+
resource.url,
|
|
95
|
+
]
|
|
96
|
+
.filter(Boolean)
|
|
97
|
+
.join(' ')
|
|
98
|
+
.toLowerCase();
|
|
99
|
+
return hay.includes(q);
|
|
100
|
+
});
|
|
101
|
+
}, [
|
|
102
|
+
kind,
|
|
103
|
+
pathPrefix,
|
|
104
|
+
posts,
|
|
105
|
+
search,
|
|
106
|
+
selectedTags,
|
|
107
|
+
saved,
|
|
108
|
+
bookmarkedIds.data,
|
|
109
|
+
]);
|
|
110
|
+
|
|
111
|
+
const activeFilterCount = useMemo(
|
|
112
|
+
() =>
|
|
113
|
+
(kind !== 'all' ? 1 : 0) +
|
|
114
|
+
(selectedTags.length ? 1 : 0) +
|
|
115
|
+
(pathPrefix.length ? 1 : 0) +
|
|
116
|
+
(search.trim() ? 1 : 0) +
|
|
117
|
+
(saved ? 1 : 0),
|
|
118
|
+
[kind, pathPrefix, search, selectedTags, saved],
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const clearAllFilters = () => {
|
|
122
|
+
setKind('all');
|
|
123
|
+
setSelectedTags([]);
|
|
124
|
+
setPathPrefix([]);
|
|
125
|
+
setSearch('');
|
|
126
|
+
setSaved(false);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const [tagsOpen, setTagsOpen] = useState(false);
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
query,
|
|
133
|
+
posts: filtered,
|
|
134
|
+
tags,
|
|
135
|
+
tree,
|
|
136
|
+
search,
|
|
137
|
+
setSearch,
|
|
138
|
+
kind,
|
|
139
|
+
setKind,
|
|
140
|
+
selectedTags,
|
|
141
|
+
setSelectedTags,
|
|
142
|
+
toggleTag,
|
|
143
|
+
pathPrefix,
|
|
144
|
+
setPathPrefix,
|
|
145
|
+
hierarchy,
|
|
146
|
+
setHierarchy,
|
|
147
|
+
view,
|
|
148
|
+
setView,
|
|
149
|
+
saved,
|
|
150
|
+
setSaved,
|
|
151
|
+
activeFilterCount,
|
|
152
|
+
clearAllFilters,
|
|
153
|
+
tagsOpen,
|
|
154
|
+
setTagsOpen,
|
|
155
|
+
};
|
|
156
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
-
import { isExternalLink } from '
|
|
2
|
+
import { isExternalLink } from '@openpeepshq/common/lib';
|
|
3
3
|
import { useOpenpeeps } from '../contexts/openpeeps';
|
|
4
4
|
import { useOptionalPathname } from '../contexts/router';
|
|
5
5
|
|
|
@@ -60,6 +60,12 @@ export const buildMainNavItems = (caps: MainMenuCapabilities): NavItemDef[] => {
|
|
|
60
60
|
labelKey: 'navigation.articles',
|
|
61
61
|
icon: 'ScrollText',
|
|
62
62
|
},
|
|
63
|
+
{
|
|
64
|
+
id: 'resources',
|
|
65
|
+
target: { type: 'resources' },
|
|
66
|
+
labelKey: 'navigation.resources',
|
|
67
|
+
icon: 'Library',
|
|
68
|
+
},
|
|
63
69
|
{
|
|
64
70
|
id: 'messages',
|
|
65
71
|
target: { type: 'conversation' },
|
|
@@ -21,6 +21,7 @@ export type NavTarget =
|
|
|
21
21
|
| { type: 'jams'; view?: 'my' }
|
|
22
22
|
| { type: 'events'; view?: 'my' | 'new'; eventId?: string }
|
|
23
23
|
| { type: 'articles'; view?: 'new'; articleId?: string }
|
|
24
|
+
| { type: 'resources'; view?: 'new'; resourceId?: string }
|
|
24
25
|
| { type: 'members' }
|
|
25
26
|
| { type: 'notifications' }
|
|
26
27
|
| { type: 'tags'; hashtag: string }
|
|
@@ -23,6 +23,7 @@ const POST_TYPE_META: Array<{
|
|
|
23
23
|
{ key: 'article', label: 'Articles', color: analyticsChartColor(1) },
|
|
24
24
|
{ key: 'note', label: 'Notes', color: analyticsChartColor(2) },
|
|
25
25
|
{ key: 'poll', label: 'Polls', color: analyticsChartColor(3) },
|
|
26
|
+
{ key: 'resource', label: 'Resources', color: analyticsChartColor(5) },
|
|
26
27
|
];
|
|
27
28
|
|
|
28
29
|
const utcDayCount = (from: string, to: string) => {
|
|
@@ -121,7 +122,7 @@ export const AnalyticsContentPage = () => {
|
|
|
121
122
|
|
|
122
123
|
const postsByPeriod = data.postsOverTime.map((p) => ({
|
|
123
124
|
label: p.label,
|
|
124
|
-
value: p.jam + p.article + p.note + p.poll + p.event,
|
|
125
|
+
value: p.jam + p.article + p.note + p.poll + p.event + p.resource,
|
|
125
126
|
}));
|
|
126
127
|
const info = (key: string, defaultValue: string) =>
|
|
127
128
|
t(`admin.analytics.info.${key}`, { defaultValue });
|
|
@@ -25,6 +25,7 @@ const POST_TYPE_SERIES: Array<{
|
|
|
25
25
|
{ key: 'note', label: 'Notes', color: analyticsChartColor(2) },
|
|
26
26
|
{ key: 'poll', label: 'Polls', color: analyticsChartColor(3) },
|
|
27
27
|
{ key: 'event', label: 'Events', color: analyticsChartColor(4) },
|
|
28
|
+
{ key: 'resource', label: 'Resources', color: analyticsChartColor(5) },
|
|
28
29
|
];
|
|
29
30
|
|
|
30
31
|
const PostTypesList = ({
|
|
@@ -75,12 +76,13 @@ export const AnalyticsOverviewPage = () => {
|
|
|
75
76
|
|
|
76
77
|
const stackedData = data.postsOverTime.map((p) => ({
|
|
77
78
|
label: p.label,
|
|
78
|
-
value: p.jam + p.article + p.note + p.poll + p.event,
|
|
79
|
+
value: p.jam + p.article + p.note + p.poll + p.event + p.resource,
|
|
79
80
|
jam: p.jam,
|
|
80
81
|
article: p.article,
|
|
81
82
|
note: p.note,
|
|
82
83
|
poll: p.poll,
|
|
83
84
|
event: p.event,
|
|
85
|
+
resource: p.resource,
|
|
84
86
|
}));
|
|
85
87
|
|
|
86
88
|
const activeUsersChart = data.activeUsersSeries.map((p) => ({
|
|
@@ -160,11 +162,20 @@ export const AnalyticsOverviewPage = () => {
|
|
|
160
162
|
})}
|
|
161
163
|
info={info(
|
|
162
164
|
'postsOverTime',
|
|
163
|
-
'Posts created in each time bucket of the range, stacked by type (jams, articles, notes, polls, events).',
|
|
165
|
+
'Posts created in each time bucket of the range, stacked by type (jams, articles, notes, polls, events, resources).',
|
|
164
166
|
)}
|
|
165
167
|
csvFilename="posts-over-time.csv"
|
|
166
168
|
csvRows={[
|
|
167
|
-
[
|
|
169
|
+
[
|
|
170
|
+
'bucket',
|
|
171
|
+
'label',
|
|
172
|
+
'jam',
|
|
173
|
+
'article',
|
|
174
|
+
'note',
|
|
175
|
+
'poll',
|
|
176
|
+
'event',
|
|
177
|
+
'resource',
|
|
178
|
+
],
|
|
168
179
|
...data.postsOverTime.map((p) => [
|
|
169
180
|
p.day,
|
|
170
181
|
p.label,
|
|
@@ -173,6 +184,7 @@ export const AnalyticsOverviewPage = () => {
|
|
|
173
184
|
p.note,
|
|
174
185
|
p.poll,
|
|
175
186
|
p.event,
|
|
187
|
+
p.resource,
|
|
176
188
|
]),
|
|
177
189
|
]}
|
|
178
190
|
>
|
|
@@ -7,11 +7,13 @@ import {
|
|
|
7
7
|
GroupFeed,
|
|
8
8
|
GroupHeader,
|
|
9
9
|
NewEventButton,
|
|
10
|
+
NewResourceButton,
|
|
10
11
|
PostMarkdown,
|
|
11
12
|
useCurrentProfile,
|
|
12
13
|
} from '../../components';
|
|
13
14
|
import { routeHandleParam } from '../../lib/routeHandles';
|
|
14
15
|
import { LoadingSpinner } from '@openpeepshq/react-ui';
|
|
16
|
+
import { ResourceLibrary } from '../../components/resources/ResourceLibrary';
|
|
15
17
|
|
|
16
18
|
export function GroupShow() {
|
|
17
19
|
const t = useT();
|
|
@@ -23,7 +25,9 @@ export function GroupShow() {
|
|
|
23
25
|
const groupQuery = openpeepsApi.useGroupByHandle(handle);
|
|
24
26
|
const group = groupQuery.data;
|
|
25
27
|
const currentProfile = useCurrentProfile();
|
|
26
|
-
const [tab, setTab] = useState<
|
|
28
|
+
const [tab, setTab] = useState<
|
|
29
|
+
'posts' | 'events' | 'resources' | 'description'
|
|
30
|
+
>('posts');
|
|
27
31
|
|
|
28
32
|
const upcomingEvents = openpeepsApi.useGroupUpcomingEventsFeed(
|
|
29
33
|
group?.id ?? '',
|
|
@@ -110,6 +114,20 @@ export function GroupShow() {
|
|
|
110
114
|
>
|
|
111
115
|
{t('groups.sections.events', { defaultValue: 'Events' })}
|
|
112
116
|
</TabButton>
|
|
117
|
+
<TabButton
|
|
118
|
+
active={tab === 'resources'}
|
|
119
|
+
onClick={() => {
|
|
120
|
+
setTab('resources');
|
|
121
|
+
window.history.replaceState(
|
|
122
|
+
null,
|
|
123
|
+
'',
|
|
124
|
+
`${window.location.pathname}#resources`,
|
|
125
|
+
);
|
|
126
|
+
}}
|
|
127
|
+
testId="groups-tab-resources"
|
|
128
|
+
>
|
|
129
|
+
{t('groups.sections.resources', { defaultValue: 'Resources' })}
|
|
130
|
+
</TabButton>
|
|
113
131
|
<TabButton
|
|
114
132
|
active={tab === 'description'}
|
|
115
133
|
onClick={() => {
|
|
@@ -168,6 +186,17 @@ export function GroupShow() {
|
|
|
168
186
|
</div>
|
|
169
187
|
)}
|
|
170
188
|
|
|
189
|
+
{tab === 'resources' && (
|
|
190
|
+
<div>
|
|
191
|
+
<NewResourceButton
|
|
192
|
+
visibility="group"
|
|
193
|
+
currentProfile={currentProfile}
|
|
194
|
+
group={group}
|
|
195
|
+
/>
|
|
196
|
+
<ResourceLibrary groupId={group.id} />
|
|
197
|
+
</div>
|
|
198
|
+
)}
|
|
199
|
+
|
|
171
200
|
{tab === 'description' && (
|
|
172
201
|
<div className="space-y-2 p-4">
|
|
173
202
|
<section className="border-b py-2">
|
package/src/pages/index.ts
CHANGED
|
@@ -34,6 +34,9 @@ export { GroupMembers } from './groups/Members';
|
|
|
34
34
|
export { JamsIndex } from './jams/Index';
|
|
35
35
|
export { JamEvent } from './jams/Event';
|
|
36
36
|
export { ArticlesIndex } from './articles/Index';
|
|
37
|
+
export { ResourcesIndex } from './resources/Index';
|
|
38
|
+
export { NewResource } from './resources/New';
|
|
39
|
+
export { EditResource } from './resources/Edit';
|
|
37
40
|
export { Followers as ProfileFollowers } from './profile/Followers';
|
|
38
41
|
export { PublicProfileSettings } from './settings/PublicProfile';
|
|
39
42
|
export { ThemeSettings } from './settings/Theme';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useParams } from 'react-router-dom';
|
|
3
|
+
import { truncateText } from '@openpeepshq/common/lib';
|
|
4
|
+
import { useT, useSetPageHeader } from '../../index';
|
|
5
|
+
import { ResourceForm } from '../../components/post/post-form/ResourceForm';
|
|
6
|
+
import { useEditResource } from '../../hooks';
|
|
7
|
+
import { Button, LoadingSpinner, Toast } from '@openpeepshq/react-ui';
|
|
8
|
+
|
|
9
|
+
export const EditResource = () => {
|
|
10
|
+
const t = useT();
|
|
11
|
+
const { resourceId = '' } = useParams<{ resourceId: string }>();
|
|
12
|
+
const {
|
|
13
|
+
postQuery,
|
|
14
|
+
postData,
|
|
15
|
+
setPostData,
|
|
16
|
+
resourceTitle,
|
|
17
|
+
submitting,
|
|
18
|
+
error,
|
|
19
|
+
clearError,
|
|
20
|
+
submit,
|
|
21
|
+
} = useEditResource(resourceId);
|
|
22
|
+
|
|
23
|
+
const headerActions = useMemo(
|
|
24
|
+
() => (
|
|
25
|
+
<Button
|
|
26
|
+
title={t('resources.update.title', { defaultValue: 'Update resource' })}
|
|
27
|
+
variant="default"
|
|
28
|
+
action={submit}
|
|
29
|
+
disabled={submitting}
|
|
30
|
+
>
|
|
31
|
+
{submitting
|
|
32
|
+
? t('common.saving', { defaultValue: 'Saving…' })
|
|
33
|
+
: t('resources.update.title', { defaultValue: 'Update resource' })}
|
|
34
|
+
</Button>
|
|
35
|
+
),
|
|
36
|
+
[submit, submitting, t],
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
useSetPageHeader(
|
|
40
|
+
resourceTitle
|
|
41
|
+
? `${t('resources.edit', { defaultValue: 'Edit resource' })} ${truncateText(resourceTitle)}`
|
|
42
|
+
: t('resources.edit', { defaultValue: 'Edit resource' }),
|
|
43
|
+
headerActions,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (postQuery.isLoading) {
|
|
47
|
+
return (
|
|
48
|
+
<div className="text-muted-foreground flex h-32 items-center justify-center text-sm">
|
|
49
|
+
<LoadingSpinner />
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (!postQuery.data || !postData) {
|
|
54
|
+
return (
|
|
55
|
+
<div className="p-8 text-center text-2xl">
|
|
56
|
+
{t('resources.notFound', { defaultValue: 'Resource not found' })}
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<div className="pb-12">
|
|
63
|
+
<ResourceForm postData={postData} onChange={setPostData} isEdit />
|
|
64
|
+
{error ? (
|
|
65
|
+
<div className="px-3">
|
|
66
|
+
<Toast variant="error" onDismiss={clearError}>
|
|
67
|
+
{error}
|
|
68
|
+
</Toast>
|
|
69
|
+
</div>
|
|
70
|
+
) : null}
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { FilePlus } from 'lucide-react';
|
|
3
|
+
import { canCreatePostType } from '@openpeepshq/common/lib';
|
|
4
|
+
import {
|
|
5
|
+
useT,
|
|
6
|
+
useSetPageHeader,
|
|
7
|
+
useSetPlusButtonActions,
|
|
8
|
+
useAuthData,
|
|
9
|
+
} from '../../index';
|
|
10
|
+
import { useNavigate } from '../../contexts/router';
|
|
11
|
+
import { ResourceLibrary } from '../../components/resources/ResourceLibrary';
|
|
12
|
+
import { getNewPostStores } from '../../stores';
|
|
13
|
+
|
|
14
|
+
export const ResourcesIndex = () => {
|
|
15
|
+
const t = useT();
|
|
16
|
+
const navigate = useNavigate();
|
|
17
|
+
const authData = useAuthData();
|
|
18
|
+
const canCreate = canCreatePostType(authData, 'resource');
|
|
19
|
+
|
|
20
|
+
const openNew = useCallback(() => {
|
|
21
|
+
const stores = getNewPostStores();
|
|
22
|
+
stores.resource = { ...stores.resource, groupId: undefined };
|
|
23
|
+
navigate({ type: 'resources', view: 'new' });
|
|
24
|
+
}, [navigate]);
|
|
25
|
+
|
|
26
|
+
const plusButton = useMemo(
|
|
27
|
+
() =>
|
|
28
|
+
canCreate
|
|
29
|
+
? {
|
|
30
|
+
title: t('resources.new', { defaultValue: 'New resource' }),
|
|
31
|
+
icon: FilePlus,
|
|
32
|
+
action: openNew,
|
|
33
|
+
}
|
|
34
|
+
: undefined,
|
|
35
|
+
[canCreate, openNew, t],
|
|
36
|
+
);
|
|
37
|
+
useSetPlusButtonActions(plusButton);
|
|
38
|
+
useSetPageHeader(
|
|
39
|
+
t('navigation.resources', { defaultValue: 'Resources' }),
|
|
40
|
+
undefined,
|
|
41
|
+
'resources-page-heading',
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return <ResourceLibrary />;
|
|
45
|
+
};
|