diff --git a/package.json b/package.json index 6031766..5dffd9c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "siteforge", "private": true, - "version": "1.1.50", + "version": "1.1.51", "type": "module", "scripts": { "dev": "vite", diff --git a/src/AdminPage.tsx b/src/AdminPage.tsx index e73aaf0..2a61cee 100644 --- a/src/AdminPage.tsx +++ b/src/AdminPage.tsx @@ -11,150 +11,57 @@ import { AdminCollapsibleCard } from './components/AdminCollapsibleCard' import { useAutosave } from './hooks/useAutosave' import QRCode from 'qrcode' -interface SortableLessonSectionProps { + +interface SortableLessonRowProps { section: ColossiansStudySection study: StudyProgram - updateStudySection: (studyId: string, sectionId: string, field: keyof ColossiansStudySection, value: string | string[] | number) => void + onEdit: () => void removeStudySection: (studyId: string, sectionId: string) => void - rssEpisodes: Array<{ title: string; audioUrl: string; duration: string; episode: string }> } -function SortableLessonSection({ section, study, updateStudySection, removeStudySection, rssEpisodes }: SortableLessonSectionProps) { +function SortableLessonRow({ section, study, onEdit, removeStudySection }: SortableLessonRowProps) { const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: section.id }) - const [bsbFetching, setBsbFetching] = useState(false) - const [bsbMsg, setBsbMsg] = useState('') + const style = { transform: CSS.Transform.toString(transform), transition, opacity: isDragging ? 0.4 : 1 } + const isLive = section.releasedAt ? new Date(section.releasedAt) <= new Date() : false + return ( +
+ ⠿ + {section.reference || '—'} + {section.title || Untitled} + {isLive ? 'Live' : 'Draft'} +
+ + e.stopPropagation()}>Preview + +
+
+ ) +} - async function fetchBsbPassage() { +function BsbFetchButton({ study, section, updateStudySection }: { study: StudyProgram; section: ColossiansStudySection; updateStudySection: (studyId: string, sectionId: string, field: keyof ColossiansStudySection, value: string | string[] | number) => void }) { + const [busy, setBusy] = useState(false) + const [msg, setMsg] = useState('') + async function fetch_() { const bookKey = (study.bibleBook?.trim() || study.slug).toLowerCase() const reference = section.reference?.trim() - if (!bookKey || !reference) { setBsbMsg('Set the passage reference first.'); return } - setBsbFetching(true) - setBsbMsg('') + if (!bookKey || !reference) { setMsg('Set the passage reference first.'); return } + setBusy(true); setMsg('') try { - const params = new URLSearchParams({ book: bookKey, reference }) - const res = await fetch(`/api/bible-passage?${params}`) + const res = await fetch(`/api/bible-passage?${new URLSearchParams({ book: bookKey, reference })}`) const data = await res.json() as { text?: string; message?: string } - if (!res.ok || !data.text) { setBsbMsg(data.message ?? 'Passage not found.'); return } + if (!res.ok || !data.text) { setMsg(data.message ?? 'Passage not found.'); return } updateStudySection(study.id, section.id, 'passageText', data.text) - setBsbMsg('Passage filled from BSB.') - } catch { - setBsbMsg('Could not reach the BSB API.') - } finally { - setBsbFetching(false) - } + setMsg('Passage filled from BSB.') + } catch { setMsg('Could not reach the BSB API.') } + finally { setBusy(false) } } - const style = { - transform: CSS.Transform.toString(transform), - transition, - opacity: isDragging ? 0.5 : 1, - background: isDragging ? '#f8f7f2' : undefined, - border: isDragging ? '2px solid #e0c070' : undefined, - marginBottom: '0.5rem', - } - return ( -
- -
- Lesson {section.reference || section.id} -

{section.title || 'Untitled section'}

-
-
- e.stopPropagation()}>Preview - Expand to edit lesson -
-
-
-
-
-
- - -
-
- - updateStudySection(study.id, section.id, 'reference', e.target.value)} /> -
-
- - updateStudySection(study.id, section.id, 'title', e.target.value)} /> -
-
- - -
-
- - { - const val = e.target.value; - if (val) { - const date = new Date(val + ':00Z'); - updateStudySection(study.id, section.id, 'releasedAt', date.toISOString()); - } else { - updateStudySection(study.id, section.id, 'releasedAt', ''); - } - }} /> -
-
- -