Content-Length: 725823 | pFad | http://github.com/Sefaria/Sefaria-Project/pull/2398

B4 Feature/sc 26865/sheets desktop topics display sheets only by stevekaplan123 · Pull Request #2398 · Sefaria/Sefaria-Project · GitHub
Skip to content

Feature/sc 26865/sheets desktop topics display sheets only #2398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

stevekaplan123
Copy link
Contributor

@stevekaplan123 stevekaplan123 commented Apr 2, 2025

Description

This PR implements a requirement for modularization -- while in the 'sheets' module, topic pages should only display sheet sources rather than library sources.

Code Changes

  1. I re-factored the TopicPage component to make the component smaller and easier to read. I pulled out a lot of functionality into a new component TopicPageTabView which wrap the existing component TabView.
  2. processTopicsTabsData -- This is the substantive change for this PR. This function gets called whenever the topic API is called. This function makes sure that the Sefaria._topics cache entry for the given topic contains the appropriate tabs. In the case of the 'sheets' module, this function will now put the topics' ref links in the 'sheets' tab in the cache, whereas in the 'library' module, the refs will be stored under the 'sources' or 'notable-sources' tab. For example, suppose I go to the library today to the topic "Pharoah". Sefaria._topics Pharoah entry will look like this with 186 refs in the 'sources' tab:
image In order to do this, I created a helper function _createTabKeyAndTitle to simplify the code.

@stevekaplan123 stevekaplan123 changed the base branch from modularization-main to feature/sc-32283/sheets-desktop-update-topics-homepage-navigation April 2, 2025 15:46
@stevekaplan123 stevekaplan123 marked this pull request as ready for review April 2, 2025 16:14
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modularizes topic page components to support displaying sheet sources exclusively in the 'sheets' module while preserving the library source display in the 'library' module. Key changes include updating processTopicsData to properly filter and rename tabs based on active modules, renaming tab keys to use consistent, capitalized naming, and integrating new components (TopicPageTabs and AuthorIndexItems) into TopicPage for improved readability and maintainability.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
static/js/sefaria/sefaria.js Updates the processTopicsData function to filter references by module and refines tab key naming.
static/js/TopicPage.jsx Adjusts tab key values, updates conditional checks accordingly, and integrates new components to modularize the topic page UI.
Comments suppressed due to low confidence (3)

static/js/sefaria/sefaria.js:2916

  • Ensure that the capitalization changes for tab keys (e.g., 'Notable Sources') are consistently updated across all related translation and comparison functions.
