@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.
Files changed (112) hide show
  1. package/dist/components/index.d.ts +1 -0
  2. package/dist/components/index.js +1 -0
  3. package/dist/components/markdown/CompiledMarkdown.d.ts +3 -1
  4. package/dist/components/markdown/CompiledMarkdown.js +17 -1
  5. package/dist/components/markdown/OpenpeepsMarkdown.d.ts +3 -7
  6. package/dist/components/markdown/OpenpeepsMarkdown.js +11 -7
  7. package/dist/components/markdown/classes.d.ts +3 -3
  8. package/dist/components/markdown/classes.js +3 -3
  9. package/dist/components/markdown/compileMarkdown.d.ts +3 -1
  10. package/dist/components/markdown/compileMarkdown.js +29 -4
  11. package/dist/components/markdown/index.d.ts +3 -1
  12. package/dist/components/markdown/linkTargets.d.ts +2 -3
  13. package/dist/components/markdown/linkTargets.js +2 -27
  14. package/dist/components/post/CompactReplyParent.js +8 -0
  15. package/dist/components/post/FeedPostContent.js +3 -0
  16. package/dist/components/post/NewResourceButton.d.ts +8 -0
  17. package/dist/components/post/NewResourceButton.js +36 -0
  18. package/dist/components/post/PostDetail.js +3 -0
  19. package/dist/components/post/index.d.ts +5 -0
  20. package/dist/components/post/index.js +3 -0
  21. package/dist/components/post/pieces/PostMenu.js +4 -0
  22. package/dist/components/post/post-form/PostTypeSwitcher.js +12 -2
  23. package/dist/components/post/post-form/ResourceForm.d.ts +7 -0
  24. package/dist/components/post/post-form/ResourceForm.js +68 -0
  25. package/dist/components/post/types/resource/FullResource.d.ts +5 -0
  26. package/dist/components/post/types/resource/FullResource.js +99 -0
  27. package/dist/components/resources/CategoryPathPicker.d.ts +7 -0
  28. package/dist/components/resources/CategoryPathPicker.js +26 -0
  29. package/dist/components/resources/ResourceCard.d.ts +8 -0
  30. package/dist/components/resources/ResourceCard.js +121 -0
  31. package/dist/components/resources/ResourceLibrary.d.ts +4 -0
  32. package/dist/components/resources/ResourceLibrary.js +106 -0
  33. package/dist/components/resources/index.d.ts +6 -0
  34. package/dist/components/resources/index.js +3 -0
  35. package/dist/contexts/openpeeps/hooks/admin.d.ts +1064 -38
  36. package/dist/contexts/openpeeps/hooks/jams.d.ts +1064 -38
  37. package/dist/contexts/openpeeps/hooks/posts.d.ts +4508 -39936
  38. package/dist/hooks/events/useEventComposer.d.ts +1184 -44
  39. package/dist/hooks/events/useEventsCalendar.d.ts +2113 -61
  40. package/dist/hooks/index.d.ts +2 -0
  41. package/dist/hooks/index.js +2 -0
  42. package/dist/hooks/jams/useCreateNewJamForm.d.ts +39 -1
  43. package/dist/hooks/jams/useJamDetails.d.ts +1064 -38
  44. package/dist/hooks/jams/useJamRoom.d.ts +2113 -61
  45. package/dist/hooks/posts/useArticleComposer.d.ts +1184 -44
  46. package/dist/hooks/posts/useFeedPostPresentation.d.ts +2113 -61
  47. package/dist/hooks/posts/usePostDetailTitle.d.ts +1064 -38
  48. package/dist/hooks/posts/useResourceComposer.d.ts +12019 -0
  49. package/dist/hooks/posts/useResourceComposer.js +139 -0
  50. package/dist/hooks/resources/useResourceLibrary.d.ts +21880 -0
  51. package/dist/hooks/resources/useResourceLibrary.js +130 -0
  52. package/dist/hooks/settings/useNotificationPreferences.d.ts +1 -1
  53. package/dist/lib/analyticsClicks.js +1 -1
  54. package/dist/navigation/menuItems.js +5 -0
  55. package/dist/navigation/targets.d.ts +4 -0
  56. package/dist/pages/admin/analytics/Content.js +2 -1
  57. package/dist/pages/admin/analytics/Overview.js +15 -3
  58. package/dist/pages/groups/Show.js +7 -3
  59. package/dist/pages/index.d.ts +3 -0
  60. package/dist/pages/index.js +3 -0
  61. package/dist/pages/resources/Edit.d.ts +1 -0
  62. package/dist/pages/resources/Edit.js +26 -0
  63. package/dist/pages/resources/Index.d.ts +1 -0
  64. package/dist/pages/resources/Index.js +29 -0
  65. package/dist/pages/resources/New.d.ts +1 -0
  66. package/dist/pages/resources/New.js +15 -0
  67. package/dist/react-native.d.ts +3 -1
  68. package/dist/react-native.js +2 -1
  69. package/dist/stores/index.d.ts +1 -1
  70. package/dist/stores/index.js +1 -1
  71. package/dist/stores/newPosts.d.ts +79 -2
  72. package/dist/stores/newPosts.js +26 -2
  73. package/dist/stores/types.d.ts +2 -0
  74. package/package.json +7 -6
  75. package/src/components/index.ts +1 -0
  76. package/src/components/markdown/CompiledMarkdown.tsx +36 -7
  77. package/src/components/markdown/OpenpeepsMarkdown.tsx +16 -16
  78. package/src/components/markdown/classes.ts +3 -3
  79. package/src/components/markdown/compileMarkdown.ts +45 -5
  80. package/src/components/markdown/index.ts +6 -1
  81. package/src/components/markdown/linkTargets.ts +2 -31
  82. package/src/components/post/CompactReplyParent.tsx +8 -0
  83. package/src/components/post/FeedPostContent.tsx +3 -0
  84. package/src/components/post/NewResourceButton.tsx +75 -0
  85. package/src/components/post/PostDetail.tsx +3 -0
  86. package/src/components/post/index.ts +5 -0
  87. package/src/components/post/pieces/PostMenu.tsx +4 -0
  88. package/src/components/post/post-form/PostTypeSwitcher.tsx +19 -1
  89. package/src/components/post/post-form/ResourceForm.tsx +237 -0
  90. package/src/components/post/types/resource/FullResource.tsx +173 -0
  91. package/src/components/resources/CategoryPathPicker.tsx +95 -0
  92. package/src/components/resources/ResourceCard.tsx +335 -0
  93. package/src/components/resources/ResourceLibrary.tsx +374 -0
  94. package/src/components/resources/index.ts +6 -0
  95. package/src/contexts/openpeeps/hooks/posts.ts +11 -2
  96. package/src/hooks/index.ts +2 -0
  97. package/src/hooks/posts/useResourceComposer.ts +165 -0
  98. package/src/hooks/resources/useResourceLibrary.ts +156 -0
  99. package/src/lib/analyticsClicks.ts +1 -1
  100. package/src/navigation/menuItems.ts +6 -0
  101. package/src/navigation/targets.ts +1 -0
  102. package/src/pages/admin/analytics/Content.tsx +2 -1
  103. package/src/pages/admin/analytics/Overview.tsx +15 -3
  104. package/src/pages/groups/Show.tsx +30 -1
  105. package/src/pages/index.ts +3 -0
  106. package/src/pages/resources/Edit.tsx +73 -0
  107. package/src/pages/resources/Index.tsx +45 -0
  108. package/src/pages/resources/New.tsx +53 -0
  109. package/src/react-native.ts +12 -0
  110. package/src/stores/index.ts +1 -0
  111. package/src/stores/newPosts.ts +33 -2
  112. package/src/stores/types.ts +2 -0
