mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 06:09:19 +00:00
Bug 1929378 - Newtab sections experiment handle loading and empty states r=home-newtab-reviewers,maxx
Differential Revision: https://phabricator.services.mozilla.com/D229551
This commit is contained in:
parent
341dafed36
commit
04a522cd47
@ -97,6 +97,10 @@ main {
|
|||||||
|
|
||||||
.ds-card-grid:not(.ds-section-grid) {
|
.ds-card-grid:not(.ds-section-grid) {
|
||||||
grid-gap: var(--space-large);
|
grid-gap: var(--space-large);
|
||||||
|
|
||||||
|
&.empty {
|
||||||
|
grid-template-columns: auto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.body-wrapper {
|
.body-wrapper {
|
||||||
@ -114,7 +118,6 @@ main {
|
|||||||
.body-wrapper {
|
.body-wrapper {
|
||||||
width: 346px;
|
width: 346px;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: $break-point-layout-variant) {
|
@media (min-width: $break-point-layout-variant) {
|
||||||
@ -127,7 +130,6 @@ main {
|
|||||||
.body-wrapper {
|
.body-wrapper {
|
||||||
width: 659px;
|
width: 659px;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: $break-point-widest) {
|
@media (min-width: $break-point-widest) {
|
||||||
@ -141,7 +143,6 @@ main {
|
|||||||
.body-wrapper {
|
.body-wrapper {
|
||||||
width: 989px;
|
width: 989px;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: $break-point-ultra-wide) {
|
@media (min-width: $break-point-ultra-wide) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import React, { useCallback } from "react";
|
import React, { useCallback } from "react";
|
||||||
import { DSEmptyState } from "../DSEmptyState/DSEmptyState";
|
import { DSEmptyState } from "../DSEmptyState/DSEmptyState";
|
||||||
import { DSCard } from "../DSCard/DSCard";
|
import { DSCard, PlaceholderDSCard } from "../DSCard/DSCard";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { actionCreators as ac, actionTypes as at } from "common/Actions.mjs";
|
import { actionCreators as ac, actionTypes as at } from "common/Actions.mjs";
|
||||||
import { useIntersectionObserver } from "../../../lib/hooks";
|
import { useIntersectionObserver } from "../../../lib/hooks";
|
||||||
@ -28,7 +28,7 @@ function CardSections({
|
|||||||
ctaButtonSponsors,
|
ctaButtonSponsors,
|
||||||
}) {
|
}) {
|
||||||
const { recommendations, sections } = data;
|
const { recommendations, sections } = data;
|
||||||
const isEmpty = recommendations?.length === 0 || !sections;
|
const isEmpty = !recommendations?.length || !sections;
|
||||||
|
|
||||||
const prefs = useSelector(state => state.Prefs.values);
|
const prefs = useSelector(state => state.Prefs.values);
|
||||||
const showTopics = prefs[PREF_TOPICS_ENABLED];
|
const showTopics = prefs[PREF_TOPICS_ENABLED];
|
||||||
@ -102,6 +102,13 @@ function CardSections({
|
|||||||
const { sectionKey, title, subtitle } = section;
|
const { sectionKey, title, subtitle } = section;
|
||||||
const { responsiveLayouts } = section.layout;
|
const { responsiveLayouts } = section.layout;
|
||||||
const { maxTile } = getMaxTiles(responsiveLayouts);
|
const { maxTile } = getMaxTiles(responsiveLayouts);
|
||||||
|
const displaySections = section.data.slice(0, maxTile);
|
||||||
|
const isSectionEmpty = !displaySections?.length;
|
||||||
|
|
||||||
|
if (isSectionEmpty) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
key={sectionKey}
|
key={sectionKey}
|
||||||
@ -119,6 +126,11 @@ function CardSections({
|
|||||||
{section.data.slice(0, maxTile).map((rec, index) => {
|
{section.data.slice(0, maxTile).map((rec, index) => {
|
||||||
const layoutData = getLayoutData(responsiveLayouts, index);
|
const layoutData = getLayoutData(responsiveLayouts, index);
|
||||||
const { classNames, position } = layoutData;
|
const { classNames, position } = layoutData;
|
||||||
|
|
||||||
|
if (!rec || rec.placeholder) {
|
||||||
|
return <PlaceholderDSCard key={`dscard-${index}`} />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DSCard
|
<DSCard
|
||||||
key={`dscard-${rec.id}`}
|
key={`dscard-${rec.id}`}
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
height: $card-height-compact;
|
height: $card-height-compact;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
|
@media (min-width: $break-point-sections-variant) {
|
||||||
|
width: 936px;
|
||||||
|
}
|
||||||
|
|
||||||
.empty-state-message {
|
.empty-state-message {
|
||||||
color: var(--newtab-text-secondary-color);
|
color: var(--newtab-text-secondary-color);
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
@ -100,6 +100,14 @@ export const selectLayoutRender = ({ state = {}, prefs = {} }) => {
|
|||||||
}
|
}
|
||||||
const data = {
|
const data = {
|
||||||
recommendations: [],
|
recommendations: [],
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
layout: {
|
||||||
|
responsiveLayouts: [],
|
||||||
|
},
|
||||||
|
data: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
let items = 0;
|
let items = 0;
|
||||||
@ -110,11 +118,18 @@ export const selectLayoutRender = ({ state = {}, prefs = {} }) => {
|
|||||||
data.recommendations.push({ placeholder: true });
|
data.recommendations.push({ placeholder: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sectionsEnabled = prefs["discoverystream.sections.enabled"];
|
||||||
|
if (sectionsEnabled) {
|
||||||
|
for (let i = 0; i < items; i++) {
|
||||||
|
data.sections[0].data.push({ placeholder: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return { ...component, data };
|
return { ...component, data };
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO update devtools to show placements
|
// TODO update devtools to show placements
|
||||||
const handleSpocs = (data, spocsPositions, spocsPlacement) => {
|
const handleSpocs = (data = [], spocsPositions, spocsPlacement) => {
|
||||||
let result = [...data];
|
let result = [...data];
|
||||||
// Do we ever expect to possibly have a spoc.
|
// Do we ever expect to possibly have a spoc.
|
||||||
if (spocsPositions?.length) {
|
if (spocsPositions?.length) {
|
||||||
|
@ -533,6 +533,10 @@ main section {
|
|||||||
.layout-variant-b .ds-outer-wrapper-breakpoint-override main .ds-card-grid:not(.ds-section-grid) {
|
.layout-variant-b .ds-outer-wrapper-breakpoint-override main .ds-card-grid:not(.ds-section-grid) {
|
||||||
grid-gap: var(--space-large);
|
grid-gap: var(--space-large);
|
||||||
}
|
}
|
||||||
|
.layout-variant-a .ds-outer-wrapper-breakpoint-override main .ds-card-grid:not(.ds-section-grid).empty,
|
||||||
|
.layout-variant-b .ds-outer-wrapper-breakpoint-override main .ds-card-grid:not(.ds-section-grid).empty {
|
||||||
|
grid-template-columns: auto;
|
||||||
|
}
|
||||||
.layout-variant-a .ds-outer-wrapper-breakpoint-override main .body-wrapper,
|
.layout-variant-a .ds-outer-wrapper-breakpoint-override main .body-wrapper,
|
||||||
.layout-variant-b .ds-outer-wrapper-breakpoint-override main .body-wrapper {
|
.layout-variant-b .ds-outer-wrapper-breakpoint-override main .body-wrapper {
|
||||||
width: 346px;
|
width: 346px;
|
||||||
@ -6155,6 +6159,11 @@ main section {
|
|||||||
height: 160px;
|
height: 160px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
@media (min-width: 1390px) {
|
||||||
|
.section-empty-state {
|
||||||
|
width: 936px;
|
||||||
|
}
|
||||||
|
}
|
||||||
.section-empty-state .empty-state-message {
|
.section-empty-state .empty-state-message {
|
||||||
color: var(--newtab-text-secondary-color);
|
color: var(--newtab-text-secondary-color);
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
@ -9262,6 +9262,14 @@ const selectLayoutRender = ({ state = {}, prefs = {} }) => {
|
|||||||
}
|
}
|
||||||
const data = {
|
const data = {
|
||||||
recommendations: [],
|
recommendations: [],
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
layout: {
|
||||||
|
responsiveLayouts: [],
|
||||||
|
},
|
||||||
|
data: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
let items = 0;
|
let items = 0;
|
||||||
@ -9272,11 +9280,18 @@ const selectLayoutRender = ({ state = {}, prefs = {} }) => {
|
|||||||
data.recommendations.push({ placeholder: true });
|
data.recommendations.push({ placeholder: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sectionsEnabled = prefs["discoverystream.sections.enabled"];
|
||||||
|
if (sectionsEnabled) {
|
||||||
|
for (let i = 0; i < items; i++) {
|
||||||
|
data.sections[0].data.push({ placeholder: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return { ...component, data };
|
return { ...component, data };
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO update devtools to show placements
|
// TODO update devtools to show placements
|
||||||
const handleSpocs = (data, spocsPositions, spocsPlacement) => {
|
const handleSpocs = (data = [], spocsPositions, spocsPlacement) => {
|
||||||
let result = [...data];
|
let result = [...data];
|
||||||
// Do we ever expect to possibly have a spoc.
|
// Do we ever expect to possibly have a spoc.
|
||||||
if (spocsPositions?.length) {
|
if (spocsPositions?.length) {
|
||||||
@ -9560,7 +9575,7 @@ function CardSections({
|
|||||||
recommendations,
|
recommendations,
|
||||||
sections
|
sections
|
||||||
} = data;
|
} = data;
|
||||||
const isEmpty = recommendations?.length === 0 || !sections;
|
const isEmpty = !recommendations?.length || !sections;
|
||||||
const prefs = (0,external_ReactRedux_namespaceObject.useSelector)(state => state.Prefs.values);
|
const prefs = (0,external_ReactRedux_namespaceObject.useSelector)(state => state.Prefs.values);
|
||||||
const showTopics = prefs[CardSections_PREF_TOPICS_ENABLED];
|
const showTopics = prefs[CardSections_PREF_TOPICS_ENABLED];
|
||||||
const mayHaveSectionsCards = prefs[PREF_SECTIONS_CARDS_ENABLED];
|
const mayHaveSectionsCards = prefs[PREF_SECTIONS_CARDS_ENABLED];
|
||||||
@ -9628,6 +9643,11 @@ function CardSections({
|
|||||||
const {
|
const {
|
||||||
maxTile
|
maxTile
|
||||||
} = getMaxTiles(responsiveLayouts);
|
} = getMaxTiles(responsiveLayouts);
|
||||||
|
const displaySections = section.data.slice(0, maxTile);
|
||||||
|
const isSectionEmpty = !displaySections?.length;
|
||||||
|
if (isSectionEmpty) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return /*#__PURE__*/external_React_default().createElement("section", {
|
return /*#__PURE__*/external_React_default().createElement("section", {
|
||||||
key: sectionKey,
|
key: sectionKey,
|
||||||
id: sectionKey,
|
id: sectionKey,
|
||||||
@ -9649,6 +9669,11 @@ function CardSections({
|
|||||||
classNames,
|
classNames,
|
||||||
position
|
position
|
||||||
} = layoutData;
|
} = layoutData;
|
||||||
|
if (!rec || rec.placeholder) {
|
||||||
|
return /*#__PURE__*/external_React_default().createElement(PlaceholderDSCard, {
|
||||||
|
key: `dscard-${index}`
|
||||||
|
});
|
||||||
|
}
|
||||||
return /*#__PURE__*/external_React_default().createElement(DSCard, {
|
return /*#__PURE__*/external_React_default().createElement(DSCard, {
|
||||||
key: `dscard-${rec.id}`,
|
key: `dscard-${rec.id}`,
|
||||||
pos: rec.pos,
|
pos: rec.pos,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user