| 1 |
/** |
| 2 |
* Import CSS |
| 3 |
*/ |
| 4 |
import './fonts.scss'; |
| 5 |
|
| 6 |
import { merge } from 'lodash'; |
| 7 |
|
| 8 |
import apiFetch from '@wordpress/api-fetch'; |
| 9 |
import { ExternalLink } from '@wordpress/components'; |
| 10 |
import { compose } from '@wordpress/compose'; |
| 11 |
import { withDispatch, withSelect } from '@wordpress/data'; |
| 12 |
import { Component } from '@wordpress/element'; |
| 13 |
import { __ } from '@wordpress/i18n'; |
| 14 |
|
| 15 |
import ApplyFilters from '../../gutenberg/components/apply-filters'; |
| 16 |
|
| 17 |
const { version } = window.ghostkitVariables; |
| 18 |
|
| 19 |
let reloadPage = false; |
| 20 |
|
| 21 |
class FontsSettings extends Component { |
| 22 |
/** |
| 23 |
* We should reload page after fonts updated and when we visit the Fonts settings page. |
| 24 |
*/ |
| 25 |
componentWillUnmount() { |
| 26 |
if (reloadPage) { |
| 27 |
setTimeout(() => { |
| 28 |
window.location.reload(); |
| 29 |
}, 0); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
render() { |
| 34 |
return ( |
| 35 |
<ApplyFilters name="ghostkit.fonts.settings" props={this.props}> |
| 36 |
<div className="ghostkit-settings-content-wrapper ghostkit-settings-fonts"> |
| 37 |
{__( |
| 38 |
'Adobe and Custom Fonts available for Pro users only. Read more about Ghost Kit Pro plugin here - ', |
| 39 |
'ghostkit' |
| 40 |
)} |
| 41 |
<ExternalLink |
| 42 |
href={`https://www.ghostkit.io/pricing/?utm_source=plugin&utm_medium=settings&utm_campaign=fonts&utm_content=${version}`} |
| 43 |
> |
| 44 |
https://www.ghostkit.io/pricing/ |
| 45 |
</ExternalLink> |
| 46 |
</div> |
| 47 |
</ApplyFilters> |
| 48 |
); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
const ComposeFontsSettings = compose([ |
| 53 |
withSelect((select) => { |
| 54 |
const { getIcon } = select('ghostkit/base/utils').get(); |
| 55 |
|
| 56 |
const customFonts = select('ghostkit/plugins/fonts').getCustomFonts(); |
| 57 |
|
| 58 |
const defaultCustomFonts = { |
| 59 |
adobe: { |
| 60 |
token: false, |
| 61 |
errors: false, |
| 62 |
kits: false, |
| 63 |
kit: false, |
| 64 |
fonts: false, |
| 65 |
}, |
| 66 |
google: false, |
| 67 |
custom: false, |
| 68 |
}; |
| 69 |
|
| 70 |
return { |
| 71 |
getIcon, |
| 72 |
customFonts: merge(defaultCustomFonts, customFonts), |
| 73 |
}; |
| 74 |
}), |
| 75 |
withDispatch((dispatch) => ({ |
| 76 |
updateFonts(value) { |
| 77 |
dispatch('ghostkit/plugins/fonts').setCustomFonts(value); |
| 78 |
|
| 79 |
apiFetch({ |
| 80 |
path: '/ghostkit/v1/update_custom_fonts', |
| 81 |
method: 'POST', |
| 82 |
data: { |
| 83 |
data: value, |
| 84 |
}, |
| 85 |
}).then(() => { |
| 86 |
reloadPage = true; |
| 87 |
}); |
| 88 |
}, |
| 89 |
})), |
| 90 |
])(FontsSettings); |
| 91 |
|
| 92 |
export default function addFontSettings(Control, props) { |
| 93 |
return <ComposeFontsSettings {...props} />; |
| 94 |
} |
| 95 |
|