@tribe-nest/forge 1.13.0

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 (255) hide show
  1. package/package.json +42 -0
  2. package/src/client/createForgeClient.ts +54 -0
  3. package/src/content/ForgeContentProvider.tsx +118 -0
  4. package/src/content/ForgeEditBridge.tsx +134 -0
  5. package/src/content/editFlag.ts +23 -0
  6. package/src/content/index.ts +28 -0
  7. package/src/content/resolve.ts +67 -0
  8. package/src/content/types.ts +97 -0
  9. package/src/content/useField.ts +64 -0
  10. package/src/contexts/AppAuthContext.tsx +185 -0
  11. package/src/contexts/AudioPlayerContext.tsx +389 -0
  12. package/src/contexts/CartContext.tsx +131 -0
  13. package/src/contexts/PublicAuthContext.tsx +333 -0
  14. package/src/contexts/useAppAdminGuard.ts +56 -0
  15. package/src/css.d.ts +5 -0
  16. package/src/data/collectionParams.ts +57 -0
  17. package/src/data/queries/useAccount.ts +71 -0
  18. package/src/data/queries/useAccountSettings.ts +82 -0
  19. package/src/data/queries/useAnalytics.ts +86 -0
  20. package/src/data/queries/useAuthActions.ts +28 -0
  21. package/src/data/queries/useBlog.ts +103 -0
  22. package/src/data/queries/useBlogComments.ts +96 -0
  23. package/src/data/queries/useBroadcasts.ts +31 -0
  24. package/src/data/queries/useCertificates.ts +58 -0
  25. package/src/data/queries/useChat.ts +267 -0
  26. package/src/data/queries/useCoachingAvailability.ts +69 -0
  27. package/src/data/queries/useCoachingProducts.ts +67 -0
  28. package/src/data/queries/useCohortPage.ts +17 -0
  29. package/src/data/queries/useCollections.ts +211 -0
  30. package/src/data/queries/useCommunity.ts +794 -0
  31. package/src/data/queries/useCoupons.ts +20 -0
  32. package/src/data/queries/useCourseAccess.ts +50 -0
  33. package/src/data/queries/useCourses.ts +91 -0
  34. package/src/data/queries/useCurrencies.ts +33 -0
  35. package/src/data/queries/useDocuments.ts +208 -0
  36. package/src/data/queries/useDonations.ts +29 -0
  37. package/src/data/queries/useEngagement.ts +115 -0
  38. package/src/data/queries/useEvents.ts +69 -0
  39. package/src/data/queries/useFinalize.ts +109 -0
  40. package/src/data/queries/useForms.ts +31 -0
  41. package/src/data/queries/useInvoice.ts +65 -0
  42. package/src/data/queries/useLeadMagnet.ts +96 -0
  43. package/src/data/queries/useMembership.ts +20 -0
  44. package/src/data/queries/useNotifications.ts +267 -0
  45. package/src/data/queries/useOffers.ts +56 -0
  46. package/src/data/queries/useOrders.ts +71 -0
  47. package/src/data/queries/usePWA.ts +101 -0
  48. package/src/data/queries/usePageActions.ts +36 -0
  49. package/src/data/queries/usePaymentFlow.ts +80 -0
  50. package/src/data/queries/usePaymentLink.ts +47 -0
  51. package/src/data/queries/usePodcast.ts +85 -0
  52. package/src/data/queries/usePostCollections.ts +48 -0
  53. package/src/data/queries/usePosts.ts +94 -0
  54. package/src/data/queries/useProducts.ts +108 -0
  55. package/src/data/queries/useReplay.ts +19 -0
  56. package/src/data/queries/useReviews.ts +122 -0
  57. package/src/data/queries/useShipping.ts +109 -0
  58. package/src/data/queries/useSubscriptions.ts +66 -0
  59. package/src/data/queries/useWebsite.ts +128 -0
  60. package/src/data/queries/useWebsiteAgent.ts +100 -0
  61. package/src/index.ts +98 -0
  62. package/src/provider/ForgeAppProvider.tsx +149 -0
  63. package/src/provider/ForgeProvider.tsx +91 -0
  64. package/src/provider/SiteConfigProvider.tsx +27 -0
  65. package/src/server/_tests/buildPwaHead.spec.ts +182 -0
  66. package/src/server/_tests/buildWebManifest.spec.ts +313 -0
  67. package/src/server/_tests/forgeServiceWorkerScript.spec.ts +251 -0
  68. package/src/server/index.ts +260 -0
  69. package/src/server/jobs.ts +104 -0
  70. package/src/server/pwa.ts +332 -0
  71. package/src/types/index.ts +74 -0
  72. package/src/types/models.ts +1313 -0
  73. package/src/ui/analytics/ForgeAnalytics.tsx +208 -0
  74. package/src/ui/analytics/PageMetaPixel.tsx +92 -0
  75. package/src/ui/content/Editable.tsx +90 -0
  76. package/src/ui/format/PriceDisplay.tsx +142 -0
  77. package/src/ui/format/useFormatCurrency.ts +92 -0
  78. package/src/ui/headless/agent/useAiAgent.ts +106 -0
  79. package/src/ui/headless/auth/useLoginFlow.ts +72 -0
  80. package/src/ui/headless/auth/useSignupForm.ts +85 -0
  81. package/src/ui/headless/broadcast/useBroadcastWatch.ts +59 -0
  82. package/src/ui/headless/chat/attachmentKind.ts +27 -0
  83. package/src/ui/headless/chat/useChatAttachmentUpload.ts +132 -0
  84. package/src/ui/headless/chat/useChatRoom.ts +223 -0
  85. package/src/ui/headless/chat/useMessageThread.ts +60 -0
  86. package/src/ui/headless/checkout/useCheckout.ts +438 -0
  87. package/src/ui/headless/coaching/useCoachingBooking.ts +223 -0
  88. package/src/ui/headless/community/index.ts +20 -0
  89. package/src/ui/headless/community/lexical.ts +131 -0
  90. package/src/ui/headless/community/replyTree.ts +51 -0
  91. package/src/ui/headless/community/richLexical.ts +314 -0
  92. package/src/ui/headless/community/useCommunityAttachmentUpload.ts +137 -0
  93. package/src/ui/headless/community/useCommunitySpaceFeed.ts +122 -0
  94. package/src/ui/headless/community/useCommunityThread.ts +95 -0
  95. package/src/ui/headless/community/useMentionComposer.ts +105 -0
  96. package/src/ui/headless/community/useRichMentionComposer.ts +193 -0
  97. package/src/ui/headless/consent/useCookieConsent.ts +81 -0
  98. package/src/ui/headless/course/useCourseCheckout.ts +99 -0
  99. package/src/ui/headless/dialog.tsx +14 -0
  100. package/src/ui/headless/document/index.ts +7 -0
  101. package/src/ui/headless/document/useContractSignature.ts +68 -0
  102. package/src/ui/headless/document/useDocumentSigningFlow.ts +92 -0
  103. package/src/ui/headless/document/useOtpCodeInput.ts +86 -0
  104. package/src/ui/headless/document/useSignaturePad.ts +180 -0
  105. package/src/ui/headless/donation/Donation.tsx +115 -0
  106. package/src/ui/headless/donation/DonationContext.tsx +223 -0
  107. package/src/ui/headless/donation/fees.ts +15 -0
  108. package/src/ui/headless/donation/index.ts +10 -0
  109. package/src/ui/headless/engagement/usePostEngagement.ts +119 -0
  110. package/src/ui/headless/event/useEventCheckout.ts +141 -0
  111. package/src/ui/headless/forms/useContactForm.ts +58 -0
  112. package/src/ui/headless/forms/useEmailListForm.ts +75 -0
  113. package/src/ui/headless/forms/useSectionedForm.ts +256 -0
  114. package/src/ui/headless/index.ts +60 -0
  115. package/src/ui/headless/invoice/useInvoicePayment.ts +48 -0
  116. package/src/ui/headless/memberHome/index.ts +7 -0
  117. package/src/ui/headless/memberHome/useMemberHomeNav.ts +82 -0
  118. package/src/ui/headless/membership/MembershipGate.tsx +39 -0
  119. package/src/ui/headless/membership/useMembershipCheckout.ts +121 -0
  120. package/src/ui/headless/offer/Offer.tsx +88 -0
  121. package/src/ui/headless/offer/OfferContext.tsx +162 -0
  122. package/src/ui/headless/offer/index.ts +8 -0
  123. package/src/ui/headless/paymentLink/usePaymentLinkPayment.ts +46 -0
  124. package/src/ui/headless/podcast/usePodcastPlayer.ts +96 -0
  125. package/src/ui/headless/posts/index.ts +13 -0
  126. package/src/ui/headless/posts/upsell.ts +41 -0
  127. package/src/ui/headless/posts/useMemberPostsFeed.ts +110 -0
  128. package/src/ui/headless/posts/usePostCollectionDetail.ts +56 -0
  129. package/src/ui/headless/posts/usePostCollectionsList.ts +90 -0
  130. package/src/ui/headless/posts/usePostItem.ts +81 -0
  131. package/src/ui/headless/reviews/index.ts +6 -0
  132. package/src/ui/headless/reviews/useHelpfulVote.ts +45 -0
  133. package/src/ui/headless/reviews/useReviewForm.ts +108 -0
  134. package/src/ui/headless/reviews/useReviewsList.ts +79 -0
  135. package/src/ui/headless/work/index.ts +25 -0
  136. package/src/ui/headless/work/useWorkPortal.ts +349 -0
  137. package/src/ui/index.ts +144 -0
  138. package/src/ui/payment/ForgePaymentProvider.tsx +45 -0
  139. package/src/ui/payment/ForgeStripePayment.tsx +171 -0
  140. package/src/ui/shell/TribeNestApp.tsx +121 -0
  141. package/src/ui/shell/shellGating.spec.ts +28 -0
  142. package/src/ui/shell/shellGating.ts +11 -0
  143. package/src/ui/styled/AccountDashboard.tsx +575 -0
  144. package/src/ui/styled/AiAgentWidget.tsx +152 -0
  145. package/src/ui/styled/AudioPlayer.tsx +123 -0
  146. package/src/ui/styled/BlogCategory.tsx +79 -0
  147. package/src/ui/styled/BlogComments.tsx +236 -0
  148. package/src/ui/styled/BlogList.tsx +101 -0
  149. package/src/ui/styled/BlogPost.tsx +160 -0
  150. package/src/ui/styled/BlogPostFooter.tsx +33 -0
  151. package/src/ui/styled/BotProtection.tsx +101 -0
  152. package/src/ui/styled/Button.tsx +88 -0
  153. package/src/ui/styled/Cart.tsx +276 -0
  154. package/src/ui/styled/ChatRoom.tsx +252 -0
  155. package/src/ui/styled/Checkout.tsx +988 -0
  156. package/src/ui/styled/CheckoutConfirmation.tsx +452 -0
  157. package/src/ui/styled/CoachingBooking.tsx +605 -0
  158. package/src/ui/styled/CoachingConfirmation.tsx +151 -0
  159. package/src/ui/styled/CoachingDetail.tsx +99 -0
  160. package/src/ui/styled/CohortPage.tsx +82 -0
  161. package/src/ui/styled/ConfirmSubscription.tsx +134 -0
  162. package/src/ui/styled/Confirmation.tsx +171 -0
  163. package/src/ui/styled/ContactForm.tsx +81 -0
  164. package/src/ui/styled/CookieConsent.tsx +239 -0
  165. package/src/ui/styled/CourseAccess.tsx +169 -0
  166. package/src/ui/styled/CourseCheckout.tsx +425 -0
  167. package/src/ui/styled/CourseConfirmation.tsx +191 -0
  168. package/src/ui/styled/CourseDetail.tsx +140 -0
  169. package/src/ui/styled/CoursesGrid.tsx +85 -0
  170. package/src/ui/styled/CurrencySwitcher.tsx +51 -0
  171. package/src/ui/styled/DonationButton.tsx +247 -0
  172. package/src/ui/styled/DonationPage.tsx +29 -0
  173. package/src/ui/styled/EmailListForm.tsx +88 -0
  174. package/src/ui/styled/EventConfirmation.tsx +228 -0
  175. package/src/ui/styled/EventCountdown.tsx +98 -0
  176. package/src/ui/styled/EventDetail.tsx +141 -0
  177. package/src/ui/styled/EventTickets.tsx +548 -0
  178. package/src/ui/styled/EventsList.tsx +83 -0
  179. package/src/ui/styled/ForgotPasswordForm.tsx +105 -0
  180. package/src/ui/styled/FormRenderer.tsx +249 -0
  181. package/src/ui/styled/InstallBanner.tsx +114 -0
  182. package/src/ui/styled/InvoiceConfirmation.tsx +50 -0
  183. package/src/ui/styled/InvoicePayment.tsx +141 -0
  184. package/src/ui/styled/LeadMagnet.tsx +93 -0
  185. package/src/ui/styled/Loading.tsx +56 -0
  186. package/src/ui/styled/LoginForm.tsx +134 -0
  187. package/src/ui/styled/Markdown.tsx +103 -0
  188. package/src/ui/styled/MembershipCheckout.tsx +197 -0
  189. package/src/ui/styled/MembershipTiers.tsx +115 -0
  190. package/src/ui/styled/OfferButton.tsx +181 -0
  191. package/src/ui/styled/PageActions.tsx +124 -0
  192. package/src/ui/styled/PaymentLinkConfirmation.tsx +50 -0
  193. package/src/ui/styled/PaymentLinkPayment.tsx +85 -0
  194. package/src/ui/styled/Paywall.tsx +54 -0
  195. package/src/ui/styled/PlayButton.tsx +48 -0
  196. package/src/ui/styled/PodcastEpisode.tsx +137 -0
  197. package/src/ui/styled/PodcastList.tsx +58 -0
  198. package/src/ui/styled/PodcastShow.tsx +164 -0
  199. package/src/ui/styled/PostsFeed.tsx +63 -0
  200. package/src/ui/styled/ProductDetail.tsx +616 -0
  201. package/src/ui/styled/ProductGrid.tsx +82 -0
  202. package/src/ui/styled/PushOptIn.tsx +65 -0
  203. package/src/ui/styled/PwaRegistration.tsx +58 -0
  204. package/src/ui/styled/ReactionBar.tsx +93 -0
  205. package/src/ui/styled/ReplayList.tsx +134 -0
  206. package/src/ui/styled/ResetPasswordForm.tsx +127 -0
  207. package/src/ui/styled/ReviewForm.tsx +292 -0
  208. package/src/ui/styled/ReviewsSection.tsx +260 -0
  209. package/src/ui/styled/SectionedFormRenderer.tsx +146 -0
  210. package/src/ui/styled/SignupForm.tsx +109 -0
  211. package/src/ui/styled/UserMenu.tsx +166 -0
  212. package/src/ui/styled/chat/ChatAttachments.tsx +172 -0
  213. package/src/ui/styled/chat/ChatComposer.tsx +153 -0
  214. package/src/ui/styled/chat/ChatThreadPanel.tsx +94 -0
  215. package/src/ui/styled/chat/MessageBubble.tsx +66 -0
  216. package/src/ui/styled/chat/NewDmDialog.tsx +78 -0
  217. package/src/ui/styled/community/CommunityComposer.tsx +358 -0
  218. package/src/ui/styled/community/CommunityFeed.tsx +483 -0
  219. package/src/ui/styled/community/CommunityLeaderboard.tsx +109 -0
  220. package/src/ui/styled/community/CommunityMediaGallery.tsx +116 -0
  221. package/src/ui/styled/community/CommunityMemberProfile.tsx +285 -0
  222. package/src/ui/styled/community/CommunityNotifications.tsx +222 -0
  223. package/src/ui/styled/community/CommunityPostCard.tsx +165 -0
  224. package/src/ui/styled/community/CommunityPostDetail.tsx +337 -0
  225. package/src/ui/styled/community/CommunityReactionBar.tsx +107 -0
  226. package/src/ui/styled/community/CommunityRichText.tsx +157 -0
  227. package/src/ui/styled/community/CommunitySpaces.tsx +174 -0
  228. package/src/ui/styled/community/MemberAvatar.tsx +74 -0
  229. package/src/ui/styled/community/index.ts +23 -0
  230. package/src/ui/styled/community/util.ts +15 -0
  231. package/src/ui/styled/members/MemberHomeLayout.tsx +98 -0
  232. package/src/ui/styled/members/MemberPostCard.tsx +392 -0
  233. package/src/ui/styled/members/MemberPostsFeed.tsx +219 -0
  234. package/src/ui/styled/members/PostCollectionDetail.tsx +227 -0
  235. package/src/ui/styled/members/PostCollectionsGrid.tsx +287 -0
  236. package/src/ui/styled/members/index.ts +7 -0
  237. package/src/ui/styled/rich-text.css +150 -0
  238. package/src/ui/styled/work/WorkInviteAccept.tsx +222 -0
  239. package/src/ui/styled/work/WorkPortalProjects.tsx +163 -0
  240. package/src/ui/styled/work/WorkProjectInvoices.tsx +113 -0
  241. package/src/ui/styled/work/WorkProjectReport.tsx +66 -0
  242. package/src/ui/styled/work/WorkReportBody.tsx +327 -0
  243. package/src/ui/styled/work/WorkTaskAttachments.tsx +67 -0
  244. package/src/ui/styled/work/WorkTaskComments.tsx +151 -0
  245. package/src/ui/styled/work/WorkTaskDetail.tsx +92 -0
  246. package/src/ui/styled/work/WorkTokenReport.tsx +49 -0
  247. package/src/ui/styled/work/index.ts +10 -0
  248. package/src/ui/theme/ForgeThemeProvider.tsx +121 -0
  249. package/src/ui/theme/contrast.ts +22 -0
  250. package/src/utils/analyticsBus.ts +31 -0
  251. package/src/utils/attribution.ts +68 -0
  252. package/src/utils/cookieConsent.ts +83 -0
  253. package/src/utils/landing.ts +153 -0
  254. package/src/utils/metaPixel.ts +122 -0
  255. package/src/utils/structuredData.ts +126 -0
