From 698496a56d8d40dce076d3d848db61d07529a786 Mon Sep 17 00:00:00 2001 From: Michael Canova Date: Tue, 14 Oct 2025 13:08:28 -0700 Subject: [PATCH 1/7] making all pages work properly with tips --- components/work/WorkRightSidebar.tsx | 6 +++++- components/work/components/SupportersSection.tsx | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/components/work/WorkRightSidebar.tsx b/components/work/WorkRightSidebar.tsx index d0b9e317a..1608f770c 100644 --- a/components/work/WorkRightSidebar.tsx +++ b/components/work/WorkRightSidebar.tsx @@ -28,7 +28,11 @@ export const WorkRightSidebar = ({ work, metadata }: WorkRightSidebarProps) => { {hasResearchHubJournalVersions && ( )} - + {work.doi && } {work.postType !== 'QUESTION' && } diff --git a/components/work/components/SupportersSection.tsx b/components/work/components/SupportersSection.tsx index 09a46bc17..ccec6a70b 100644 --- a/components/work/components/SupportersSection.tsx +++ b/components/work/components/SupportersSection.tsx @@ -8,7 +8,7 @@ import { HeartHandshake } from 'lucide-react'; import { Button } from '@/components/ui/Button'; import { ResearchCoinIcon } from '@/components/ui/icons/ResearchCoinIcon'; import { Icon } from '@/components/ui/icons/Icon'; -import { Work } from '@/types/work'; +import { Work, ContentType } from '@/types/work'; import { TipContentModal } from '@/components/modals/TipContentModal'; import { CurrencyBadge } from '@/components/ui/CurrencyBadge'; import { useCurrencyPreference } from '@/contexts/CurrencyPreferenceContext'; @@ -16,10 +16,16 @@ import { useCurrencyPreference } from '@/contexts/CurrencyPreferenceContext'; interface SupportersSectionProps { tips: Tip[]; documentId: number; + contentType: ContentType; onTip?: () => void; } -export const SupportersSection: FC = ({ tips = [], documentId, onTip }) => { +export const SupportersSection: FC = ({ + tips = [], + documentId, + contentType, + onTip, +}) => { const [isModalOpen, setIsModalOpen] = useState(false); const [showAllSupporters, setShowAllSupporters] = useState(false); const { showUSD } = useCurrencyPreference(); @@ -119,7 +125,7 @@ export const SupportersSection: FC = ({ tips = [], docum isOpen={isModalOpen} onClose={() => setIsModalOpen(false)} contentId={documentId} - feedContentType="PAPER" + feedContentType={contentType === 'paper' ? 'PAPER' : 'POST'} onTipSuccess={handleTipSuccess} /> From 081c421563250f1b992f58f868a0e82e95c33e4c Mon Sep 17 00:00:00 2001 From: Michael Canova Date: Tue, 14 Oct 2025 13:23:32 -0700 Subject: [PATCH 2/7] console logging some information for the different types/testing --- components/work/components/SupportersSection.tsx | 10 +++++++++- types/work.ts | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/components/work/components/SupportersSection.tsx b/components/work/components/SupportersSection.tsx index ccec6a70b..2539af02a 100644 --- a/components/work/components/SupportersSection.tsx +++ b/components/work/components/SupportersSection.tsx @@ -30,6 +30,14 @@ export const SupportersSection: FC = ({ const [showAllSupporters, setShowAllSupporters] = useState(false); const { showUSD } = useCurrencyPreference(); + const feedContentType = contentType === 'paper' ? 'PAPER' : 'POST'; + console.log( + '[SupportersSection] contentType:', + contentType, + '→ feedContentType:', + feedContentType + ); + const hasSupporters = tips && tips.length > 0; const displayLimit = 5; // Show only top 5 supporters in the sidebar const displayedSupporters = showAllSupporters ? tips : tips.slice(0, displayLimit); @@ -125,7 +133,7 @@ export const SupportersSection: FC = ({ isOpen={isModalOpen} onClose={() => setIsModalOpen(false)} contentId={documentId} - feedContentType={contentType === 'paper' ? 'PAPER' : 'POST'} + feedContentType={feedContentType} onTipSuccess={handleTipSuccess} /> diff --git a/types/work.ts b/types/work.ts index 50c6a759e..8e808e2d1 100644 --- a/types/work.ts +++ b/types/work.ts @@ -268,7 +268,9 @@ export const transformPost = createTransformer((raw) => ({ ? 'preregistration' : raw.unified_document?.document_type === 'GRANT' || raw.type === 'GRANT' ? 'funding_request' - : 'post', + : raw.unified_document?.document_type === 'QUESTION' || raw.type === 'QUESTION' + ? 'question' + : 'post', note: raw.note ? transformNoteWithContent(raw.note) : undefined, publishedDate: raw.created_date, // Posts use created_date for both previewContent: raw.full_markdown || '', From a397ad5fb86831a22b5ad14778b1394518aa1ce1 Mon Sep 17 00:00:00 2001 From: Michael Canova Date: Tue, 14 Oct 2025 13:30:25 -0700 Subject: [PATCH 3/7] more testing --- hooks/useTip.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hooks/useTip.ts b/hooks/useTip.ts index 30e28a53e..073b33fc0 100644 --- a/hooks/useTip.ts +++ b/hooks/useTip.ts @@ -65,6 +65,14 @@ export function useTip({ contentId, feedContentType, onTipSuccess, onTipError }: setIsTipping(true); const contentType = mapFeedContentTypeToTipContentType(feedContentType); + console.log( + '[useTip] feedContentType:', + feedContentType, + '→ contentType:', + contentType, + 'objectId:', + contentId + ); // Call service with camelCase args const response = await TransactionService.tipContentTransaction({ From a79c906e468c08da54f04dab56da49eecfdf70a5 Mon Sep 17 00:00:00 2001 From: Michael Canova Date: Tue, 14 Oct 2025 14:12:02 -0700 Subject: [PATCH 4/7] some cleanup and testing --- components/work/components/SupportersSection.tsx | 11 +---------- hooks/useTip.ts | 8 -------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/components/work/components/SupportersSection.tsx b/components/work/components/SupportersSection.tsx index 2539af02a..bedbbf05c 100644 --- a/components/work/components/SupportersSection.tsx +++ b/components/work/components/SupportersSection.tsx @@ -30,14 +30,6 @@ export const SupportersSection: FC = ({ const [showAllSupporters, setShowAllSupporters] = useState(false); const { showUSD } = useCurrencyPreference(); - const feedContentType = contentType === 'paper' ? 'PAPER' : 'POST'; - console.log( - '[SupportersSection] contentType:', - contentType, - '→ feedContentType:', - feedContentType - ); - const hasSupporters = tips && tips.length > 0; const displayLimit = 5; // Show only top 5 supporters in the sidebar const displayedSupporters = showAllSupporters ? tips : tips.slice(0, displayLimit); @@ -128,12 +120,11 @@ export const SupportersSection: FC = ({ )} - {/* Tip Modal */} setIsModalOpen(false)} contentId={documentId} - feedContentType={feedContentType} + feedContentType={contentType === 'paper' ? 'PAPER' : 'POST'} onTipSuccess={handleTipSuccess} /> diff --git a/hooks/useTip.ts b/hooks/useTip.ts index 073b33fc0..30e28a53e 100644 --- a/hooks/useTip.ts +++ b/hooks/useTip.ts @@ -65,14 +65,6 @@ export function useTip({ contentId, feedContentType, onTipSuccess, onTipError }: setIsTipping(true); const contentType = mapFeedContentTypeToTipContentType(feedContentType); - console.log( - '[useTip] feedContentType:', - feedContentType, - '→ contentType:', - contentType, - 'objectId:', - contentId - ); // Call service with camelCase args const response = await TransactionService.tipContentTransaction({ From c46b22a1b9d91afdbe73091f0d719518a8a13bec Mon Sep 17 00:00:00 2001 From: Michael Canova Date: Tue, 14 Oct 2025 16:01:14 -0700 Subject: [PATCH 5/7] readding the tip consolidation --- .../work/components/SupportersSection.tsx | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/components/work/components/SupportersSection.tsx b/components/work/components/SupportersSection.tsx index bedbbf05c..fdd2aa928 100644 --- a/components/work/components/SupportersSection.tsx +++ b/components/work/components/SupportersSection.tsx @@ -1,6 +1,6 @@ 'use client'; -import { FC, useState } from 'react'; +import { FC, useState, useMemo } from 'react'; import { Avatar } from '@/components/ui/Avatar'; import { formatRSC } from '@/utils/number'; import { Tip } from '@/types/tip'; @@ -30,10 +30,23 @@ export const SupportersSection: FC = ({ const [showAllSupporters, setShowAllSupporters] = useState(false); const { showUSD } = useCurrencyPreference(); - const hasSupporters = tips && tips.length > 0; - const displayLimit = 5; // Show only top 5 supporters in the sidebar - const displayedSupporters = showAllSupporters ? tips : tips.slice(0, displayLimit); - const hasMoreSupporters = tips.length > displayLimit; + const consolidatedTips = useMemo(() => { + const byUser = tips.reduce((acc, { user, amount }) => { + const existing = acc.get(user.id); + return acc.set(user.id, { + user, + amount: (existing?.amount || 0) + amount, + }); + }, new Map()); + return Array.from(byUser.values()).sort((a, b) => b.amount - a.amount); + }, [tips]); + + const hasSupporters = consolidatedTips.length > 0; + const displayLimit = 5; + const displayedSupporters = showAllSupporters + ? consolidatedTips + : consolidatedTips.slice(0, displayLimit); + const hasMoreSupporters = consolidatedTips.length > displayLimit; const handleTipSuccess = (amount: number) => { // Close the modal and potentially refresh data @@ -59,20 +72,22 @@ export const SupportersSection: FC = ({ {hasSupporters ? ( <>
- {displayedSupporters.map((tip, index) => ( -
+ {displayedSupporters.map((supporter) => ( +
- {tip.user.fullName} + + {supporter.user.fullName} +
+ = ({ onClick={() => setShowAllSupporters(!showAllSupporters)} className="text-sm text-blue-600 hover:text-blue-800 font-medium mt-3 w-full text-center" > - {showAllSupporters ? 'Show less' : `View all supporters (${tips.length})`} + {showAllSupporters ? 'Show less' : `View all supporters (${consolidatedTips.length})`} )} From c7cea09d578595b6f3627772f778471fea44862c Mon Sep 17 00:00:00 2001 From: Michael Canova Date: Tue, 14 Oct 2025 16:13:39 -0700 Subject: [PATCH 6/7] reverting consolidation after testing --- .../work/components/SupportersSection.tsx | 37 ++++++------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/components/work/components/SupportersSection.tsx b/components/work/components/SupportersSection.tsx index fdd2aa928..bd7e75e17 100644 --- a/components/work/components/SupportersSection.tsx +++ b/components/work/components/SupportersSection.tsx @@ -1,6 +1,6 @@ 'use client'; -import { FC, useState, useMemo } from 'react'; +import { FC, useState } from 'react'; import { Avatar } from '@/components/ui/Avatar'; import { formatRSC } from '@/utils/number'; import { Tip } from '@/types/tip'; @@ -30,23 +30,10 @@ export const SupportersSection: FC = ({ const [showAllSupporters, setShowAllSupporters] = useState(false); const { showUSD } = useCurrencyPreference(); - const consolidatedTips = useMemo(() => { - const byUser = tips.reduce((acc, { user, amount }) => { - const existing = acc.get(user.id); - return acc.set(user.id, { - user, - amount: (existing?.amount || 0) + amount, - }); - }, new Map()); - return Array.from(byUser.values()).sort((a, b) => b.amount - a.amount); - }, [tips]); - - const hasSupporters = consolidatedTips.length > 0; + const hasSupporters = tips && tips.length > 0; const displayLimit = 5; - const displayedSupporters = showAllSupporters - ? consolidatedTips - : consolidatedTips.slice(0, displayLimit); - const hasMoreSupporters = consolidatedTips.length > displayLimit; + const displayedSupporters = showAllSupporters ? tips : tips.slice(0, displayLimit); + const hasMoreSupporters = tips.length > displayLimit; const handleTipSuccess = (amount: number) => { // Close the modal and potentially refresh data @@ -72,22 +59,20 @@ export const SupportersSection: FC = ({ {hasSupporters ? ( <>
- {displayedSupporters.map((supporter) => ( -
+ {displayedSupporters.map((tip, index) => ( +
- - {supporter.user.fullName} - + {tip.user.fullName}
+ = ({ onClick={() => setShowAllSupporters(!showAllSupporters)} className="text-sm text-blue-600 hover:text-blue-800 font-medium mt-3 w-full text-center" > - {showAllSupporters ? 'Show less' : `View all supporters (${consolidatedTips.length})`} + {showAllSupporters ? 'Show less' : `View all supporters (${tips.length})`} )} From c9fcf8176320d76f061dcff6167c826a58ba1bc4 Mon Sep 17 00:00:00 2001 From: Michael Canova Date: Tue, 14 Oct 2025 16:19:58 -0700 Subject: [PATCH 7/7] removing extra statement from work.ts --- types/work.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/types/work.ts b/types/work.ts index 8e808e2d1..50c6a759e 100644 --- a/types/work.ts +++ b/types/work.ts @@ -268,9 +268,7 @@ export const transformPost = createTransformer((raw) => ({ ? 'preregistration' : raw.unified_document?.document_type === 'GRANT' || raw.type === 'GRANT' ? 'funding_request' - : raw.unified_document?.document_type === 'QUESTION' || raw.type === 'QUESTION' - ? 'question' - : 'post', + : 'post', note: raw.note ? transformNoteWithContent(raw.note) : undefined, publishedDate: raw.created_date, // Posts use created_date for both previewContent: raw.full_markdown || '',