This repository was archived by the owner on Oct 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathDashboardWidgetWrapper.js
98 lines (87 loc) · 2.27 KB
/
DashboardWidgetWrapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import React from "react";
import styled from "styled-components";
import ExamplesContainer from "./ExamplesContainer";
import { getPostFeed } from "@yoast/helpers";
import { ArticleList } from "@yoast/components";
import { SiteSEOReport } from "@yoast/analysis-report";
export const DashboardContainer = styled.div`
padding: 8px;
border: 1px solid black;
width: 400px;
`;
/**
* Returns the DashboardWidget component.
*
* @returns {ReactElement} The DashboardWidget component.
*/
export default class DashboardWidget extends React.Component {
/**
* Creates the components and initializes its state.
*/
constructor() {
super();
this.state = {
siteSEOReportItems: [
{
value: 33,
color: "#F00",
html: "Posts with a <b>bad</b> score",
},
{
value: 20,
color: "#FF0",
html: "Posts with a <b>decent</b> score",
},
{
value: 47,
color: "#0F0",
html: "Posts with a <b>good</b> score",
},
],
feed: null,
};
this.getFeed();
}
/**
* Fetches data from the yoast.com feed, parses it and sets it to the state.
*
* @returns {void}
*/
getFeed() {
// Developer note: this link should -not- be converted to a shortlink.
getPostFeed( "https://yoast.com/feed/widget/", 3 )
.then( ( feed ) => {
feed.items = feed.items.map( ( item ) => {
// The implementation on wordpress-seo makes use of jQuery for escaping.
item.description = item.description;
item.description = item.description.replace( `The post ${ item.title } appeared first on Yoast.`, "" ).trim();
return item;
} );
this.setState( { feed } );
} )
/* eslint-disable-next-line no-console */
.catch( error => console.error( error ) );
}
/**
* Renders all the Dashboard widget example.
*
* @returns {ReactElement} The rendered Dashboard widget example.
*/
render() {
const feed = this.state.feed;
return (
<ExamplesContainer>
<DashboardContainer>
<SiteSEOReport
seoAssessmentText="Your SEO score is decent overall, but can be improved! Get to work!"
seoAssessmentItems={ this.state.siteSEOReportItems }
/>
{ feed && <ArticleList
feed={ feed }
footerLinkText="View our blog on yoast.com!"
/> }
</DashboardContainer>
</ExamplesContainer>
);
}
}