/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ import React from "react"; import { actionCreators as ac } from "common/Actions.sys.mjs"; export class ContentSection extends React.PureComponent { constructor(props) { super(props); this.onPreferenceSelect = this.onPreferenceSelect.bind(this); // Refs are necessary for dynamically measuring drawer heights for slide animations this.topSitesDrawerRef = React.createRef(); this.pocketDrawerRef = React.createRef(); } inputUserEvent(eventSource, status) { this.props.dispatch( ac.UserEvent({ event: "PREF_CHANGED", source: eventSource, value: { status, menu_source: "CUSTOMIZE_MENU" }, }) ); } onPreferenceSelect(e) { let prefName = e.target.getAttribute("preference"); const eventSource = e.target.getAttribute("eventSource"); // TOP_SITES, TOP_STORIES, HIGHLIGHTS let value; if (e.target.nodeName === "SELECT") { value = parseInt(e.target.value, 10); } else if (e.target.nodeName === "INPUT") { value = e.target.checked; if (eventSource) { this.inputUserEvent(eventSource, value); } } this.props.setPref(prefName, value); } componentDidMount() { this.setDrawerMargins(); } componentDidUpdate() { this.setDrawerMargins(); } setDrawerMargins() { this.setDrawerMargin( `TOP_SITES`, this.props.enabledSections.topSitesEnabled ); this.setDrawerMargin( `TOP_STORIES`, this.props.enabledSections.pocketEnabled ); } setDrawerMargin(drawerID, isOpen) { let drawerRef; if (drawerID === `TOP_SITES`) { drawerRef = this.topSitesDrawerRef.current; } else if (drawerID === `TOP_STORIES`) { drawerRef = this.pocketDrawerRef.current; } else { return; } let drawerHeight; if (drawerRef) { drawerHeight = parseFloat(window.getComputedStyle(drawerRef)?.height); if (isOpen) { drawerRef.style.marginTop = `0`; } else { drawerRef.style.marginTop = `-${drawerHeight}px`; } } } render() { const { enabledSections, mayHaveSponsoredTopSites, pocketRegion, mayHaveSponsoredStories, mayHaveRecentSaves, openPreferences, } = this.props; const { topSitesEnabled, pocketEnabled, highlightsEnabled, showSponsoredTopSitesEnabled, showSponsoredPocketEnabled, showRecentSavesEnabled, topSitesRowsCount, } = enabledSections; return (

{mayHaveSponsoredTopSites && (
)}
{pocketRegion && (

{(mayHaveSponsoredStories || mayHaveRecentSaves) && (

{mayHaveSponsoredStories && (
)} {mayHaveRecentSaves && (
)}
)}
)}

); } }