Skip to content

Commit

Permalink
Merge pull request #1782 from MahtabBukhari/Generic_Nodes_should_rend…
Browse files Browse the repository at this point in the history
…er_color_based_on_schema

Generic nodes should render color based on schema
  • Loading branch information
Rassl authored Jul 12, 2024
2 parents 918fcc8 + 539f085 commit 4957193
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
7 changes: 4 additions & 3 deletions src/components/App/SideBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import ClearIcon from '~/components/Icons/ClearIcon'
import SearchFilterCloseIcon from '~/components/Icons/SearchFilterCloseIcon'
import SearchFilterIcon from '~/components/Icons/SearchFilterIcon'
import SearchIcon from '~/components/Icons/SearchIcon'
import { SchemaExtended } from '~/components/ModalsContainer/BlueprintModal/types'
import { SearchBar } from '~/components/SearchBar'
import { Flex } from '~/components/common/Flex'
import { FetchLoaderText } from '~/components/common/Loader'
Expand All @@ -30,6 +29,7 @@ import { EpisodeSkeleton } from './Relevance/EpisodeSkeleton'
import { SideBarSubView } from './SidebarSubView'
import { Tab } from './Tab'
import { Trending } from './Trending'
import { useSchemaStore } from '~/stores/useSchemaStore'

export const MENU_WIDTH = 390

Expand All @@ -45,6 +45,8 @@ type ContentProp = {
// eslint-disable-next-line react/display-name
const Content = forwardRef<HTMLDivElement, ContentProp>(({ onSubmit, subViewOpen }, ref) => {
const { isFetching: isLoading, setSidebarFilter, setFilters } = useDataStore((s) => s)
const [schemaAll, setSchemaAll] = useSchemaStore((s) => [s.schemas, s.setSchemas])

const { aiSummaryAnswers } = useAiSummaryStore((s) => s)
const setSelectedNode = useUpdateSelectedNode()

Expand All @@ -59,7 +61,6 @@ const Content = forwardRef<HTMLDivElement, ContentProp>(({ onSubmit, subViewOpen
const [isScrolled, setIsScrolled] = useState(false)
const [isFilterOpen, setIsFilterOpen] = useState(false)
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null)
const [schemaAll, setSchemaAll] = useState<SchemaExtended[]>([])
const [selectedTypes, setSelectedTypes] = useState<string[]>([])
const [showAllSchemas, setShowAllSchemas] = useState(false)

Expand Down Expand Up @@ -95,7 +96,7 @@ const Content = forwardRef<HTMLDivElement, ContentProp>(({ onSubmit, subViewOpen
}

fetchSchemaData()
}, [])
}, [setSchemaAll])

const handleFilterIconClick = (event: React.MouseEvent<HTMLElement>) => {
if (isFilterOpen) {
Expand Down
7 changes: 6 additions & 1 deletion src/components/Universe/Graph/Cubes/Text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { NodeExtended } from '~/types'
import { colors } from '~/utils/colors'
import { truncateText } from '~/utils/truncateText'
import { fontProps } from './constants'
import { useSchemaStore } from '~/stores/useSchemaStore'

const COLORS_MAP = [
'#fff',
Expand Down Expand Up @@ -51,6 +52,8 @@ export const TextNode = memo(({ node, hide }: Props) => {
const isRelative = selectedNodeRelativeIds.includes(node?.ref_id || '')
const isSelected = !!selectedNode && selectedNode?.ref_id === node.ref_id
const showSelectionGraph = useGraphStore((s) => s.showSelectionGraph)
const [getPrimaryColorByType] = useSchemaStore((s) => [s.getPrimaryColorByType])

const nodeTypes = useNodeTypes()

useFrame(({ camera }) => {
Expand Down Expand Up @@ -80,7 +83,9 @@ export const TextNode = memo(({ node, hide }: Props) => {
return 1
}, [isSelected, selectedNode])

const color = COLORS_MAP[nodeTypes.indexOf(node.node_type)] || colors.white
const primaryColor = getPrimaryColorByType(node.node_type)

const color = primaryColor ?? (COLORS_MAP[nodeTypes.indexOf(node.node_type)] || colors.white)

return (
<>
Expand Down
25 changes: 14 additions & 11 deletions src/components/common/TypeBadge/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from 'styled-components'
import { colors } from '~/utils/colors'
import { Flex } from '../Flex'
import { useSchemaStore } from '~/stores/useSchemaStore'

type Props = {
type: string
Expand All @@ -14,57 +15,59 @@ type BadgeProps = {

export const TypeBadge = ({ type }: Props) => {
let badgeProps: Omit<BadgeProps, 'label'>

const [getPrimaryColorByType] = useSchemaStore((s) => [s.getPrimaryColorByType])
const nodeType = type.toLowerCase()

const primaryColor = getPrimaryColorByType(type)

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

break

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

break

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

break

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

break

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

break

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

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

break

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

break

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

break

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

break
Expand Down
1 change: 1 addition & 0 deletions src/network/fetchSourcesData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export interface Schema {
search_term?: string
is_deleted?: boolean
children?: string[]
primary_color?: string
attributes?: { [key: string]: string }
}

Expand Down
10 changes: 8 additions & 2 deletions src/stores/useSchemaStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ type SchemasStore = {
links: SchemaLink[]
setSchemas: (schema: SchemaExtended[]) => void
setSchemaLinks: (schema: SchemaLink[]) => void
getPrimaryColorByType: (type: string) => string | undefined
}

const defaultData: Omit<SchemasStore, 'setSchemas' | 'setSchemaLinks'> = {
const defaultData: Omit<SchemasStore, 'setSchemas' | 'setSchemaLinks' | 'getPrimaryColorByType'> = {
schemas: [],
links: [],
}

export const useSchemaStore = create<SchemasStore>((set) => ({
export const useSchemaStore = create<SchemasStore>((set, get) => ({
...defaultData,
setSchemas: (schemas: SchemaExtended[]) => {
set({ schemas: schemas.map((i) => ({ ...i, ref_id: i?.attributes?.ref_id || '' })) })
},
setSchemaLinks: (links: SchemaLink[]) => {
set({ links })
},
getPrimaryColorByType: (type: string) => {
const schema = get().schemas.find((schem) => schem.type === type)

return schema ? schema.primary_color : undefined
},
}))

0 comments on commit 4957193

Please sign in to comment.