Content-Length: 650367 | pFad | http://github.com/Sefaria/Sefaria-Project/pull/2338

9C Feature/sc 32283/sheets desktop update topics homepage navigation by stevekaplan123 · Pull Request #2338 · Sefaria/Sefaria-Project · GitHub
Skip to content

Feature/sc 32283/sheets desktop update topics homepage navigation #2338

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 Feb 18, 2025

Description

This PR implements a topic TOC for the sheets module. 1) As opposed to the library module, the topics TOC is not the topics landing page but is the old TopicsPage component. 2) The Topics TOC in the sheets module only shows topics that have sheets associated with them. 3) When viewing a topic category in either the library or sheets module, we only show topics that are appropriate for the given module. In other words, in the sheets module, subtopics are only shown if that subtopic has sheets associated with it, and likewise, in the library module, subtopics are only shown if they have library sources associated with them.

Code Changes

  1. I created a new component TopicTOCCard to display topics throughout the topic TOC. The TopicsPage component and TopicCategory components now use TopicTOCCard.
  2. Most of the changes in this PR were from this PR. There is very little in this PR specifically required to implement the sheets module topics TOC. The logic is basically just that (a) when building the topic TOC on the backend in model/text.py in get_topic_toc_json_recursive, we add a new property to each topic object called pools, which is just an array of the topic pools that the topic belongs to. Then, when we already on a topic category page, such as prayer, when we render the TopicCategory component, we call a function shouldDisplay to determine if each subtopic (such as Aleinu) actually belongs to the sheets/library topic pool. See the function shouldDisplay in TopicPage.jsx where we filter out all subtopics that are not appropriate for the given Sefaria.activeModule:
