diff --git a/src/App.tsx b/src/App.tsx index 1956565..b21d70a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,7 +4,7 @@ import { Link, NavLink, Routes, Route, useLocation, useNavigate, useParams } fro import AdminPage from './AdminPage' import QASection from './components/QASection' import ContactForm from './components/ContactForm' -import { ColossiansStudyIndexPage, ColossiansStudyNotesPage, ColossiansStudySectionPage, StudyLandingPage, StudySignupPage, StudyAccountPage } from './colossiansStudy' +import { ColossiansStudyIndexPage, ColossiansStudyNotesPage, ColossiansStudySectionPage, StudyLandingPage, StudySignupPage, StudyAccountPage, StudyCommunityPage } from './colossiansStudy' import { SpotifyIcon } from './icons' import type { SiteContent, ArchivedSeries, StudyProgram } from './content' import { DEFAULTS } from './content' @@ -2021,6 +2021,7 @@ export default function App() { } />} /> } />} /> } />} /> + } />} /> } />} /> } />} /> } /> diff --git a/src/colossiansStudy.tsx b/src/colossiansStudy.tsx index a92ae71..217665e 100644 --- a/src/colossiansStudy.tsx +++ b/src/colossiansStudy.tsx @@ -172,16 +172,16 @@ function formatCommunityDate(value: string) { return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }) } -function StudyCommunityWidget({ +function CommunityBoard({ study, - section, auth, isEnrolled, + sectionFilter, }: { study: StudyProgram - section: StudySection auth: StudyAuthState isEnrolled: boolean + sectionFilter?: string }) { const [posts, setPosts] = useState([]) const [loading, setLoading] = useState(true) @@ -191,10 +191,16 @@ function StudyCommunityWidget({ const [replyingTo, setReplyingTo] = useState(null) const [submitting, setSubmitting] = useState(false) const [newPost, setNewPost] = useState('') + const [activeSection, setActiveSection] = useState(sectionFilter ?? '') const canParticipate = auth.authenticated && isEnrolled const communityDisplayName = getDisplayName(auth) + const releasedSections = study.sections.filter(isSectionReleased) + const visiblePosts = activeSection + ? posts.filter(p => p.sectionId === activeSection) + : posts + useEffect(() => { let cancelled = false @@ -235,7 +241,7 @@ function StudyCommunityWidget({ const data = await readJson<{ post?: StudyCommunityPost }>('/api/study-community/posts', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ studySlug: study.slug, sectionId: section.id, message: newPost }), + body: JSON.stringify({ studySlug: study.slug, sectionId: activeSection, message: newPost }), }) if (data.post) setPosts(prev => [data.post!, ...prev]) setNewPost('') @@ -272,18 +278,29 @@ function StudyCommunityWidget({ } return ( -
-
-
-

Study Community

-

Talk with other enrolled students about {study.title}. Keep it gracious and on topic.

+
+ {/* Section filter tabs */} + {releasedSections.length > 1 && canParticipate && ( +
+ + {releasedSections.map(s => ( + + ))}
- Ask Nate -
+ )} - {!auth.checked &&

Checking your account status...

} + {!auth.checked &&

Checking your account status...

} {auth.checked && !auth.authenticated && ( -
+

Sign in to join the study community.

Create Account @@ -292,8 +309,8 @@ function StudyCommunityWidget({
)} {auth.checked && auth.authenticated && !isEnrolled && ( -
-

Enroll in this study to participate in the community.

+
+

Enroll in {study.title} to participate in the community.

Go to My Account
@@ -301,12 +318,17 @@ function StudyCommunityWidget({ )} {canParticipate && ( -
+
+ {activeSection && ( +

+ Posting to: {releasedSections.find(s => s.id === activeSection)?.title ?? 'this lesson'} +

+ )}