@@ -25,46 +25,38 @@ function Simplesite({ simplesite }: { simplesite: SimpleSite }) {
2525 showContactHint,
2626 showBackButton,
2727 } = simplesite
28- let textComponents : React . ReactNode [ ] = [ ]
2928 const color = pickColor ( title )
3029
31- if ( textBlocks != null ) {
32- const orderedTextBlocks = sortBy ( textBlocks , [ prop ( 'order' ) , 'asc' ] )
33- textComponents = textComponents . concat (
34- orderedTextBlocks . map ( ( block ) => (
35- < TextBlock
36- key = { block . title }
37- title = { block . title }
38- content = { < ParsedText content = { block . content } /> }
39- />
40- ) )
41- )
42- }
30+ const allBlocks = [
31+ ...( textBlocks ?? [ ] ) . map ( ( b ) => ( { type : 'text' as const , order : b . order , data : b } ) ) ,
32+ ...( multiColumnBlocks ?? [ ] ) . map ( ( b ) => ( { type : 'multiColumn' as const , order : b . order , data : b } ) ) ,
33+ ...( gridBlocks ?? [ ] ) . map ( ( b ) => ( { type : 'grid' as const , order : b . order , data : b } ) ) ,
34+ ]
4335
44- if ( multiColumnBlocks != null ) {
45- const orderedMultiColumnBlocks = sortBy ( multiColumnBlocks , [
46- prop ( 'order' ) ,
47- 'asc' ,
48- ] )
49- textComponents = textComponents . concat (
50- orderedMultiColumnBlocks . map ( ( block ) => (
51- < MultiColumnBlock
52- key = { block . title }
53- color = { color }
54- multiColumnBlock = { block }
55- />
56- ) )
57- )
58- }
36+ const orderedBlocks = sortBy ( allBlocks , [ prop ( 'order' ) , 'asc' ] )
5937
60- if ( gridBlocks != null ) {
61- const orderedGridBlocks = sortBy ( gridBlocks , [ prop ( 'order' ) , 'asc' ] )
62- textComponents = textComponents . concat (
63- orderedGridBlocks . map ( ( block ) => (
64- < GridBlock key = { block . title } gridBlock = { block } />
65- ) )
66- )
67- }
38+ const textComponents : React . ReactNode [ ] = orderedBlocks . map ( ( block ) => {
39+ switch ( block . type ) {
40+ case 'text' :
41+ return (
42+ < TextBlock
43+ key = { block . data . title }
44+ title = { block . data . title }
45+ content = { < ParsedText content = { block . data . content } /> }
46+ />
47+ )
48+ case 'multiColumn' :
49+ return (
50+ < MultiColumnBlock
51+ key = { block . data . title }
52+ color = { color }
53+ multiColumnBlock = { block . data }
54+ />
55+ )
56+ case 'grid' :
57+ return < GridBlock key = { block . data . title } gridBlock = { block . data } />
58+ }
59+ } )
6860
6961 if ( showContactHint === 'true' ) {
7062 textComponents . push ( < ContactHint color = { color } /> )
0 commit comments