Skip to content
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

Website: Remove glossary duplicate data #2477

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions website2/src/app/clean-air-forum/glossary/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const GlossaryPage: React.FC = () => {
const glossaryHTML = renderContent(selectedEvent.glossary_details);
const showGlossaryMain = isValidGlossaryContent(glossaryHTML);

const glossarySections = selectedEvent.sections?.filter((section: any) => {
if (!section.pages.includes('glossary')) return false;
const html = renderContent(section.content);
return html.trim().length > 0;
});
Comment on lines +39 to +43
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve type safety and performance of section filtering.

The current implementation has a few areas for improvement:

  1. Replace any type with a proper interface
  2. Add memoization to prevent unnecessary re-renders
  3. Add proper error handling

Consider this improved implementation:

+ interface ForumSection {
+   id: string;
+   pages: string[];
+   content: string;
+ }
+
- const glossarySections = selectedEvent.sections?.filter((section: any) => {
+ const glossarySections = React.useMemo(() => 
+   selectedEvent.sections?.filter((section: ForumSection) => {
+     if (!section?.pages?.includes('glossary')) return false;
      const html = renderContent(section.content);
      return html.trim().length > 0;
-   });
+   }), [selectedEvent.sections]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const glossarySections = selectedEvent.sections?.filter((section: any) => {
if (!section.pages.includes('glossary')) return false;
const html = renderContent(section.content);
return html.trim().length > 0;
});
interface ForumSection {
id: string;
pages: string[];
content: string;
}
const glossarySections = React.useMemo(
() =>
selectedEvent.sections?.filter((section: ForumSection) => {
if (!section?.pages?.includes('glossary')) return false;
const html = renderContent(section.content);
return html.trim().length > 0;
}),
[selectedEvent.sections]
);


return (
<div className="px-4 lg:px-0 prose max-w-none flex flex-col gap-6">
<Divider className="bg-black p-0 m-0 h-[1px] w-full" />
Expand Down Expand Up @@ -95,9 +101,9 @@ const GlossaryPage: React.FC = () => {
)}

{/* Additional Glossary Sections (if any) */}
{selectedEvent.sections && selectedEvent.sections.length > 0 && (
{glossarySections && glossarySections.length > 0 && (
<>
{selectedEvent.sections.map((section: any) => (
{glossarySections.map((section: any) => (
<SectionDisplay key={section.id} section={section} />
))}
</>
Expand Down
Loading