@openpeepshq/react 0.6.0 → 0.6.2
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/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/event/FullEvent.js +3 -1
- 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/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 +1 -1
- package/dist/react-native.js +1 -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 +6 -6
- package/src/components/index.ts +1 -0
- 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/event/FullEvent.tsx +11 -3
- 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/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 +1 -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,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
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useT, useSetPageHeader } from '../../index';
|
|
3
|
+
import { ResourceForm } from '../../components/post/post-form/ResourceForm';
|
|
4
|
+
import { useNewResource } from '../../hooks';
|
|
5
|
+
import { Button, Toast } from '@openpeepshq/react-ui';
|
|
6
|
+
|
|
7
|
+
export const NewResource = () => {
|
|
8
|
+
const t = useT();
|
|
9
|
+
const {
|
|
10
|
+
postData,
|
|
11
|
+
setPostData,
|
|
12
|
+
canSubmit,
|
|
13
|
+
submitting,
|
|
14
|
+
error,
|
|
15
|
+
clearError,
|
|
16
|
+
submit,
|
|
17
|
+
} = useNewResource();
|
|
18
|
+
|
|
19
|
+
const headerActions = useMemo(
|
|
20
|
+
() => (
|
|
21
|
+
<Button
|
|
22
|
+
title={t('resources.create.title', { defaultValue: 'Create resource' })}
|
|
23
|
+
variant="default"
|
|
24
|
+
action={submit}
|
|
25
|
+
disabled={submitting || !canSubmit}
|
|
26
|
+
data-testid="resources-submit"
|
|
27
|
+
>
|
|
28
|
+
{submitting
|
|
29
|
+
? t('common.submitting', { defaultValue: 'Publishing…' })
|
|
30
|
+
: t('resources.create.title', { defaultValue: 'Create resource' })}
|
|
31
|
+
</Button>
|
|
32
|
+
),
|
|
33
|
+
[canSubmit, submit, submitting, t],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
useSetPageHeader(
|
|
37
|
+
t('resources.new', { defaultValue: 'New resource' }),
|
|
38
|
+
headerActions,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div className="pb-12">
|
|
43
|
+
<ResourceForm postData={postData} onChange={setPostData} />
|
|
44
|
+
{error ? (
|
|
45
|
+
<div className="px-3">
|
|
46
|
+
<Toast variant="error" onDismiss={clearError}>
|
|
47
|
+
{error}
|
|
48
|
+
</Toast>
|
|
49
|
+
</div>
|
|
50
|
+
) : null}
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
};
|
package/src/react-native.ts
CHANGED
package/src/stores/index.ts
CHANGED
package/src/stores/newPosts.ts
CHANGED
|
@@ -56,6 +56,21 @@ export const defaultNewArticle = (publicContent = false): PostCreationData => ({
|
|
|
56
56
|
data: { type: 'article', content: '' },
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
+
export const defaultNewResource = (
|
|
60
|
+
publicContent = false,
|
|
61
|
+
): PostCreationData => ({
|
|
62
|
+
type: 'resource',
|
|
63
|
+
visibility: defaultVisibility(publicContent),
|
|
64
|
+
data: {
|
|
65
|
+
type: 'resource',
|
|
66
|
+
title: '',
|
|
67
|
+
content: '',
|
|
68
|
+
resourceKind: 'link',
|
|
69
|
+
tags: [],
|
|
70
|
+
categoryPath: [],
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
|
|
59
74
|
export const eventSanitizer = (publicContent = false) => {
|
|
60
75
|
const def = defaultNewEvent(publicContent);
|
|
61
76
|
return (event: PostCreationData): PostCreationData => {
|
|
@@ -102,6 +117,10 @@ const ensureInitialized = (publicContent = false): NewPostsState => {
|
|
|
102
117
|
'new-article-state',
|
|
103
118
|
defaultNewArticle(publicContent),
|
|
104
119
|
);
|
|
120
|
+
const resource = persistedStore(
|
|
121
|
+
'new-resource-state',
|
|
122
|
+
defaultNewResource(publicContent),
|
|
123
|
+
);
|
|
105
124
|
const note = persistedStore('new-note-state', defaultNewNote(publicContent));
|
|
106
125
|
const question = persistedStore(
|
|
107
126
|
'new-question-state',
|
|
@@ -130,6 +149,13 @@ const ensureInitialized = (publicContent = false): NewPostsState => {
|
|
|
130
149
|
article.set(v);
|
|
131
150
|
},
|
|
132
151
|
resetNewArticleState: () => article.reset(),
|
|
152
|
+
get resource() {
|
|
153
|
+
return resource.get();
|
|
154
|
+
},
|
|
155
|
+
set resource(v: PostCreationData) {
|
|
156
|
+
resource.set(v);
|
|
157
|
+
},
|
|
158
|
+
resetNewResourceState: () => resource.reset(),
|
|
133
159
|
get note() {
|
|
134
160
|
return note.get();
|
|
135
161
|
},
|
|
@@ -147,7 +173,7 @@ const ensureInitialized = (publicContent = false): NewPostsState => {
|
|
|
147
173
|
};
|
|
148
174
|
|
|
149
175
|
// wire subscribe so React `useNewPostStores` can re-render on writes
|
|
150
|
-
internalStores = { jam, event, article, note, question };
|
|
176
|
+
internalStores = { jam, event, article, resource, note, question };
|
|
151
177
|
return initialized;
|
|
152
178
|
};
|
|
153
179
|
|
|
@@ -156,6 +182,7 @@ let internalStores:
|
|
|
156
182
|
jam: ReturnType<typeof persistedStore<PostCreationData>>;
|
|
157
183
|
event: ReturnType<typeof persistedStore<PostCreationData>>;
|
|
158
184
|
article: ReturnType<typeof persistedStore<PostCreationData>>;
|
|
185
|
+
resource: ReturnType<typeof persistedStore<PostCreationData>>;
|
|
159
186
|
note: ReturnType<typeof persistedStore<PostCreationData>>;
|
|
160
187
|
question: ReturnType<typeof persistedStore<PostCreationData>>;
|
|
161
188
|
}
|
|
@@ -169,13 +196,14 @@ export const getNewPostStores = (): NewPostsState => ensureInitialized();
|
|
|
169
196
|
|
|
170
197
|
export const useNewPostStores = (): NewPostsState => {
|
|
171
198
|
ensureInitialized();
|
|
172
|
-
// Subscribe to all
|
|
199
|
+
// Subscribe to all composer sub-stores so any write triggers a re-render.
|
|
173
200
|
useSyncExternalStore(
|
|
174
201
|
(l) => {
|
|
175
202
|
const subs = [
|
|
176
203
|
internalStores!.jam.subscribe(l),
|
|
177
204
|
internalStores!.event.subscribe(l),
|
|
178
205
|
internalStores!.article.subscribe(l),
|
|
206
|
+
internalStores!.resource.subscribe(l),
|
|
179
207
|
internalStores!.note.subscribe(l),
|
|
180
208
|
internalStores!.question.subscribe(l),
|
|
181
209
|
];
|
|
@@ -235,6 +263,9 @@ export const resetStore = (type: PostType) => {
|
|
|
235
263
|
case 'article':
|
|
236
264
|
stores.resetNewArticleState();
|
|
237
265
|
return;
|
|
266
|
+
case 'resource':
|
|
267
|
+
stores.resetNewResourceState();
|
|
268
|
+
return;
|
|
238
269
|
default:
|
|
239
270
|
return;
|
|
240
271
|
}
|
package/src/stores/types.ts
CHANGED
|
@@ -36,6 +36,8 @@ export interface NewPostsState {
|
|
|
36
36
|
resetNewEventState: () => void;
|
|
37
37
|
article: PostCreationData;
|
|
38
38
|
resetNewArticleState: () => void;
|
|
39
|
+
resource: PostCreationData;
|
|
40
|
+
resetNewResourceState: () => void;
|
|
39
41
|
note: PostCreationData;
|
|
40
42
|
resetNewNoteState: () => void;
|
|
41
43
|
question: PostCreationData;
|