if (tabs["Notable Sources"]) {

static/js/TopicPage.jsx:661

  • Verify that the tab name comparisons here match the new, capitalized naming convention to prevent any logical regressions in tab selection.
if (displayTabs.length && tab !== "Notable Sources" && tab !== "Author Works on Sefaria") {

static/js/TopicPage.jsx:803

  • [nitpick] Consider extracting the AuthorIndexItems and TopicPageTabs components into separate modules to improve maintainability and adhere to a clearer separation of concerns.
const AuthorIndexItems = ({topicData}) => {

@stevekaplan123 stevekaplan123 changed the base branch from feature/sc-32283/sheets-desktop-update-topics-homepage-navigation to modularization-main April 7, 2025 08:16
@stevekaplan123 stevekaplan123 changed the base branch from modularization-main to feature/sc-32283/sheets-desktop-update-topics-homepage-navigation April 7, 2025 13:05
@stevekaplan123 stevekaplan123 changed the base branch from feature/sc-32283/sheets-desktop-update-topics-homepage-navigation to master April 7, 2025 13:10
@stevekaplan123 stevekaplan123 changed the base branch from master to feature/sc-32283/sheets-desktop-update-topics-homepage-navigation April 7, 2025 13:11
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • static/css/s2.css: Language not supported
Comments suppressed due to low confidence (1)

static/js/TopicPage.jsx:587

  • React hooks must be called unconditionally in the top-level of a component or custom hook. Calling useIncrementalLoad within the helper function setupDisplayTabs may violate the rules of hooks; consider refactoring setupDisplayTabs into a custom hook.
useIncrementalLoad(tabObj.fetcher, refsToFetchByTab[key] || false, Sefaria._topicPageSize, data => onIncrementalLoad(data, key), topic);

@stevekaplan123 stevekaplan123 requested a review from Copilot April 28, 2025 13:37
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the modularization of topic pages so that when viewing topics in the sheets module only sheet sources are displayed. Key changes include:

  • Refactoring of the TopicPage component and extraction of helper functions to set up tabs.
  • Updating the topic API processing by replacing processTopicsData with processTopicsTabsData and introducing a new helper method (_createTabKeyAndTitle).
  • Adjustments in the TopicPageTab view and bulk sheet fetch to correctly handle sheet identifiers.

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
static/js/sefaria/strings.js Added new localized string for "Top Citations."
static/js/sefaria/sefaria.js Updated topic API processor to use processTopicsTabsData and added helper method _createTabKeyAndTitle.
static/js/TopicPage.jsx Refactored TopicPage component, renamed hooks and updated sheet fetching logic.
Files not reviewed (1)
  • static/css/s2.css: Language not supported

for (let [linkType, topicLinks] of Object.entries(topicData.refs)) {
let refs = topicLinks.refs.filter(refObj => (Sefaria.activeModule === 'sheets') === refObj.is_sheet);
for (let refObj of refs) {
const {tabKey, title} = _createTabKeyAndTitle(linkType, refObj);
Copy link
Preview

Copilot AI Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since _createTabKeyAndTitle is defined as a method on the Sefaria object, ensure that it is invoked with the correct context (e.g. this._createTabKeyAndTitle(linkType, refObj)) to avoid undefined behavior.

Suggested change
const {tabKey, title} = _createTabKeyAndTitle(linkType, refObj);
const {tabKey, title} = Sefaria._createTabKeyAndTitle(linkType, refObj);

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@akiva10b akiva10b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have a look at other tab views and see if there are any reusable components here

@stevekaplan123
Copy link
Contributor Author

stevekaplan123 commented Apr 29, 2025

have a look at other tab views and see if there are any reusable components here

I don't see how to immediately make TopicPageTabView work based on purely reusable components, although I noticed a few things that could be cleaned up. First of all, every client of TabView creates an array 'tabs' which is just a list of javascript objects and the client also passes a renderTab function to TabView. These renderTab functions are very similar to each other and it seems like we should just have a component Tab that handles the data passed to the array and also can render itself. I also found one glaring issue that entangles TabView (which we use many times on the site) to TopicPageTabView. Strangely, the filter button and lang toggle for TopicPageTabView are considered tabs which makes no sense conceptually and also entangles the two components together more than they need to be. In the CollectionsPage we also consider filter to be a tab so that component could also be cleaned up by separating filter/lang toggles out of TabView.

@yitzhakc

@stevekaplan123 stevekaplan123 changed the base branch from feature/sc-32283/sheets-desktop-update-topics-homepage-navigation to master May 6, 2025 08:28
@stevekaplan123 stevekaplan123 changed the base branch from master to feature/sc-32283/sheets-desktop-update-topics-homepage-navigation May 6, 2025 08:29
…navigation' into feature/sc-26865/sheets-desktop-topics-display-sheets-only
@yitzhakc
Copy link
Contributor

yitzhakc commented May 8, 2025

have a look at other tab views and see if there are any reusable components here

I don't see how to immediately make TopicPageTabView work based on purely reusable components, although I noticed a few things that could be cleaned up. First of all, every client of TabView creates an array 'tabs' which is just a list of javascript objects and the client also passes a renderTab function to TabView. These renderTab functions are very similar to each other and it seems like we should just have a component Tab that handles the data passed to the array and also can render itself. I also found one glaring issue that entangles TabView (which we use many times on the site) to TopicPageTabView. Strangely, the filter button and lang toggle for TopicPageTabView are considered tabs which makes no sense conceptually and also entangles the two components together more than they need to be. In the CollectionsPage we also consider filter to be a tab so that component could also be cleaned up by separating filter/lang toggles out of TabView.

@yitzhakc

I agree @stevekaplan123, I would love for us to turn the filter button and language toggle into separate components and not tabs. But I don't think it should be done in this PR, we should create a separate story and PR so as not to break the scope here.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the display logic change for topic pages in the sheets module by refactoring topics data processing and splitting the TopicPage component into smaller components. Key changes include updating the topics data processor in sefaria.js, refactoring TopicPageTab view and related fetch functions in TopicPage.jsx, and adding a new translation string in strings.js.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
static/js/sefaria/strings.js Added a new translation string for "Top Citations".
static/js/sefaria/sefaria.js Replaced processTopicsData with processTopicsTabsData and added helper _deriveTabDataForTopicLink for proper tab mapping.
static/js/TopicPage.jsx Refactored fetchBulkSheet and TopicPage logic; reorganized tab setup and useEffect cleanups.
static/css/s2.css Updated CSS selectors for clamped text in card descriptions.

} else {
setLoadedData(prev => ({...prev, [tabKey]: tabObj.loadedData}));
}
}
})());
promise.catch((error) => { if (!error.isCanceled) { console.log('TopicPage Error', error); } });
Copy link
Preview

Copilot AI May 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The promise returned from the self-invoking async function is not stored in a variable before calling 'promise.catch'. Assign the result of the async invocation to a variable (e.g., 'const promise = (async () => { ... })();') to handle errors properly.

Copilot uses AI. Check for mistakes.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
}
else {
if (linkType === 'about') {
const lang = Sefaria.interfaceLang === "hebrew" ? 'he' : 'en';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think Sefaria.interfaceLang.slice(0, 2) is more readable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YishaiGlasner I don't think that's so readable either 🙈

@stevekaplan123 maybe better to add a helper function to Sefaria.js that returns he or en? I.e that encapsulates this logic? It feels like we have it in lots of places...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YishaiGlasner @yitzhakc I'm creating a helper function Sefaria._getShortInterfaceLang()
How does this sound?
It can replace 15-20 cases throughout the site

}
else {
if (linkType === 'about') {
const lang = Sefaria.interfaceLang === "hebrew" ? 'he' : 'en';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YishaiGlasner I don't think that's so readable either 🙈

@stevekaplan123 maybe better to add a helper function to Sefaria.js that returns he or en? I.e that encapsulates this logic? It feels like we have it in lots of places...

@stevekaplan123 stevekaplan123 requested review from yitzhakc and YishaiGlasner and removed request for yonadavGit May 14, 2025 07:18
@stevekaplan123 stevekaplan123 merged commit 8f64e2a into feature/sc-32283/sheets-desktop-update-topics-homepage-navigation May 22, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/Sefaria/Sefaria-Project/pull/2398

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy