@@ -2,29 +2,31 @@ import React from 'react';
2
2
import RawHTML from '~/components/jsx-helpers/raw-html' ;
3
3
import usePageData from '~/helpers/use-page-data' ;
4
4
import { useLocation } from 'react-router-dom' ;
5
+ import useDocumentHead from '~/helpers/use-document-head' ;
5
6
import './footer-page.scss' ;
6
7
7
- const specialSlugFromPath = {
8
+ const specialSlugFromPath : Record < string , string > = {
8
9
'/privacy' : '/privacy-policy'
9
10
} ;
10
11
11
- export default function FooterPage ( ) {
12
- const { pathname} = useLocation ( ) ;
13
- const slugEnd = specialSlugFromPath [ pathname ] || pathname ;
14
- const slug = `pages${ slugEnd } ` ;
15
- const data = usePageData ( slug ) ;
16
-
17
- React . useLayoutEffect (
18
- ( ) => window . scrollTo ( 0 , 0 ) ,
19
- [ pathname ]
20
- ) ;
12
+ type PageData = {
13
+ introHeading : string ;
14
+ title : string ;
15
+ meta : {
16
+ searchDescription : string ;
17
+ } ;
18
+ } & {
19
+ [ contentFieldName : string ] : string ;
20
+ }
21
21
22
- if ( ! data ) {
23
- return null ;
24
- }
22
+ function FooterPage ( { data} : { data : PageData } ) {
23
+ useDocumentHead ( {
24
+ title : data . title ,
25
+ description : data . meta . searchDescription
26
+ } ) ;
25
27
26
- const contentFieldName = Reflect . ownKeys ( data )
27
- . find ( ( k ) => k . match ( / C o n t e n t $ / ) ) ;
28
+ const contentFieldName = Object . keys ( data )
29
+ . find ( ( k ) => k . match ( / C o n t e n t $ / ) ) as string ;
28
30
const { introHeading : heading , [ contentFieldName ] : content } = data ;
29
31
30
32
return (
@@ -37,3 +39,21 @@ export default function FooterPage() {
37
39
</ div >
38
40
) ;
39
41
}
42
+
43
+ export default function LoadFooterPage ( ) {
44
+ const { pathname} = useLocation ( ) ;
45
+ const slugEnd = specialSlugFromPath [ pathname ] ?? pathname ;
46
+ const slug = `pages${ slugEnd } ` ;
47
+ const data = usePageData < PageData > ( slug ) ;
48
+
49
+ React . useLayoutEffect (
50
+ ( ) => window . scrollTo ( 0 , 0 ) ,
51
+ [ pathname ]
52
+ ) ;
53
+
54
+ if ( ! data ) {
55
+ return null ;
56
+ }
57
+
58
+ return < FooterPage data = { data } /> ;
59
+ }
0 commit comments