@@ -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
+ };
@@ -27,6 +27,17 @@ export {
27
27
  performResetPassword,
28
28
  performLogout,
29
29
  } from './lib/auth';
30
+ export type {
31
+ MarkdownRenderProps,
32
+ MentionProfileRef,
33
+ } from '@openpeepshq/common/lib';
34
+ export {
35
+ preprocessMarkdownSource,
36
+ linkProfileMentions,
37
+ isExternalLink,
38
+ toGotoUrl,
39
+ } from '@openpeepshq/common/lib';
40
+
30
41
  export * from './hooks';
31
42
  export { useDefaultVisibility } from './components/post/visibility';
32
43
  export {
@@ -81,6 +92,7 @@ export {
81
92
  useNewPostStores,
82
93
  resetStore,
83
94
  defaultNewArticle,
95
+ defaultNewResource,
84
96
  defaultNewEvent,
85
97
  defaultNewNote,
86
98
  defaultNewQuestion,
@@ -24,6 +24,7 @@ export {
24
24
  useNewPostStores,
25
25
  resetStore,
26
26
  defaultNewArticle,
27
+ defaultNewResource,
27
28
  defaultNewEvent,
28
29
  defaultNewNote,
29
30
  defaultNewQuestion,
@@ -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 five sub-stores so any write triggers a re-render.
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
  }
@@ -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;