Complete notes export foundation
This commit is contained in:
+57
-10
@@ -23,6 +23,16 @@ export type TimelineEntry = {
|
||||
detail?: string
|
||||
}
|
||||
|
||||
export type SessionNote = {
|
||||
id: string
|
||||
kind: 'draft'
|
||||
body: string
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
reference?: string
|
||||
translationId?: string
|
||||
}
|
||||
|
||||
export type StudySession = {
|
||||
id: string
|
||||
title: string
|
||||
@@ -39,6 +49,7 @@ export type StudySession = {
|
||||
viewMode: ViewMode
|
||||
strongDisplay: StrongDisplayMode
|
||||
noteDraft: string
|
||||
notes: SessionNote[]
|
||||
timeline: TimelineEntry[]
|
||||
}
|
||||
|
||||
@@ -140,6 +151,7 @@ export function createSession(title = 'Study Session', baseTranslation = default
|
||||
viewMode: 'notes',
|
||||
strongDisplay: 'highlight',
|
||||
noteDraft: '',
|
||||
notes: [],
|
||||
timeline: [],
|
||||
}
|
||||
}
|
||||
@@ -158,16 +170,51 @@ export function normalizeStudySettings(settings?: Partial<StudySettings> | null)
|
||||
export function normalizeSessions(sessions?: StudySession[] | null): StudySession[] {
|
||||
const source = Array.isArray(sessions) && sessions.length ? sessions : [createSession('KJV Study Session')]
|
||||
|
||||
return source.map((session) => ({
|
||||
...createSession(session.title),
|
||||
...session,
|
||||
baseTranslation: session.baseTranslation ?? defaultTranslationId,
|
||||
footnotesEnabled: session.footnotesEnabled ?? true,
|
||||
strongsEnabled: session.strongsEnabled ?? true,
|
||||
commentaryEnabled: session.commentaryEnabled ?? true,
|
||||
dictionaryEnabled: session.dictionaryEnabled ?? true,
|
||||
timelineEnabled: session.timelineEnabled ?? true,
|
||||
}))
|
||||
return source.map((session) => {
|
||||
const normalized = {
|
||||
...createSession(session.title),
|
||||
...session,
|
||||
baseTranslation: session.baseTranslation ?? defaultTranslationId,
|
||||
footnotesEnabled: session.footnotesEnabled ?? true,
|
||||
strongsEnabled: session.strongsEnabled ?? true,
|
||||
commentaryEnabled: session.commentaryEnabled ?? true,
|
||||
dictionaryEnabled: session.dictionaryEnabled ?? true,
|
||||
timelineEnabled: session.timelineEnabled ?? true,
|
||||
notes: normalizeSessionNotes(session),
|
||||
}
|
||||
const draft = normalized.notes.find((note) => note.kind === 'draft')?.body ?? normalized.noteDraft
|
||||
return {
|
||||
...normalized,
|
||||
noteDraft: draft,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function normalizeSessionNotes(session: Partial<StudySession>): SessionNote[] {
|
||||
if (Array.isArray(session.notes) && session.notes.length) {
|
||||
return session.notes.map((note) => ({
|
||||
id: note.id || timelineId(),
|
||||
kind: 'draft',
|
||||
body: note.body ?? '',
|
||||
createdAt: note.createdAt ?? session.createdAt ?? new Date().toISOString(),
|
||||
updatedAt: note.updatedAt ?? session.updatedAt ?? new Date().toISOString(),
|
||||
reference: note.reference,
|
||||
translationId: note.translationId ?? session.baseTranslation,
|
||||
}))
|
||||
}
|
||||
|
||||
if (!session.noteDraft) return []
|
||||
const now = session.updatedAt ?? new Date().toISOString()
|
||||
return [
|
||||
{
|
||||
id: timelineId(),
|
||||
kind: 'draft',
|
||||
body: session.noteDraft,
|
||||
createdAt: session.createdAt ?? now,
|
||||
updatedAt: now,
|
||||
translationId: session.baseTranslation,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
export function selectActiveSessionId(sessions: StudySession[], requestedId?: string | null): string {
|
||||
|
||||
Reference in New Issue
Block a user