const TopicCategory = ({topic, topicTitle, setTopic, setNavTopic, initialWidth,
  openSearch}) => {
    const [topicData, setTopicData] = useState(Sefaria.getTopicFromCache(topic) || {primaryTitle: topicTitle});
    const [subtopics, setSubtopics] = useState(Sefaria.topicTocPage(topic));
@@ -226,38 +230,15 @@ const TopicCategory = ({topic, topicTitle, setTopic, setNavTopic, compare, initi
        setSubtopics(Sefaria.topicTocPage(topic));
    }, [topic]);

    const shouldDisplay = (t) => {
      const inActiveModule = t.pools.includes(Sefaria.activeModule);
      return t.shouldDisplay !== false && inActiveModule;
    }

    let topicBlocks = subtopics
      .filter(shouldDisplay)
      .sort(Sefaria.sortTopicsCompareFn)
      .map((topic, i) => <TopicTOCCard topic={topic} setTopic={setTopic} setNavTopic={setNavTopic} key={i}/>);

@stevekaplan123 stevekaplan123 changed the base branch from modularization-main to modukarization-themes-sheets-homepage-refactor March 12, 2025 10:14
@stevekaplan123 stevekaplan123 changed the base branch from modukarization-themes-sheets-homepage-refactor to modulrization-themes March 12, 2025 10:15
@stevekaplan123 stevekaplan123 changed the base branch from modulrization-themes to modularization-main March 12, 2025 10:15
@stevekaplan123 stevekaplan123 marked this pull request as ready for review March 20, 2025 08: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.

Pull Request Overview

This PR implements module-specific topic displays by supplementing topic entries with a "pools" property and updating the navigation components. Key changes include:

  • Adding a "pools" field for topics in the TOC in text.py.
  • Updating TopicPage.jsx to filter topics based on the active module.
  • Adjusting sidebar components and navigation in NavSidebar.jsx, ReaderPanel.jsx, and TopicsPage.jsx.

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
static/js/TopicPage.jsx Introduces a new topic filter function and refactors topic block rendering.
static/js/NavSidebar.jsx Adds a new sidebar module component "JoinTheConversation".
sefaria/urls.py Introduces new URL routes for sheets topics.
static/js/ReaderPanel.jsx Updates menu rendering based on the active module.
static/js/TopicsPage.jsx Modifies sidebar module list to include "JoinTheConversation".
sefaria/model/text.py Adds support for a "pools" key in the topic TOC JSON output.
Files not reviewed (1)
  • static/css/s2.css: Language not supported

…navigation' into feature/sc-26865/sheets-desktop-topics-display-sheets-only
@@ -5157,7 +5158,8 @@ def get_topic_toc_json_recursive(self, topic=None, explored=None, with_descripti
"shouldDisplay": True if len(children) > 0 else topic.should_display(),
"en": topic.get_primary_title("en"),
"he": topic.get_primary_title("he"),
"displayOrder": getattr(topic, "displayOrder", 10000)
"displayOrder": getattr(topic, "displayOrder", 10000),
"pools": DjangoTopic.objects.slug_to_pools[topic.slug]
Copy link
Contributor

Choose a reason for hiding this comment

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

if i understand correctly, that changes an API response object.

  1. it seems ok for me, but i think those changes (although small) should be considered from architecture POV.
  2. IMHO it would be better to add reader_views.topic_page a param that says if it's for library or sheet, and mpving the filtering logics to the server side.
  3. if we have this response in the dev portal, it should be reflected there also, so you should change the json accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

@YishaiGlasner Are you sure this changes an API response? Which API url does it change?

Re 2. I do agree that we should take advantage of the request.active_module attribute set in the ModuleMiddleware to either sheets or library to take advantage of filtering the list of topics on the backend, although I see no problem having the pools remain on this object, since it's cached anyways.

Copy link
Contributor

Choose a reason for hiding this comment

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

@yitzhakc i think it adds the key pools to topics/

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 don't think this changes any API results. This changes the Sefaria._topics cache which is handled by the front-end only. /api/topics is not affected by this. And yes, this adds a 'pools' key to every topic in the Sefaria._topics cache. The reason I did it this way is because reader_views.topic_page only gets called if someone loads a topic page server side. Therefore, if you navigate to "Explore" and then go to a topic page, reader_views.topic_page won't get called. Instead, the front-end will use the Sefaria._topics cache. The problem is that this cache gets set on the backend by get_topic_toc_json (which is in turn called by large_data in context_processors.py) when the server initially loads. This happens long before any request is received with an active_module parameter. Therefore, I don't see how we could take advantage of the active_module parameter in the request.

@@ -5157,7 +5158,8 @@ def get_topic_toc_json_recursive(self, topic=None, explored=None, with_descripti
"shouldDisplay": True if len(children) > 0 else topic.should_display(),
"en": topic.get_primary_title("en"),
"he": topic.get_primary_title("he"),
"displayOrder": getattr(topic, "displayOrder", 10000)
"displayOrder": getattr(topic, "displayOrder", 10000),
"pools": DjangoTopic.objects.slug_to_pools[topic.slug]
Copy link
Contributor

Choose a reason for hiding this comment

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

@YishaiGlasner Are you sure this changes an API response? Which API url does it change?

Re 2. I do agree that we should take advantage of the request.active_module attribute set in the ModuleMiddleware to either sheets or library to take advantage of filtering the list of topics on the backend, although I see no problem having the pools remain on this object, since it's cached anyways.

stevekaplan123 and others added 5 commits May 12, 2025 00:24
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…-topics-display-sheets-only

Feature/sc 26865/sheets desktop topics display sheets only
@stevekaplan123 stevekaplan123 changed the base branch from modularization-main to feature/sc-26865/sheets-desktop-topics-display-sheets-only May 25, 2025 08:59
@stevekaplan123 stevekaplan123 changed the base branch from feature/sc-26865/sheets-desktop-topics-display-sheets-only to master May 25, 2025 09:01
@stevekaplan123 stevekaplan123 changed the base branch from master to feature/sc-26865/sheets-desktop-topics-display-sheets-only May 25, 2025 09:04
@stevekaplan123 stevekaplan123 marked this pull request as ready for review May 25, 2025 09:18
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 adds a topic table of contents (TOC) card component and refactors both client and server logic to support module-specific topic navigation (library vs. sheets). Key changes include

  • New TopicTOCCard component and refactoring of TopicsPage/TopicCategory to use it
  • Backend updates (processTopicsTabsData, URL patterns, view logic) to handle sheets vs. library pools and module-specific topic tabs
  • Introduction of _getShortInterfaceLang helper and widespread refactoring of interface-language slicing

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
static/js/common/TopicTOCCard.jsx Added reusable TOC card for topics
static/js/sefaria/sefaria.js Replaced processTopicsData with processTopicsTabsData; added tab derivation, module-specific trending, and _getShortInterfaceLang
static/js/TopicsPage.jsx Switched to TopicTOCCard for root topics page; updated sidebar
sourcesheets/views.py Updated trending tags API to accept n parameter
sefaria/urls.py Added /sheets/topics/ URL patterns
sefaria/model/text.py Included pools in topic TOC JSON
reader/views.py Refactored topic_page view for slug parameter and module checks
[Various other JS/CSS files] Refactored language-slice logic; added join-conversation sidebar module and styles

@stevekaplan123 stevekaplan123 changed the base branch from feature/sc-26865/sheets-desktop-topics-display-sheets-only to modularization-main May 25, 2025 09:19
stevekaplan123 and others added 4 commits May 28, 2025 09:55
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@stevekaplan123 stevekaplan123 force-pushed the feature/sc-32283/sheets-desktop-update-topics-homepage-navigation branch from e69039b to e70f746 Compare May 29, 2025 08:57
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 a module-aware topic table of contents (TOC) for the sheets module by extending topic card rendering and backend tab logic.

  • Introduces TopicTOCCard for consistent topic listing across pages
  • Refactors topic data processing to assign refs into module-specific tabs
  • Adds pools metadata on topics and filters subtopics by active module

Reviewed Changes

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

Show a summary per file
File Description
static/js/sefaria/sefaria.js Adds processTopicsTabsData and _deriveTabDataForTopicLink, updates topic caching to use module-specific pools
static/js/common/TopicTOCCard.jsx New component for rendering topic cards in category pages
static/js/TopicsPage.jsx Replaces manual category listing with TopicTOCCard and updates sidebar modules
static/js/TopicPageAll.jsx Switches to central _getShortInterfaceLang helper
static/js/TopicLandingPage/TopicsLandingPage.jsx Uses generic TrendingTopics in sidebar
static/js/TopicLandingPage/TopicLandingNewsletter.jsx Uses _getShortInterfaceLang for newsletter analytics
static/js/TopicEditor.jsx Simplifies language selection via Sefaria._v
static/js/Story.jsx Centralizes short-code language helper
static/js/StaticPages.jsx Uses _getShortInterfaceLang for locale in sorting
static/js/SourceEditor.jsx Applies short-code helper for sheet descriptions
static/js/ReaderPanel.jsx Renders TopicsPage in sheets module and TopicsLandingPage in library
static/js/ReaderApp.jsx Adopts _getShortInterfaceLang for interface language slicing
static/js/NavSidebar.jsx Adds "JoinTheConversation" module and cleans up trending mapping
static/css/s2.css Styles .joinTheConversation and clamps card descriptions
sourcesheets/views.py Validates n parameter in trending tags API
sefaria/utils/util.py Adds get_short_lang helper
sefaria/urls.py Adds routes for sheets topic pages
sefaria/model/text.py Extends TOC JSON with pools for module filtering
reader/views.py Applies get_short_lang in view logic and enforces module access
Comments suppressed due to low confidence (4)

static/js/sefaria/sefaria.js:2858

  • [nitpick] The new processTopicsTabsData function introduces module-specific tab assignment logic but lacks accompanying unit tests. Consider adding tests to verify correct tab grouping for both library and sheets modules.
processTopicsTabsData: function(topicData) {

static/js/common/TopicTOCCard.jsx:10

  • The openTopic handler references children, slug, en, and he before they are declared (TDZ error). Move the destructuring of topic above this handler or reference topic.slug etc. directly inside the function.
children ? setNavTopic(slug, {en, he}) : setTopic(slug, {en, he});

static/js/ReaderPanel.jsx:951

  • TopicsPage is used here but not imported in this file, causing a ReferenceError. Add import { TopicsPage } from './TopicsPage'; at the top.
menu = <TopicsPage

sourcesheets/views.py:966

  • This error response returns JSON without an HTTP error status. Consider returning a 400 Bad Request (e.g., jsonResponse(..., status=400)) to more clearly signal client input error.
return jsonResponse({"error": "Invalid value for parameter 'n'. It must be an integer."})

@stevekaplan123 stevekaplan123 requested a review from Copilot May 29, 2025 09:08
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 an updated topics table-of-contents (TOC) for the sheets module that filters topics based on the module (sheets vs. library) and updates related views, components, and APIs.

  • Introduces a new TopicTOCCard component to standardize topic presentation.
  • Updates the topics processor to processTopicsTabsData and applies topic pool filtering in the backend.
  • Adjusts trending topics API calls, URL routes, and various UI components for proper handling of the active module.

Reviewed Changes

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

Show a summary per file
File Description
static/js/sefaria/sefaria.js Updates topics processor, trending topics functions, and language helpers.
static/js/common/TopicTOCCard.jsx New component for rendering topic cards with conditional navigation.
static/js/TopicsPage.jsx Replaces legacy category rendering with TopicTOCCard usage.
static/js/TopicPageAll.jsx Updates topic sorting to leverage the new language helper.
static/js/TopicLandingPage/* Adjusts trending topics module and newsletter language handling.
static/js/TopicEditor.jsx, Story.jsx, etc. Refactors usage of language conversion to Sefaria._getShortInterfaceLang.
static/css/s2.css Adds styling for card clamping and spacing adjustments.
sourcesheets/views.py Enhances trending topics API endpoint with parameter validation.
sefaria/utils/util.py Adds a helper function to convert full language strings to short codes.
sefaria/urls.py Introduces new URL routes for sheets topics.
sefaria/model/text.py Adds new property ‘pools’ for topics to facilitate module filtering.
reader/views.py Updates topic page processing to normalize slugs and filter topics by active module.
Comments suppressed due to low confidence (1)

static/js/common/TopicTOCCard.jsx:8

  • The openTopic function uses the 'children' variable before its destructuring assignment. Consider moving the destructuring of { slug, children } to before the definition of openTopic to ensure the variable is defined when used.
const openTopic = e => { e.preventDefault(); children ? setNavTopic(slug, {en, he}) : setTopic(slug, {en, he}); }

@stevekaplan123 stevekaplan123 requested a review from yitzhakc June 3, 2025 10:09
@stevekaplan123 stevekaplan123 merged commit 8f6c13b into modularization-main Jun 4, 2025
21 of 27 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/2338

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy