Skip to content

Commit acd44eb

Browse files
committed
feat: top tags limit and sort on opportunity preview
1 parent f561903 commit acd44eb

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

src/schema/opportunity.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
getBufferFromStream,
2121
getSecondsTimestamp,
2222
toGQLEnum,
23-
uniqueifyArray,
2423
uniqueifyObjectArray,
2524
updateFlagsStatement,
2625
} from '../common';
@@ -1751,9 +1750,27 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
17511750
true,
17521751
);
17531752

1754-
const tags = uniqueifyArray(
1755-
connection.edges.flatMap(({ node }) => node.topTags || []),
1753+
const flatTags = connection.edges.flatMap(({ node }) => {
1754+
return node.topTags || [];
1755+
});
1756+
const uniqueTagsMap = flatTags.reduce(
1757+
(acc, item) => {
1758+
// map tags to how much they appear across all users
1759+
if (typeof acc[item] === 'undefined') {
1760+
acc[item] = 1;
1761+
} else {
1762+
acc[item] += 1;
1763+
}
1764+
1765+
return acc;
1766+
},
1767+
{} as Record<string, number>,
17561768
);
1769+
// final map and sort to get X tags that appear the most
1770+
const tags = Object.entries(uniqueTagsMap)
1771+
.sort((a, b) => b[1] - a[1])
1772+
.slice(0, 16)
1773+
.map(([tag]) => tag);
17571774

17581775
const companies = getShowcaseCompanies();
17591776

0 commit comments

Comments
 (0)