@@ -0,0 +1,165 @@
1
+ import { Lock, MessageCircle, Pin } from "lucide-react";
2
+ import { useThemeTokens } from "../../theme/ForgeThemeProvider";
3
+ import { communityMemberName, type CommunityPost } from "../../../data/queries/useCommunity";
4
+ import { CommunityRichText } from "./CommunityRichText";
5
+ import { CommunityMediaGallery } from "./CommunityMediaGallery";
6
+ import { CommunityReactionBar } from "./CommunityReactionBar";
7
+ import { LevelBadge, MemberAvatar } from "./MemberAvatar";
8
+ import { timeAgo } from "./util";
9
+
10
+ export interface CommunityPostCardProps {
11
+ post: CommunityPost;
12
+ /** "feed" renders the full body inline; "forum" renders a compact title row. */
13
+ variant: "feed" | "forum";
14
+ onOpen?: (post: CommunityPost) => void;
15
+ onOpenProfile?: (accountId: string) => void;
16
+ onReact?: (emoji: string) => void;
17
+ }
18
+
19
+ /** One post in a space — card (feed spaces) or compact row (forum spaces). */
20
+ export function CommunityPostCard({ post, variant, onOpen, onOpenProfile, onReact }: CommunityPostCardProps) {
21
+ const t = useThemeTokens();
22
+ const border = `1px solid ${t.border}`;
23
+ const author = post.author;
24
+
25
+ const meta = (
26
+ <div style={{ display: "flex", alignItems: "center", gap: 8, minWidth: 0 }}>
27
+ <MemberAvatar member={author} size={variant === "feed" ? 36 : 28} onClick={() => author && onOpenProfile?.(author.accountId)} />
28
+ <div style={{ minWidth: 0 }}>
29
+ <div style={{ display: "flex", alignItems: "center", gap: 6 }}>
30
+ <button
31
+ onClick={() => author && onOpenProfile?.(author.accountId)}
32
+ style={{
33
+ background: "none",
34
+ border: "none",
35
+ padding: 0,
36
+ cursor: "pointer",
37
+ color: t.text,
38
+ fontWeight: 600,
39
+ fontSize: 14,
40
+ whiteSpace: "nowrap",
41
+ overflow: "hidden",
42
+ textOverflow: "ellipsis",
43
+ }}
44
+ >
45
+ {communityMemberName(author)}
46
+ </button>
47
+ <LevelBadge level={author?.level} />
48
+ {author?.role === "moderator" && (
49
+ <span style={{ fontSize: 10, fontWeight: 700, color: t.muted, textTransform: "uppercase" }}>Mod</span>
50
+ )}
51
+ </div>
52
+ <div style={{ fontSize: 12, color: t.muted }}>{timeAgo(post.createdAt)}</div>
53
+ </div>
54
+ </div>
55
+ );
56
+
57
+ const badges = (
58
+ <span style={{ display: "inline-flex", gap: 6, alignItems: "center" }}>
59
+ {post.isPinned && <Pin size={14} style={{ color: t.primary }} aria-label="Pinned" />}
60
+ {post.isLocked && <Lock size={14} style={{ color: t.muted }} aria-label="Locked" />}
61
+ </span>
62
+ );
63
+
64
+ if (variant === "forum") {
65
+ return (
66
+ <div
67
+ style={{
68
+ border,
69
+ borderRadius: t.cornerRadius,
70
+ background: t.surface,
71
+ padding: "10px 14px",
72
+ display: "flex",
73
+ alignItems: "center",
74
+ gap: 12,
75
+ }}
76
+ >
77
+ <div style={{ flex: 1, minWidth: 0 }}>
78
+ <button
79
+ onClick={() => onOpen?.(post)}
80
+ style={{
81
+ background: "none",
82
+ border: "none",
83
+ padding: 0,
84
+ cursor: "pointer",
85
+ color: t.text,
86
+ fontWeight: 700,
87
+ fontSize: 15,
88
+ textAlign: "left",
89
+ display: "flex",
90
+ alignItems: "center",
91
+ gap: 6,
92
+ }}
93
+ >
94
+ {badges}
95
+ <span style={{ overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>
96
+ {post.title || post.bodyText?.slice(0, 80) || "Untitled"}
97
+ </span>
98
+ </button>
99
+ <div style={{ display: "flex", alignItems: "center", gap: 8, marginTop: 4, fontSize: 12, color: t.muted }}>
100
+ <span>{communityMemberName(author)}</span>
101
+ <span>·</span>
102
+ <span>{timeAgo(post.lastActivityAt ?? post.createdAt)}</span>
103
+ </div>
104
+ </div>
105
+ <div style={{ display: "flex", alignItems: "center", gap: 12, fontSize: 13, color: t.muted, flexShrink: 0 }}>
106
+ <span style={{ display: "inline-flex", alignItems: "center", gap: 4 }}>
107
+ <MessageCircle size={14} /> {post.replyCount}
108
+ </span>
109
+ <span>{post.reactionCount > 0 ? `${post.reactionCount} 👍` : ""}</span>
110
+ </div>
111
+ </div>
112
+ );
113
+ }
114
+
115
+ return (
116
+ <article style={{ border, borderRadius: t.cornerRadius, background: t.surface, padding: 16 }}>
117
+ <header style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8 }}>
118
+ {meta}
119
+ {badges}
120
+ </header>
121
+
122
+ {post.title && (
123
+ <h3
124
+ onClick={() => onOpen?.(post)}
125
+ style={{
126
+ margin: "10px 0 4px",
127
+ fontSize: 17,
128
+ fontFamily: t.headingFontFamily,
129
+ color: t.text,
130
+ cursor: onOpen ? "pointer" : undefined,
131
+ }}
132
+ >
133
+ {post.title}
134
+ </h3>
135
+ )}
136
+
137
+ <div style={{ marginTop: post.title ? 0 : 10 }}>
138
+ <CommunityRichText body={post.body} clampLines={8} />
139
+ </div>
140
+ <CommunityMediaGallery media={post.media ?? []} />
141
+
142
+ <footer style={{ marginTop: 12 }}>
143
+ <CommunityReactionBar reactions={post.reactions ?? []} onToggle={(emoji) => onReact?.(emoji)}>
144
+ <button
145
+ onClick={() => onOpen?.(post)}
146
+ style={{
147
+ display: "inline-flex",
148
+ alignItems: "center",
149
+ gap: 4,
150
+ background: "none",
151
+ border: "none",
152
+ cursor: "pointer",
153
+ color: t.muted,
154
+ fontSize: 13,
155
+ padding: "2px 4px",
156
+ }}
157
+ >
158
+ <MessageCircle size={14} />
159
+ {post.replyCount > 0 ? `${post.replyCount} ${post.replyCount === 1 ? "reply" : "replies"}` : "Reply"}
160
+ </button>
161
+ </CommunityReactionBar>
162
+ </footer>
163
+ </article>
164
+ );
165
+ }
@@ -0,0 +1,337 @@
1
+ import { useMemo, useState } from "react";
2
+ import { Flag, Lock } from "lucide-react";
3
+ import { useThemeTokens } from "../../theme/ForgeThemeProvider";
4
+ import { useCommunityThread } from "../../headless/community/useCommunityThread";
5
+ import { findReplyNode, type ReplyNode } from "../../headless/community/replyTree";
6
+ import {
7
+ communityMemberName,
8
+ useReportCommunityContent,
9
+ type CommunityReply,
10
+ } from "../../../data/queries/useCommunity";
11
+ import { Loading } from "../Loading";
12
+ import { CommunityComposer } from "./CommunityComposer";
13
+ import { CommunityMediaGallery } from "./CommunityMediaGallery";
14
+ import { CommunityReactionBar } from "./CommunityReactionBar";
15
+ import { CommunityRichText } from "./CommunityRichText";
16
+ import { LevelBadge, MemberAvatar } from "./MemberAvatar";
17
+ import { timeAgo } from "./util";
18
+
19
+ /** How many nesting levels are RENDERED before "Continue this thread". The
20
+ * data model nests without limit; this is purely a display cap. */
21
+ export const REPLY_DISPLAY_DEPTH = 3;
22
+
23
+ export interface CommunityPostDetailProps {
24
+ postId: string;
25
+ onOpenProfile?: (accountId: string) => void;
26
+ /** Receives the post's spaceId so "back" returns to that space's feed
27
+ * (not the spaces list). May be undefined before the post loads. */
28
+ onBack?: (spaceId?: string) => void;
29
+ }
30
+
31
+ /** Full post view: rich body + media, reactions, and the nested reply thread. */
32
+ export function CommunityPostDetail({ postId, onOpenProfile, onBack }: CommunityPostDetailProps) {
33
+ const t = useThemeTokens();
34
+ const thread = useCommunityThread(postId);
35
+ const report = useReportCommunityContent();
36
+ const border = `1px solid ${t.border}`;
37
+
38
+ // "Continue thread" re-roots the rendered tree on a deep reply (Reddit-style).
39
+ const [threadRootId, setThreadRootId] = useState<string | null>(null);
40
+ const [replyingTo, setReplyingTo] = useState<string | null>(null);
41
+ const [reported, setReported] = useState<Set<string>>(new Set());
42
+
43
+ const visibleTree = useMemo(() => {
44
+ if (!threadRootId) return thread.replyTree;
45
+ const node = findReplyNode(thread.replyTree, threadRootId);
46
+ return node ? [node] : thread.replyTree;
47
+ }, [thread.replyTree, threadRootId]);
48
+
49
+ if (thread.postLoading) return <Loading />;
50
+
51
+ if (!thread.post) {
52
+ return (
53
+ <div style={{ border, borderRadius: t.cornerRadius, padding: 32, textAlign: "center", color: t.muted }}>
54
+ This post is unavailable.
55
+ </div>
56
+ );
57
+ }
58
+
59
+ const post = thread.post;
60
+ const locked = post.isLocked;
61
+
62
+ const doReport = (entityId: string, entityType: "community_post" | "community_reply") => {
63
+ if (reported.has(entityId)) return;
64
+ report.mutate(
65
+ { entityId, entityType },
66
+ { onSuccess: () => setReported((prev) => new Set(prev).add(entityId)) },
67
+ );
68
+ };
69
+
70
+ const reportButton = (entityId: string, entityType: "community_post" | "community_reply") => (
71
+ <button
72
+ onClick={() => doReport(entityId, entityType)}
73
+ title={reported.has(entityId) ? "Reported" : "Report to moderators"}
74
+ style={{
75
+ display: "inline-flex",
76
+ alignItems: "center",
77
+ gap: 4,
78
+ background: "none",
79
+ border: "none",
80
+ cursor: reported.has(entityId) ? "default" : "pointer",
81
+ color: t.muted,
82
+ fontSize: 12,
83
+ padding: "2px 4px",
84
+ opacity: reported.has(entityId) ? 0.6 : 1,
85
+ }}
86
+ >
87
+ <Flag size={12} />
88
+ {reported.has(entityId) ? "Reported" : "Report"}
89
+ </button>
90
+ );
91
+
92
+ const submitReply = async (input: {
93
+ body: unknown;
94
+ attachments: { url: string; type: "image" | "video" | "audio" | "document" | "other"; size: number; name?: string }[];
95
+ mentionedAccountIds: string[];
96
+ }) => {
97
+ await thread.createReply.mutateAsync({
98
+ body: input.body,
99
+ attachments: input.attachments,
100
+ mentionedAccountIds: input.mentionedAccountIds,
101
+ parentReplyId: replyingTo ?? undefined,
102
+ });
103
+ setReplyingTo(null);
104
+ };
105
+
106
+ const renderNode = (node: ReplyNode, renderedDepth: number): React.ReactNode => {
107
+ const reply = node.reply;
108
+ const capped = renderedDepth >= REPLY_DISPLAY_DEPTH - 1 && node.children.length > 0;
109
+
110
+ return (
111
+ <div key={reply.id} style={{ display: "flex", flexDirection: "column", gap: 8 }}>
112
+ <ReplyItem
113
+ reply={reply}
114
+ onOpenProfile={onOpenProfile}
115
+ onReact={(emoji) => thread.react("community_reply", reply.id, emoji)}
116
+ extraActions={
117
+ <>
118
+ {!locked && (
119
+ <button
120
+ onClick={() => setReplyingTo((prev) => (prev === reply.id ? null : reply.id))}
121
+ style={{
122
+ background: "none",
123
+ border: "none",
124
+ cursor: "pointer",
125
+ color: t.muted,
126
+ fontSize: 12,
127
+ padding: "2px 4px",
128
+ }}
129
+ >
130
+ Reply
131
+ </button>
132
+ )}
133
+ {reportButton(reply.id, "community_reply")}
134
+ </>
135
+ }
136
+ />
137
+
138
+ {replyingTo === reply.id && (
139
+ <div style={{ marginLeft: 44 }}>
140
+ <CommunityComposer
141
+ compact
142
+ autoFocus
143
+ placeholder={`Reply to ${communityMemberName(reply.author)}…`}
144
+ submitLabel="Reply"
145
+ onSubmit={submitReply}
146
+ onCancel={() => setReplyingTo(null)}
147
+ />
148
+ </div>
149
+ )}
150
+
151
+ {node.children.length > 0 && !capped && (
152
+ <div style={{ marginLeft: 20, paddingLeft: 16, borderLeft: `2px solid ${t.border}`, display: "flex", flexDirection: "column", gap: 8 }}>
153
+ {node.children.map((child) => renderNode(child, renderedDepth + 1))}
154
+ </div>
155
+ )}
156
+
157
+ {capped && (
158
+ <button
159
+ onClick={() => setThreadRootId(reply.id)}
160
+ style={{
161
+ alignSelf: "flex-start",
162
+ marginLeft: 44,
163
+ background: "none",
164
+ border: "none",
165
+ cursor: "pointer",
166
+ color: t.primary,
167
+ fontSize: 13,
168
+ fontWeight: 600,
169
+ padding: 0,
170
+ }}
171
+ >
172
+ Continue this thread ({countDescendants(node)} more) →
173
+ </button>
174
+ )}
175
+ </div>
176
+ );
177
+ };
178
+
179
+ return (
180
+ <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
181
+ {onBack && (
182
+ <button
183
+ onClick={() => onBack(thread.post?.spaceId)}
184
+ style={{
185
+ alignSelf: "flex-start",
186
+ background: "none",
187
+ border: "none",
188
+ cursor: "pointer",
189
+ color: t.text,
190
+ fontSize: 14,
191
+ padding: 0,
192
+ }}
193
+ >
194
+ ← Back
195
+ </button>
196
+ )}
197
+
198
+ {/* Post */}
199
+ <article style={{ border, borderRadius: t.cornerRadius, background: t.surface, padding: 18 }}>
200
+ <header style={{ display: "flex", alignItems: "center", gap: 10 }}>
201
+ <MemberAvatar member={post.author} size={40} onClick={() => post.author && onOpenProfile?.(post.author.accountId)} />
202
+ <div style={{ minWidth: 0, flex: 1 }}>
203
+ <div style={{ display: "flex", alignItems: "center", gap: 6 }}>
204
+ <button
205
+ onClick={() => post.author && onOpenProfile?.(post.author.accountId)}
206
+ style={{ background: "none", border: "none", padding: 0, cursor: "pointer", color: t.text, fontWeight: 700, fontSize: 15 }}
207
+ >
208
+ {communityMemberName(post.author)}
209
+ </button>
210
+ <LevelBadge level={post.author?.level} />
211
+ </div>
212
+ <div style={{ fontSize: 12, color: t.muted }}>{timeAgo(post.createdAt)}</div>
213
+ </div>
214
+ {locked && (
215
+ <span style={{ display: "inline-flex", alignItems: "center", gap: 4, fontSize: 12, color: t.muted }}>
216
+ <Lock size={12} /> Locked
217
+ </span>
218
+ )}
219
+ </header>
220
+
221
+ {post.title && (
222
+ <h2 style={{ margin: "12px 0 6px", fontSize: 20, fontFamily: t.headingFontFamily, color: t.text }}>{post.title}</h2>
223
+ )}
224
+ <div style={{ marginTop: post.title ? 0 : 12 }}>
225
+ <CommunityRichText body={post.body} />
226
+ </div>
227
+ <CommunityMediaGallery media={post.media ?? []} />
228
+
229
+ <footer style={{ marginTop: 14 }}>
230
+ <CommunityReactionBar reactions={post.reactions ?? []} onToggle={(emoji) => thread.react("community_post", post.id, emoji)}>
231
+ {reportButton(post.id, "community_post")}
232
+ </CommunityReactionBar>
233
+ </footer>
234
+ </article>
235
+
236
+ {/* Top-level composer */}
237
+ {locked ? (
238
+ <div style={{ border, borderRadius: t.cornerRadius, padding: 14, textAlign: "center", color: t.muted, fontSize: 14 }}>
239
+ <Lock size={13} style={{ verticalAlign: -2, marginRight: 6 }} />
240
+ This post is locked — replies are closed.
241
+ </div>
242
+ ) : (
243
+ !replyingTo && <CommunityComposer compact placeholder="Write a reply…" submitLabel="Reply" onSubmit={submitReply} />
244
+ )}
245
+
246
+ {/* Thread */}
247
+ <section style={{ display: "flex", flexDirection: "column", gap: 10 }}>
248
+ <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
249
+ <h3 style={{ margin: 0, fontSize: 15, color: t.text }}>
250
+ {post.replyCount} {post.replyCount === 1 ? "reply" : "replies"}
251
+ </h3>
252
+ {threadRootId && (
253
+ <button
254
+ onClick={() => setThreadRootId(null)}
255
+ style={{ background: "none", border: "none", cursor: "pointer", color: t.primary, fontSize: 13, fontWeight: 600 }}
256
+ >
257
+ ← View full thread
258
+ </button>
259
+ )}
260
+ </div>
261
+
262
+ {thread.repliesLoading && !thread.replies.length ? (
263
+ <Loading />
264
+ ) : (
265
+ <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
266
+ {visibleTree.map((node) => renderNode(node, threadRootId ? 0 : node.depth))}
267
+ </div>
268
+ )}
269
+
270
+ {thread.hasMore && (
271
+ <button
272
+ onClick={() => thread.fetchNextPage()}
273
+ style={{
274
+ alignSelf: "center",
275
+ background: "none",
276
+ border,
277
+ borderRadius: t.cornerRadius,
278
+ padding: "6px 14px",
279
+ cursor: "pointer",
280
+ color: t.text,
281
+ fontSize: 13,
282
+ }}
283
+ >
284
+ Load more replies
285
+ </button>
286
+ )}
287
+ </section>
288
+ </div>
289
+ );
290
+ }
291
+
292
+ function countDescendants(node: ReplyNode): number {
293
+ return node.children.reduce((n, child) => n + 1 + countDescendants(child), 0);
294
+ }
295
+
296
+ function ReplyItem({
297
+ reply,
298
+ onOpenProfile,
299
+ onReact,
300
+ extraActions,
301
+ }: {
302
+ reply: CommunityReply;
303
+ onOpenProfile?: (accountId: string) => void;
304
+ onReact: (emoji: string) => void;
305
+ extraActions?: React.ReactNode;
306
+ }) {
307
+ const t = useThemeTokens();
308
+
309
+ return (
310
+ <div style={{ display: "flex", gap: 10 }}>
311
+ <MemberAvatar member={reply.author} size={32} onClick={() => reply.author && onOpenProfile?.(reply.author.accountId)} />
312
+ <div style={{ flex: 1, minWidth: 0 }}>
313
+ <div style={{ display: "flex", alignItems: "center", gap: 6 }}>
314
+ <button
315
+ onClick={() => reply.author && onOpenProfile?.(reply.author.accountId)}
316
+ style={{ background: "none", border: "none", padding: 0, cursor: "pointer", color: t.text, fontWeight: 600, fontSize: 13 }}
317
+ >
318
+ {communityMemberName(reply.author)}
319
+ </button>
320
+ <LevelBadge level={reply.author?.level} />
321
+ <span style={{ fontSize: 11, color: t.muted }}>{timeAgo(reply.createdAt)}</span>
322
+ </div>
323
+
324
+ <div style={{ marginTop: 2 }}>
325
+ <CommunityRichText body={reply.body} />
326
+ </div>
327
+ <CommunityMediaGallery media={reply.media ?? []} />
328
+
329
+ <div style={{ marginTop: 6 }}>
330
+ <CommunityReactionBar reactions={reply.reactions ?? []} onToggle={onReact}>
331
+ {extraActions}
332
+ </CommunityReactionBar>
333
+ </div>
334
+ </div>
335
+ </div>
336
+ );
337
+ }
@@ -0,0 +1,107 @@
1
+ import { useState } from "react";
2
+ import { useThemeTokens } from "../../theme/ForgeThemeProvider";
3
+ import type { ReactionSummary } from "../../../data/queries/useCommunity";
4
+
5
+ /** The default quick-reaction set (👍 doubles as the legacy "like"). */
6
+ export const COMMUNITY_REACTION_EMOJIS = ["👍", "❤️", "🎉", "😂", "😮"] as const;
7
+
8
+ export interface CommunityReactionBarProps {
9
+ /** Per-emoji summary rows for THIS entity. */
10
+ reactions: ReactionSummary[];
11
+ /** Toggle handler — the backend flips the (member, entity, emoji) reaction. */
12
+ onToggle: (emoji: string) => void;
13
+ /** Extra inline actions rendered after the reactions (e.g. reply/report). */
14
+ children?: React.ReactNode;
15
+ disabled?: boolean;
16
+ }
17
+
18
+ /**
19
+ * Emoji reactions: existing reactions render as count chips (highlighted when
20
+ * you reacted); the "+" opens the default picker 👍❤️🎉😂😮. Toggle semantics
21
+ * match POST /public/community/:entityType/:id/react.
22
+ */
23
+ export function CommunityReactionBar({ reactions, onToggle, children, disabled }: CommunityReactionBarProps) {
24
+ const t = useThemeTokens();
25
+ const [pickerOpen, setPickerOpen] = useState(false);
26
+
27
+ const chip = (active: boolean): React.CSSProperties => ({
28
+ display: "inline-flex",
29
+ alignItems: "center",
30
+ gap: 4,
31
+ border: `1px solid ${active ? t.primary : t.border}`,
32
+ background: active ? `${t.primary}1a` : "transparent",
33
+ color: active ? t.primary : t.text,
34
+ borderRadius: 999,
35
+ padding: "2px 8px",
36
+ fontSize: 13,
37
+ cursor: disabled ? "default" : "pointer",
38
+ lineHeight: 1.5,
39
+ });
40
+
41
+ const shown = reactions.filter((r) => r.count > 0);
42
+
43
+ return (
44
+ <div style={{ position: "relative", display: "flex", alignItems: "center", flexWrap: "wrap", gap: 6 }}>
45
+ {shown.map((r) => (
46
+ <button
47
+ key={r.emoji}
48
+ onClick={() => !disabled && onToggle(r.emoji)}
49
+ aria-pressed={r.reactedByMe}
50
+ style={chip(r.reactedByMe)}
51
+ >
52
+ <span aria-hidden>{r.emoji}</span>
53
+ <span style={{ fontWeight: 600 }}>{r.count}</span>
54
+ </button>
55
+ ))}
56
+
57
+ <button
58
+ onClick={() => !disabled && setPickerOpen((v) => !v)}
59
+ aria-label="Add reaction"
60
+ style={{ ...chip(false), color: t.muted }}
61
+ >
62
+ {shown.length ? "+" : "🙂 React"}
63
+ </button>
64
+
65
+ {pickerOpen && (
66
+ <div
67
+ style={{
68
+ position: "absolute",
69
+ bottom: "calc(100% + 6px)",
70
+ left: 0,
71
+ display: "flex",
72
+ gap: 2,
73
+ background: t.surface,
74
+ border: `1px solid ${t.border}`,
75
+ borderRadius: 999,
76
+ padding: "4px 6px",
77
+ boxShadow: "0 4px 16px rgba(0,0,0,0.12)",
78
+ zIndex: 20,
79
+ }}
80
+ >
81
+ {COMMUNITY_REACTION_EMOJIS.map((emoji) => (
82
+ <button
83
+ key={emoji}
84
+ onClick={() => {
85
+ onToggle(emoji);
86
+ setPickerOpen(false);
87
+ }}
88
+ aria-label={`React ${emoji}`}
89
+ style={{
90
+ background: "transparent",
91
+ border: "none",
92
+ fontSize: 18,
93
+ cursor: "pointer",
94
+ padding: "2px 4px",
95
+ borderRadius: 8,
96
+ }}
97
+ >
98
+ {emoji}
99
+ </button>
100
+ ))}
101
+ </div>
102
+ )}
103
+
104
+ {children}
105
+ </div>
106
+ );
107
+ }