Skip to content

Commit

Permalink
collapseSheets_component_disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Lungsangg committed Feb 19, 2025
1 parent f2cdc49 commit 4cfb551
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions static/js/CommunityPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,24 @@ CommunityPage.propTypes = {


const RecentlyPublished = ({multiPanel, toggleSignUpModal}) => {
// const options = Sefaria.interfaceLang === "hebrew" ? {"lang": "hebrew"} : {};
const options = {};
// options["filtered"] = true;
const options = {};
const pageSize = 10;
const [nSheetsLoaded, setNSheetsLoded] = useState(0); // counting sheets loaded from the API, may be different than sheets displayed
const [nSheetsLoaded, setNSheetsLoded] = useState(0);
// Start with recent sheets in the cache, if any
const [recentSheets, setRecentSheets] = useState(collapseSheets(Sefaria.sheets.publicSheets(0, pageSize, options)));
const [recentSheets, setRecentSheets] = useState(Sefaria.sheets.publicSheets(0, pageSize, options));

// But also make an API call immeditately to check for updates
useEffect(() => {
loadMore();
}, []);

const loadMore = (e, until=pageSize) => {
Sefaria.sheets.publicSheets(nSheetsLoaded, pageSize, options, true, (data) => {
const collapsedSheets = collapseSheets(data);
const newSheets = recentSheets ? recentSheets.concat(collapsedSheets) : collapsedSheets;
const newSheets = recentSheets ? recentSheets.concat(data) : data;
setRecentSheets(newSheets);
console.log("Sheets to be displayed:", newSheets);
setNSheetsLoded(nSheetsLoaded + pageSize);
if (collapsedSheets.length < until && collapsedSheets.length !== 0) {
loadMore(null, until - collapsedSheets.length);
if (data.length < until && data.length !== 0) {
loadMore(null, until - data.length);
}
});
};
Expand Down Expand Up @@ -124,24 +121,24 @@ const RecentlyPublished = ({multiPanel, toggleSignUpModal}) => {
};


const collapseSheets = (sheets) => {
// Collapses consecutive sheets with the same author
if (!sheets) { return null; }

return sheets.reduce((accum, sheet) => {
if (!accum.length) {
return [sheet];
}
const prev = accum[accum.length-1];
if (prev.author === sheet.author) {
prev.moreSheets = prev.moreSheets || [];
prev.moreSheets.push(sheet);
} else {
accum.push(sheet);
}
return accum;
}, []);
}
// const collapseSheets = (sheets) => {
// // Collapses consecutive sheets with the same author
// if (!sheets) { return null; }

// return sheets.reduce((accum, sheet) => {
// if (!accum.length) {
// return [sheet];
// }
// const prev = accum[accum.length-1];
// if (prev.author === sheet.author) {
// prev.moreSheets = prev.moreSheets || [];
// prev.moreSheets.push(sheet);
// } else {
// accum.push(sheet);
// }
// return accum;
// }, []);
// }

const FeaturedSheet = ({sheet, showDate, trackClicks, toggleSignUpModal}) => {
if (!sheet) { return null; }
Expand Down

0 comments on commit 4cfb551

Please sign in to comment.