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

Render shape and label color based on schema primary_color #2344

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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { fontProps } from '~/components/Universe/Graph/Cubes/Text/constants'
import { truncateText } from '~/utils/truncateText'
import { NODE_RADIUS } from '../../constants'
import { useSchemaStore } from '~/stores/useSchemaStore'

export const NODE_TYPE_COLORS = ['#ff13c9', '#5af0ff', '#3233ff', '#c2f0c2', '#ff6666', '#99ccff', '#ffb3b3']

Expand Down Expand Up @@ -40,9 +41,10 @@

export const Node = memo(({ node, setSelectedNode, onSimulationUpdate, isSelected }: Props) => {
const meshRef = useRef<Mesh | null>(null)
const [normalizedSchemasByType] = useSchemaStore((s) => [s.normalizedSchemasByType])
const [showTooltip, setShowTooltip] = useState(false)

console.log(isSelected)

Check warning on line 47 in src/components/ModalsContainer/BlueprintModal/Body/Graph/Nodes/Node/index.tsx

View workflow job for this annotation

GitHub Actions / eslint-run

Unexpected console statement

const { size, camera } = useThree()

Expand Down Expand Up @@ -89,7 +91,9 @@
}
})

const color = NODE_TYPE_COLORS[node?.children?.length] || 'red'
const primaryColor = normalizedSchemasByType[node.type]?.primary_color

const color = primaryColor ?? (NODE_TYPE_COLORS[node?.children?.length] || 'red')

const handleClick = (e: { stopPropagation: () => void }) => {
e.stopPropagation()
Expand Down
29 changes: 16 additions & 13 deletions src/components/common/TypeBadge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,61 @@ type BadgeProps = {

export const TypeBadge = ({ type }: Props) => {
let badgeProps: Omit<BadgeProps, 'label'>
const [getPrimaryColorByType] = useSchemaStore((s) => [s.getPrimaryColorByType])
const [normalizedSchemasByType] = useSchemaStore((s) => [s.normalizedSchemasByType])
const nodeType = type.toLowerCase()

const primaryColor = getPrimaryColorByType(type)
const primaryColor = normalizedSchemasByType[type]?.primary_color
const primaryIcon = normalizedSchemasByType[type]?.icon

const icon = primaryIcon ? `svg-icons/${primaryIcon}.svg` : null

switch (nodeType) {
case 'video':
case 'twitter_space':
case 'podcast':
case 'clip':
badgeProps = {
iconStart: 'video_badge.svg',
iconStart: icon ?? 'video_badge.svg',
color: primaryColor ?? colors.CLIP,
}

break

case 'show':
badgeProps = {
iconStart: 'show_badge.svg',
iconStart: icon ?? 'show_badge.svg',
color: primaryColor ?? colors.SHOW,
}

break

case 'tweet':
badgeProps = {
iconStart: 'twitter_badge.svg',
iconStart: icon ?? 'twitter_badge.svg',
color: primaryColor ?? colors.TWEET,
}

break

case 'episode':
badgeProps = {
iconStart: 'audio_badge.svg',
iconStart: icon ?? 'audio_badge.svg',
color: primaryColor ?? colors.EPISODE,
}

break

case 'document':
badgeProps = {
iconStart: 'notes_badge.svg',
iconStart: icon ?? 'notes_badge.svg',
color: primaryColor ?? colors.TEXT,
}

break

case 'organization':
case primaryIcon ?? 'organization':
badgeProps = {
iconStart: 'organization_badge.svg',
iconStart: icon ?? 'organization_badge.svg',
color: primaryColor ?? colors.ORGANIZATION,
}

Expand All @@ -76,31 +79,31 @@ export const TypeBadge = ({ type }: Props) => {
case 'guest':
case 'host':
badgeProps = {
iconStart: 'person_badge.svg',
iconStart: icon ?? 'person_badge.svg',
color: primaryColor ?? colors.PERSON,
}

break

case 'event':
badgeProps = {
iconStart: 'event_badge.svg',
iconStart: icon ?? 'event_badge.svg',
color: primaryColor ?? colors.EVENT,
}

break

case 'topic':
badgeProps = {
iconStart: 'topic_badge.svg',
iconStart: icon ?? 'topic_badge.svg',
color: primaryColor ?? colors.TOPIC,
}

break

default:
badgeProps = {
iconStart: 'thing_badge.svg',
iconStart: icon ?? 'thing_badge.svg',
color: primaryColor ?? colors.THING,
}

Expand Down
Loading