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

feat: add normalized nodes, reduce rerenders, add particles #2525

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions src/components/App/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Leva } from 'leva'
import { lazy, Suspense, useCallback, useEffect, useRef } from 'react'
import { FormProvider, useForm } from 'react-hook-form'
import { useSearchParams } from 'react-router-dom'
Expand All @@ -8,7 +7,6 @@
import { Flex } from '~/components/common/Flex'
import { GlobalStyle } from '~/components/GlobalStyle'
import { Overlay } from '~/components/Universe/Overlay' // Import Overlay directly
import { isDevelopment } from '~/constants'
import { useSocket } from '~/hooks/useSockets'
import { useAiSummaryStore } from '~/stores/useAiSummaryStore'
import { useAppStore } from '~/stores/useAppStore'
Expand Down Expand Up @@ -278,7 +276,7 @@
])

useEffect(() => {
if (!runningProjectId || true) {

Check warning on line 279 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / eslint-run

Unexpected constant condition

Check warning on line 279 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected constant condition

Check warning on line 279 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/checkEnv.cy.ts)

Unexpected constant condition

Check warning on line 279 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected constant condition

Check warning on line 279 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected constant condition

Check warning on line 279 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected constant condition

Check warning on line 279 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected constant condition

Check warning on line 279 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected constant condition

Check warning on line 279 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected constant condition

Check warning on line 279 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected constant condition
return
}

Expand Down Expand Up @@ -341,8 +339,6 @@

<DeviceCompatibilityNotice />

<Leva hidden={!isDevelopment || true} isRoot />

<Suspense fallback={<div>Loading...</div>}>
{!splashDataLoading ? (
<Wrapper direction="row">
Expand Down
33 changes: 32 additions & 1 deletion src/components/Universe/Graph/Connections/LineComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { Billboard, Line, Text } from '@react-three/drei'
import { useFrame } from '@react-three/fiber'
import gsap from 'gsap'
import { memo, useEffect, useRef } from 'react'
import { Vector3 } from 'three'
import { Line2 } from 'three-stdlib'
import { useGraphStore } from '~/stores/useGraphStore'
import { LinkPosition } from '..'
import { LINE_WIDTH } from '../../constants'

type LineComponentProps = {
isSelected: boolean
position: LinkPosition
label: string
target: string
source: string
}

// eslint-disable-next-line no-underscore-dangle
const _LineComponent = ({ isSelected, position, label }: LineComponentProps) => {
const _LineComponent = ({ isSelected, position, label, target, source }: LineComponentProps) => {
const lineRef = useRef<Line2 | null>(null)

useEffect(() => {
Expand All @@ -31,6 +35,33 @@ const _LineComponent = ({ isSelected, position, label }: LineComponentProps) =>
}
}, [isSelected, lineRef])

useFrame(() => {
const { selectedNode, hoveredNode } = useGraphStore.getState()

if (lineRef.current) {
const line = lineRef.current
const activeNode = selectedNode || hoveredNode

if (activeNode?.ref_id === source || activeNode?.ref_id === target) {
line.visible = true

// Increase line width
gsap.to(line.material, {
linewidth: 6, // Target line width
duration: 0.5, // Smooth increase
ease: 'power1.out',
})
} else {
// Decrease line width back to default
gsap.to(line.material, {
linewidth: 1, // Default line width
duration: 0.5, // Smooth decrease
ease: 'power1.out',
})
}
}
})

return (
<group>
<Line
Expand Down
11 changes: 10 additions & 1 deletion src/components/Universe/Graph/Connections/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ export const Connections = memo(({ linksPosition }: Props) => {
tz: 0,
}

return <LineComponent key={l.ref_id} isSelected={isSelected} label={l.edge_type} position={position} />
return (
<LineComponent
key={l.ref_id}
isSelected={isSelected}
label={l.edge_type}
position={position}
source={l.source}
target={l.target}
/>
)
})}
</group>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const SelectionDataNodes = memo(() => {
<group ref={groupRef} name="simulation-2d-group">
{selectionGraphData?.nodes.map((node) => (
<mesh key={node.ref_id}>
<TextNode key={node.ref_id || node.id} hide ignoreDistance node={node} />
<TextNode key={node.ref_id || node.id} color="white" hide ignoreDistance node={node} />
</mesh>
))}
</group>
Expand Down
Loading
Loading