Skip to content

Commit

Permalink
fix recreating data
Browse files Browse the repository at this point in the history
  • Loading branch information
happylolonly committed Oct 31, 2023
1 parent 5c49b0b commit 27b7528
Showing 1 changed file with 34 additions and 31 deletions.
65 changes: 34 additions & 31 deletions src/features/cyberlinks/CyberlinksGraph/useCyberlinks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import gql from 'graphql-tag';
import { useMemo } from 'react';
import { useQuery } from 'react-apollo';

const limit = 740;
Expand Down Expand Up @@ -27,42 +28,44 @@ function useCyberlinks(address?: string) {

const cyberlinks = query.data?.cyberlinks;

return {
data: (() => {
if (!cyberlinks) {
return {
nodes: [],
links: [],
};
}

// TODO: a lot of loops, try to refactor
const from = cyberlinks.map((a) => a.particle_from);
const to = cyberlinks.map((a) => a.particle_to);
const data = useMemo(() => {
if (!cyberlinks) {
return {
nodes: [],
links: [],
};
}

const set = new Set(from.concat(to));
const object = [];
set.forEach((value) => {
object.push({ id: value });
});
// TODO: a lot of loops, try to refactor
const from = cyberlinks.map((a) => a.particle_from);
const to = cyberlinks.map((a) => a.particle_to);

const links = [];
const set = new Set(from.concat(to));
const object = [];
set.forEach((value) => {
object.push({ id: value });
});

for (let i = 0; i < cyberlinks.length; i++) {
links[i] = {
source: cyberlinks[i].particle_from,
target: cyberlinks[i].particle_to,
name: cyberlinks[i].transaction_hash,
subject: cyberlinks[i].subject,
// curvative: getRandomInt(20, 500) / 1000,
};
}
const links = [];

return {
nodes: object,
links: links,
for (let i = 0; i < cyberlinks.length; i++) {
links[i] = {
source: cyberlinks[i].particle_from,
target: cyberlinks[i].particle_to,
name: cyberlinks[i].transaction_hash,
subject: cyberlinks[i].subject,
// curvative: getRandomInt(20, 500) / 1000,
};
})(),
}

return {
nodes: object,
links: links,
};
}, [cyberlinks]);

return {
data,
loading: query.loading,
};
}
Expand Down

0 comments on commit 27b7528

Please sign in to comment.