@@ -18,111 +18,94 @@ import CourseMemoLinks from '../components/preview/CourseMemoLinks'
18
18
import CourseLinks from '../components/preview/CourseLinks'
19
19
import CourseContacts from '../components/preview/CourseContacts'
20
20
import Section from '../components/preview/Section'
21
- import ExtraHeadingContent from '../components/preview/ExtraHeadingContent'
22
21
23
22
import i18n from '../../../../i18n'
24
- import { context } from '../util/fieldsByType'
23
+ import { context , getDefaultSections } from '../util/fieldsByType'
25
24
import { concatMemoName , concatHeaderMemoName } from '../util/helpers'
26
25
import { seasonStr } from '../utils-shared/helpers'
27
- import { FIRST_VERSION , EMPTY , SERVICE_URL , SAVED_NEW_PARAM , ADMIN_URL } from '../util/constants'
26
+ import { FIRST_VERSION , SERVICE_URL , SAVED_NEW_PARAM , ADMIN_URL } from '../util/constants'
28
27
import { TYPE , useToast } from '../hooks/useToast'
29
- import {
30
- htmlHasContent ,
31
- isStandardHeadingVisibleInPreview ,
32
- isExtraHeadingVisibleInPreview ,
33
- } from '../util/editorAndPreviewUtils'
28
+ import { getAllSectionsAndHeadingsToShowInPreview } from '../util/editorAndPreviewUtils'
29
+ import ContentFromNewSectionEditor from '../components/preview/ContentFromNewSectionEditor'
34
30
35
31
const PROGRESS = 3
36
32
37
- const renderAllSections = ( { sections , memoData } ) => {
33
+ const renderAllSections = ( { memoData } ) => {
38
34
const memoLanguageIndex = memoData . memoCommonLangAbbr === 'en' ? 0 : 1
39
35
const { sectionsLabels } = i18n . messages [ memoLanguageIndex ]
36
+ const { noInfoYetPreview } = i18n . messages [ memoLanguageIndex ] . sourceInfo
40
37
41
- const sectionsWithContent = [ ]
42
- sections . forEach ( ( { id, content, extraHeaderTitle } ) => {
43
- content . forEach ( contentId => {
44
- const visibleInMemo = isStandardHeadingVisibleInPreview ( contentId , context , memoData )
38
+ const sections = getDefaultSections ( )
39
+ const sectionsAndContent = getAllSectionsAndHeadingsToShowInPreview ( { sections, context, memoData } )
45
40
46
- if ( visibleInMemo && ! sectionsWithContent . includes ( id ) ) {
47
- sectionsWithContent . push ( id )
48
- }
49
- } )
50
-
51
- if ( extraHeaderTitle && Array . isArray ( memoData [ extraHeaderTitle ] ) ) {
52
- memoData [ extraHeaderTitle ] . forEach ( m => {
53
- if ( m . visibleInMemo && ! sectionsWithContent . includes ( id ) ) {
54
- sectionsWithContent . push ( id )
55
- }
56
- } )
41
+ return sectionsAndContent . map ( ( { id, standardHeadingIds, extraHeaderTitle, extraHeadingIndices, isEmptySection } ) => {
42
+ if ( isEmptySection ) {
43
+ return < EmptySection key = { id } id = { id } sectionsLabels = { sectionsLabels } noInfoYetPreview = { noInfoYetPreview } />
57
44
}
58
- } )
59
45
60
- return sections . map ( ( { id, content, extraHeaderTitle } ) => {
61
- if ( ! sectionsWithContent . includes ( id ) ) {
62
- return (
63
- < section key = { id } className = "section-wrapper" >
64
- < h2 id = { id } key = { 'header-' + id } >
65
- { sectionsLabels [ id ] }
66
- </ h2 >
67
- < p >
68
- < i > { EMPTY [ memoLanguageIndex ] } </ i >
69
- </ p >
70
- </ section >
71
- )
72
- }
73
- // Contacts are displayed in the right column
74
46
return (
75
- id !== 'contacts' && (
76
- < section key = { id } className = "section-wrapper" >
77
- < h2 id = { id } key = { 'header-' + id } >
78
- { sectionsLabels [ id ] }
79
- </ h2 >
80
- { content . map ( contentId => {
81
- const menuId = id + '-' + contentId
82
- let contentHtml = memoData [ contentId ]
83
-
84
- const visibleInMemo = isStandardHeadingVisibleInPreview ( contentId , context , memoData )
85
-
86
- if ( visibleInMemo && ! htmlHasContent ( contentHtml ) ) contentHtml = `<p><i>${ EMPTY [ memoLanguageIndex ] } </i></p>`
87
-
88
- return (
89
- visibleInMemo && (
90
- < Section
91
- memoLangIndex = { memoLanguageIndex }
92
- contentId = { contentId }
93
- menuId = { menuId }
94
- key = { contentId }
95
- visibleInMemo = { visibleInMemo }
96
- html = { contentHtml }
97
- />
98
- )
99
- )
100
- } ) }
101
- { extraHeaderTitle &&
102
- Array . isArray ( memoData [ extraHeaderTitle ] ) &&
103
- memoData [ extraHeaderTitle ] . map ( ( { title, htmlContent, isEmptyNew, uKey } , index ) => {
104
- const isVisibleInMemo = isExtraHeadingVisibleInPreview ( extraHeaderTitle , index , memoData )
105
-
106
- return (
107
- isVisibleInMemo && (
108
- < ExtraHeadingContent
109
- contentId = { extraHeaderTitle }
110
- key = { uKey || extraHeaderTitle }
111
- initialTitle = { title }
112
- initialValue = { htmlContent }
113
- isEmptyNew = { isEmptyNew }
114
- uKey = { uKey }
115
- memoLanguageIndex = { memoLanguageIndex }
116
- />
117
- )
118
- )
119
- } ) }
120
- </ section >
121
- )
47
+ < SectionWrapper key = { id } id = { id } sectionsLabels = { sectionsLabels } >
48
+ < Sections headings = { standardHeadingIds } id = { id } memoData = { memoData } memoLanguageIndex = { memoLanguageIndex } />
49
+
50
+ < ExtraHeaders
51
+ headingIndices = { extraHeadingIndices }
52
+ extraHeaderTitle = { extraHeaderTitle }
53
+ memoData = { memoData }
54
+ memoLanguageIndex = { memoLanguageIndex }
55
+ />
56
+ </ SectionWrapper >
122
57
)
123
58
} )
124
59
}
125
60
61
+ const EmptySection = ( { id, sectionsLabels, noInfoYetPreview } ) => (
62
+ < SectionWrapper id = { id } sectionsLabels = { sectionsLabels } >
63
+ < article >
64
+ < p >
65
+ < i > { noInfoYetPreview } </ i >
66
+ </ p >
67
+ </ article >
68
+ </ SectionWrapper >
69
+ )
70
+
71
+ const SectionWrapper = ( { id, sectionsLabels, children } ) => (
72
+ < section key = { id } aria-labelledby = { id } className = "section-wrapper" >
73
+ < h2 id = { id } key = { 'header-' + id } >
74
+ { sectionsLabels [ id ] }
75
+ </ h2 >
76
+ { children }
77
+ </ section >
78
+ )
79
+
80
+ const Sections = ( { headings, id, memoData, memoLanguageIndex } ) =>
81
+ headings . map ( contentId => {
82
+ const menuId = id + '-' + contentId
83
+ const htmlContent = memoData [ contentId ]
84
+
85
+ return (
86
+ < Section
87
+ memoLangIndex = { memoLanguageIndex }
88
+ contentId = { contentId }
89
+ menuId = { menuId }
90
+ key = { contentId }
91
+ htmlContent = { htmlContent }
92
+ />
93
+ )
94
+ } )
95
+
96
+ const ExtraHeaders = ( { headingIndices, extraHeaderTitle, memoData, memoLanguageIndex } ) =>
97
+ headingIndices . map ( index => {
98
+ const { uKey, title, htmlContent } = memoData [ extraHeaderTitle ] ?. [ index ] || { }
99
+ return (
100
+ < ContentFromNewSectionEditor
101
+ key = { uKey }
102
+ title = { title }
103
+ htmlContent = { htmlContent }
104
+ memoLanguageIndex = { memoLanguageIndex }
105
+ />
106
+ )
107
+ } )
108
+
126
109
const determineContentFlexibility = ( ) => {
127
110
const lastColLastElem = document . getElementById ( 'last-element-which-determines-styles' )
128
111
if ( lastColLastElem ) {
0 commit comments