5
5
import _ from 'lodash' ;
6
6
import actions from 'actions/cms/dashboard/announcements' ;
7
7
import Announcement from 'components/Dashboard/Announcement' ;
8
+ import ContentfulLoader from 'containers/ContentfulLoader' ;
8
9
import cookies from 'browser-cookies' ;
10
+ import LoadingIndicator from 'components/LoadingIndicator' ;
11
+ import moment from 'moment' ;
9
12
import PT from 'prop-types' ;
10
13
import React from 'react' ;
11
14
import shortId from 'shortid' ;
@@ -16,6 +19,11 @@ const COOKIE = 'lastSeenDashboardAnnouncement';
16
19
const MAXAGE = 10 * 60 * 1000 ;
17
20
18
21
class AnnouncementContainer extends React . Component {
22
+ constructor ( props ) {
23
+ super ( props ) ;
24
+ this . now = moment ( ) . format ( ) ;
25
+ }
26
+
19
27
componentDidMount ( ) {
20
28
const {
21
29
activeLoading,
@@ -58,27 +66,52 @@ class AnnouncementContainer extends React.Component {
58
66
59
67
render ( ) {
60
68
const {
61
- active,
62
- activeAssets,
63
- activeLoading,
64
69
hidePreviewMetaData,
65
- preview,
66
- previewAssets,
67
- previewLoading,
68
70
previewId,
69
71
show,
70
72
switchShowAnnouncement,
71
73
} = this . props ;
72
74
73
75
return (
74
- < Announcement
75
- assets = { previewId ? previewAssets : activeAssets }
76
- announcement = { previewId ? preview : active }
77
- hidePreviewMetaData = { hidePreviewMetaData }
78
- loading = { previewId ? previewLoading : activeLoading }
76
+ < ContentfulLoader
77
+ entryQueries = { {
78
+ content_type : 'dashboardAnnouncement' ,
79
+ 'fields.startDate' : {
80
+ lt : this . now ,
81
+ } ,
82
+ 'fields.endDate' : {
83
+ gt : this . now ,
84
+ } ,
85
+ limit : 1 ,
86
+ order : '-fields.startDate' ,
87
+ } }
79
88
preview = { Boolean ( previewId ) }
80
- show = { show }
81
- switchShow = { switchShowAnnouncement }
89
+ render = { ( data ) => {
90
+ let announcement = data . entries . matches [ 0 ] . items [ 0 ] ;
91
+ if ( ! announcement ) return null ;
92
+ announcement = data . entries . items [ announcement ] ;
93
+ const backgroundAssetId =
94
+ _ . get ( announcement . fields . backgroundImage , 'sys.id' ) ;
95
+ return (
96
+ < ContentfulLoader
97
+ assetIds = { backgroundAssetId }
98
+ preview = { data . preview }
99
+ render = { data2 => (
100
+ < Announcement
101
+ assets = { data2 . assets . items }
102
+ announcement = { announcement }
103
+ hidePreviewMetaData = { hidePreviewMetaData }
104
+ loading = { false }
105
+ preview = { data . preview }
106
+ show = { show }
107
+ switchShow = { switchShowAnnouncement }
108
+ />
109
+ ) }
110
+ renderPlaceholder = { LoadingIndicator }
111
+ />
112
+ ) ;
113
+ } }
114
+ renderPlaceholder = { LoadingIndicator }
82
115
/>
83
116
) ;
84
117
}
@@ -91,16 +124,12 @@ AnnouncementContainer.defaultProps = {
91
124
92
125
AnnouncementContainer . propTypes = {
93
126
active : PT . shape ( ) . isRequired ,
94
- activeAssets : PT . shape ( ) . isRequired ,
95
127
activeLoading : PT . bool . isRequired ,
96
128
activeTimestamp : PT . number . isRequired ,
97
129
hidePreviewMetaData : PT . bool ,
98
130
getActive : PT . func . isRequired ,
99
131
getPreview : PT . func . isRequired ,
100
- preview : PT . shape ( ) . isRequired ,
101
- previewAssets : PT . shape ( ) . isRequired ,
102
132
previewId : PT . string ,
103
- previewLoading : PT . func . isRequired ,
104
133
show : PT . bool . isRequired ,
105
134
switchShowAnnouncement : PT . func . isRequired ,
106
135
} ;
0 commit comments