-
Notifications
You must be signed in to change notification settings - Fork 12
feat(Research): Rebuild -- Research page, Papers library and dashboard #115
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,92 @@ | ||||||||||||||||||
| "use client" | ||||||||||||||||||
|
|
||||||||||||||||||
| import { useCallback, useState } from "react" | ||||||||||||||||||
|
|
||||||||||||||||||
| import { TrackSpotlight } from "./TrackSpotlight" | ||||||||||||||||||
| import type { AnchorPreviewItem, ResearchTrackSummary, TrackFeedItem } from "@/lib/types" | ||||||||||||||||||
|
|
||||||||||||||||||
| interface TrackSpotlightSectionProps { | ||||||||||||||||||
| initialTracks: ResearchTrackSummary[] | ||||||||||||||||||
| initialActiveTrack: ResearchTrackSummary | null | ||||||||||||||||||
| initialFeedItems: TrackFeedItem[] | ||||||||||||||||||
| initialFeedTotal: number | ||||||||||||||||||
| initialAnchors: AnchorPreviewItem[] | ||||||||||||||||||
| userId?: string | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| export function TrackSpotlightSection({ | ||||||||||||||||||
| initialTracks, | ||||||||||||||||||
| initialActiveTrack, | ||||||||||||||||||
| initialFeedItems, | ||||||||||||||||||
| initialFeedTotal, | ||||||||||||||||||
| initialAnchors, | ||||||||||||||||||
| userId = "default", | ||||||||||||||||||
| }: TrackSpotlightSectionProps) { | ||||||||||||||||||
| const [tracks] = useState(initialTracks) | ||||||||||||||||||
| const [activeTrack, setActiveTrack] = useState(initialActiveTrack) | ||||||||||||||||||
| const [feedItems, setFeedItems] = useState(initialFeedItems) | ||||||||||||||||||
| const [feedTotal, setFeedTotal] = useState(initialFeedTotal) | ||||||||||||||||||
| const [anchors, setAnchors] = useState(initialAnchors) | ||||||||||||||||||
| const [isLoading, setIsLoading] = useState(false) | ||||||||||||||||||
|
|
||||||||||||||||||
| const handleSelectTrack = useCallback( | ||||||||||||||||||
| async (trackId: number) => { | ||||||||||||||||||
| const selectedTrack = tracks.find((t) => t.id === trackId) | ||||||||||||||||||
| if (!selectedTrack || selectedTrack.id === activeTrack?.id) return | ||||||||||||||||||
|
|
||||||||||||||||||
| setIsLoading(true) | ||||||||||||||||||
| setActiveTrack(selectedTrack) | ||||||||||||||||||
|
|
||||||||||||||||||
| try { | ||||||||||||||||||
| // Fetch feed and anchors for the new track | ||||||||||||||||||
| const [feedRes, anchorsRes] = await Promise.all([ | ||||||||||||||||||
| fetch(`/api/research/tracks/${trackId}/feed?user_id=${encodeURIComponent(userId)}&limit=6`), | ||||||||||||||||||
| fetch(`/api/research/tracks/${trackId}/anchors/discover?user_id=${encodeURIComponent(userId)}&limit=4`), | ||||||||||||||||||
| ]) | ||||||||||||||||||
|
Comment on lines
+42
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| if (feedRes.ok) { | ||||||||||||||||||
| const feedData = await feedRes.json() | ||||||||||||||||||
| setFeedItems(feedData.items || []) | ||||||||||||||||||
| setFeedTotal(feedData.total || 0) | ||||||||||||||||||
| } else { | ||||||||||||||||||
| setFeedItems([]) | ||||||||||||||||||
| setFeedTotal(0) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (anchorsRes.ok) { | ||||||||||||||||||
| const anchorsData = await anchorsRes.json() | ||||||||||||||||||
| setAnchors(anchorsData.items || []) | ||||||||||||||||||
| } else { | ||||||||||||||||||
| setAnchors([]) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // Optionally activate the track on the backend | ||||||||||||||||||
| await fetch(`/api/research/tracks/${trackId}/activate?user_id=${encodeURIComponent(userId)}`, { | ||||||||||||||||||
| method: "POST", | ||||||||||||||||||
| headers: { "Content-Type": "application/json" }, | ||||||||||||||||||
| body: "{}", | ||||||||||||||||||
| }) | ||||||||||||||||||
|
Comment on lines
+63
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Backend activation failure silently leaves stale If the activation POST fails, Consider either moving the activation call into the 🤖 Prompt for AI Agents |
||||||||||||||||||
| } catch (error) { | ||||||||||||||||||
| console.error("Failed to fetch track data:", error) | ||||||||||||||||||
| setFeedItems([]) | ||||||||||||||||||
| setFeedTotal(0) | ||||||||||||||||||
| setAnchors([]) | ||||||||||||||||||
| } finally { | ||||||||||||||||||
| setIsLoading(false) | ||||||||||||||||||
| } | ||||||||||||||||||
| }, | ||||||||||||||||||
| [tracks, activeTrack?.id, userId] | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| return ( | ||||||||||||||||||
| <TrackSpotlight | ||||||||||||||||||
| tracks={tracks} | ||||||||||||||||||
| activeTrack={activeTrack} | ||||||||||||||||||
| onSelectTrack={handleSelectTrack} | ||||||||||||||||||
| feedItems={feedItems} | ||||||||||||||||||
| feedTotal={feedTotal} | ||||||||||||||||||
| anchors={anchors} | ||||||||||||||||||
| isLoading={isLoading} | ||||||||||||||||||
| /> | ||||||||||||||||||
| ) | ||||||||||||||||||
| } | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
userIdis hardcoded as"default". While this might be acceptable for initial development or a single-user context, it will need to be replaced with a dynamic value from an authentication context or session when multi-user support is implemented. This hardcoded value appears in several places in this PR.