Skip to content

Commit

Permalink
Merge branch 'master' into feature/523
Browse files Browse the repository at this point in the history
  • Loading branch information
Расул authored and Расул committed Nov 20, 2023
2 parents 15af372 + 99fe2d0 commit 07825f8
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 20 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Second Brain</title>
<script type="module" crossorigin src="/assets/index-2946ad0e.js"></script>
<script type="module" crossorigin src="/assets/index-de1fe141.js"></script>
<link rel="stylesheet" href="/assets/index-9a4cd8a9.css">
</head>
<body style="background: #000">
Expand Down
1 change: 0 additions & 1 deletion src/components/App/SideBar/Relevance/Episode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export const Episode = ({
{!isSelectedView && (
<Flex align="center" pr={16}>
<Avatar size={64} src={imageUrl} type={type || ''} />
<Avatar size={64} src={imageUrl} type={type || ''} />
</Flex>
)}

Expand Down
33 changes: 33 additions & 0 deletions src/network/fetchGraphData/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ describe('formatFetchNodes', () => {
node_type: 'test',
}

const tweetNode = {
date: 1700158742,
latitude: null,
longitude: null,
name: 'Yan | swan.com',
node_type: 'tweet',
posted_by: {
name: 'Marty Bent',
ref_id: '655bdcb1-21c3-411c-aa24-fe7e4c7a248c',
twitter_handle: 'MartyBent',
},
profile_picture: 'https://pbs.twimg.com/profile_images/1599281471679766530/RhszStuB_normal.jpg',
ref_id: 'a1317497-7ebe-401b-8cfd-fe709bf04e46',
text: '@adam3us @JSeyff @SGJohnsson Where’s the Vitalik presale video where he talks about finding a friendly jurisdiction?',
topics: ['Vitalik', 'Bitcoin', 'presale', 'friendly jurisdiction'],
tweet_id: '1725216924051587516',
twitter_handle: 'skwp',
verified: false,
weight: 2,
}

const dataSeriesNode = {
x: 1,
y: 1,
Expand Down Expand Up @@ -116,4 +137,16 @@ describe('formatFetchNodes', () => {
expect(formattedResponse.nodes[2].type).toBe('data_series')
expect(formattedResponse.nodes[2].index).toBe(2)
})

it('should create topic nodes for each topic from tweet, and guest node for posted_by', () => {
const emptyInput = {
data_series: { title: 'test' },
exact: [tweetNode],
related: [],
}

const result = formatFetchNodes(emptyInput, '1', 'split')

expect(result.nodes.length).toBe(tweetNode.topics.length + 2)
})
})
61 changes: 45 additions & 16 deletions src/network/fetchGraphData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,28 @@ function generateGuestNodesFromMap(
})
}

const generateGuestsMap = (
currentGuest: Guests,
id: string,
guestMap: Record<string, guestMapChild> = {},
): Record<string, guestMapChild> => {
let updatedGuestMap = { ...guestMap }

if (currentGuest.name && currentGuest.ref_id && id) {
updatedGuestMap = {
...updatedGuestMap,
[currentGuest.ref_id]: {
children: [...(updatedGuestMap[currentGuest.ref_id]?.children || []), id],
imageUrl: currentGuest.profile_picture || '',
name: currentGuest.name,
twitterHandle: currentGuest.twitter_handle,
},
}
}

return updatedGuestMap // Return the new variable
}

export const getGraphData = async (searchterm: string, graphStyle: 'split' | 'force' | 'sphere' | 'earth') => {
try {
const dataInit = await fetchNodes(searchterm)
Expand Down Expand Up @@ -410,7 +432,7 @@ export const formatFetchNodes = (
let nodes: NodeExtended[] = []

const topicMap: TopicMap = {}
const guestMap: Record<string, guestMapChild> = {}
let guestMap: Record<string, guestMapChild> = {}

const dataSeries = Array.isArray(dataInit.data_series) ? dataInit.data_series : []

Expand All @@ -436,12 +458,22 @@ export const formatFetchNodes = (
nodes.push({
...node,
scale: getNodeScale(node),
id: node.tweet_id || `${node.unique_id}_${index}`,
ref_id: node.tweet_id || `${node.unique_id}_${index}`,
id: node.ref_id || `${node.unique_id}_${index}`,
ref_id: node.ref_id || `${node.unique_id}_${index}`,
image_url: imageUrlsMapper[node.node_type],
type: node.type || node.node_type,
})

if (node.node_type === 'tweet') {
if (node.posted_by && node.ref_id) {
const currentGuest = { ...node.posted_by, profile_picture: node.profile_picture } as Guests

const updatedGuestMap = generateGuestsMap(currentGuest, node.ref_id, guestMap)

guestMap = { ...guestMap, ...updatedGuestMap }
}
}

return
}

Expand All @@ -460,7 +492,7 @@ export const formatFetchNodes = (
nodes.push({
...node,
scale: getNodeScale(node),
id: node.ref_id || node.tweet_id || node.id,
id: node.ref_id || node.id,
image_url: smallImageUrl,
type: node.type || node.node_type,
})
Expand All @@ -472,14 +504,9 @@ export const formatFetchNodes = (
guestList.forEach((guest) => {
const currentGuest = guest as Guests

if (currentGuest.name && currentGuest.ref_id && node.ref_id) {
guestMap[currentGuest.ref_id] = {
children: [...(guestMap[currentGuest.ref_id]?.children || []), node.ref_id],
imageUrl: currentGuest.profile_picture || '',
name: currentGuest.name,
twitterHandle: currentGuest.twitter_handle,
}
}
const updatedGuestMap = generateGuestsMap(currentGuest, node.ref_id!, guestMap)

guestMap = { ...guestMap, ...updatedGuestMap }
})
}
})
Expand All @@ -500,13 +527,15 @@ export const formatFetchNodes = (
return
}

if (showTitle) {
if (topicMap[topic] && !topicMap[topic].children.includes(refId || showTitle)) {
topicMap[topic].children.push(refId || showTitle)
const value = refId || showTitle

if (value) {
if (topicMap[topic] && !topicMap[topic].children.includes(value)) {
topicMap[topic].children.push(value)
} else {
topicMap[topic] = {
position: new Vector3(0, 0, 0),
children: [refId || showTitle],
children: [value],
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type Node = {
type?: string
weight?: number
tweet_id?: string
posted_by?: PostedBy
twitter_handle?: string
profile_picture?: string
verified?: boolean
Expand Down Expand Up @@ -179,3 +180,9 @@ export type TopicFilter = {
export type SubmitErrRes = {
error?: { message?: string }
}

type PostedBy = {
name: string
ref_id: string
twitter_handle: string
}

0 comments on commit 07825f8

Please sign in to comment.