diff --git a/static/js/CommunityPage.jsx b/static/js/CommunityPage.jsx index fb967fd119..003323158e 100644 --- a/static/js/CommunityPage.jsx +++ b/static/js/CommunityPage.jsx @@ -48,7 +48,7 @@ const CommunityPage = ({multiPanel, toggleSignUpModal, initialWidth}) => { } else { featuredContent = } - console.log("load data from recentlyPUblished component") + return (
@@ -75,24 +75,29 @@ CommunityPage.propTypes = { const RecentlyPublished = ({multiPanel, toggleSignUpModal}) => { - const options = {}; - const pageSize = 16; - const [nSheetsLoaded, setNSheetsLoded] = useState(0); + // const options = Sefaria.interfaceLang === "hebrew" ? {"lang": "hebrew"} : {}; + const options = {}; + // options["filtered"] = true; + const pageSize = 60; + const [nSheetsLoaded, setNSheetsLoded] = useState(0); // counting sheets loaded from the API, may be different than sheets displayed // Start with recent sheets in the cache, if any - const [recentSheets, setRecentSheets] = useState(Sefaria.sheets.publicSheets(0, pageSize, options)); + const [recentSheets, setRecentSheets] = useState(collapseSheets(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 newSheets = recentSheets ? recentSheets.concat(data) : data; + console.log("Raw Sheets Data:", data); + const collapsedSheets = collapseSheets(data); + const newSheets = recentSheets ? recentSheets.concat(collapsedSheets) : collapsedSheets; setRecentSheets(newSheets); - console.log("Sheets to be displayed:", newSheets); + console.log("sheets to be displayed", newSheets) setNSheetsLoded(nSheetsLoaded + pageSize); - if (data.length < until && data.length !== 0) { - loadMore(null, until - data.length); + if (collapsedSheets.length < until && collapsedSheets.length !== 0) { + loadMore(null, until - collapsedSheets.length); } }); }; @@ -121,24 +126,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; } diff --git a/static/js/sefaria/util.js b/static/js/sefaria/util.js index d9a6ab63c3..0c95b155a6 100644 --- a/static/js/sefaria/util.js +++ b/static/js/sefaria/util.js @@ -201,16 +201,26 @@ class Util { } static naturalTime(timeStamp, {lang, short} = {}) { - // given epoch time stamp, return string of time delta between `timeStamp` and now const now = Util.epoch_time(); + const duration = now - timeStamp; // Calculate duration in milliseconds let language = lang ? lang : (Sefaria.interfaceLang === 'hebrew' ? 'he' : 'en'); let spacer = " "; if (short) { language = language === "en" ? "shortEn" : "shortBo"; - spacer = language === "shortEn" ? "" : " "; + spacer = ""; // Apply empty spacer to both shortEn and shortBo } - return Util.sefariaHumanizeDuration(now - timeStamp, {"language": language, "spacer": spacer}); + let result = Util.sefariaHumanizeDuration(duration, {"language": language, "spacer": spacer}); + if (language === "shortBo") { + const match = result.match(/^(\d+)(.*)/); + if (match) { + const number = match[1]; // Leading digits, e.g., "5" + const unit = match[2]; // Remainder, e.g., "ཆུ་ཚོད་" + result = unit + number; // Combine without space, e.g., "ཆུ་ཚོད་5" + } + } + return result; } + static object_equals(a, b) { // simple object equality assuming values are primitive. see here @@ -1169,9 +1179,9 @@ Util.sefariaHumanizeDuration = humanizeDuration.humanizer({ ms: () => "ms", }, shortBo: { - y: () => "ཕྱི་ལོ", + y: () => "ལོ་", mo: () => "ཟླ་", - w: () => "བདུན་ཕྲག་", + w: () => "བདུན་", d: () => "ཚེས་", h: () => "ཆུ་ཚོད་", m: () => "སྐར་མ་",