/* 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.mjs"; import { SectionsMgmtPanel } from "../SectionsMgmtPanel/SectionsMgmtPanel"; import { WallpaperCategories } from "../../WallpaperCategories/WallpaperCategories"; 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, eventValue) { this.props.dispatch( ac.UserEvent({ event: "PREF_CHANGED", source: eventSource, value: { status: eventValue, menu_source: "CUSTOMIZE_MENU" }, }) ); } onPreferenceSelect(e) { // eventSource: WEATHER | TOP_SITES | TOP_STORIES const { preference, eventSource } = e.target.dataset; 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); } } else if (e.target.nodeName === "MOZ-TOGGLE") { value = e.target.pressed; if (eventSource) { this.inputUserEvent(eventSource, value); } } this.props.setPref(preference, 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; } if (drawerRef) { let drawerHeight = parseFloat(window.getComputedStyle(drawerRef)?.height) || 0; if (isOpen) { drawerRef.style.marginTop = "var(--space-large)"; } else { drawerRef.style.marginTop = `-${drawerHeight + 3}px`; } } } render() { const { enabledSections, pocketRegion, mayHaveInferredPersonalization, mayHaveRecentSaves, mayHaveWeather, openPreferences, wallpapersEnabled, activeWallpaper, setPref, mayHaveTopicSections, exitEventFired, } = this.props; const { topSitesEnabled, pocketEnabled, weatherEnabled, showInferredPersonalizationEnabled, showRecentSavesEnabled, topSitesRowsCount, } = enabledSections; return (
{wallpapersEnabled && ( <>
)}
{mayHaveWeather && (
)}
{pocketRegion && (
{(mayHaveRecentSaves || mayHaveInferredPersonalization || mayHaveTopicSections) && (
{mayHaveInferredPersonalization && (
)} {mayHaveTopicSections && ( )} {mayHaveRecentSaves && (
)}
)}
)}
); } }