Skip to content

Commit

Permalink
feat(component): ignore current article in cooccurrence article display
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Jan 10, 2024
1 parent da3b011 commit 67c739b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 7 additions & 3 deletions components/CooccurrenceSection/CooccurrenceSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ export const fragments = {
};

type Props = {
/** Ignore the current article */
currentArticleId: string;
cooccurrences: CooccurrenceSectionDataFragment[];
};

function CooccurrenceSection({ cooccurrences }: Props) {
function CooccurrenceSection({ currentArticleId, cooccurrences }: Props) {
// Group cooccurrences by same articles
// then sort by count (more first) and then last createdAt (latest first)
const cooccurrenceEntries = useMemo(() => {
Expand All @@ -56,7 +58,9 @@ function CooccurrenceSection({ cooccurrences }: Props) {
const lastCooccurredInEntry = entry ? entry.lastCooccurred : null;
entries.set(key, {
key,
articles: cooccurrence.articles,
articles: cooccurrence.articles.filter(
({ id }) => id !== currentArticleId
),
count: entry ? entry.count + 1 : 1,
lastCooccurred:
lastCooccurredInEntry === null ||
Expand All @@ -71,7 +75,7 @@ function CooccurrenceSection({ cooccurrences }: Props) {
return +b.lastCooccurred - +a.lastCooccurred;
return 0;
});
}, [cooccurrences]);
}, [cooccurrences, currentArticleId]);

if (!cooccurrences.length) return null;

Expand Down
5 changes: 4 additions & 1 deletion pages/article/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,10 @@ function ArticlePage() {
flexDirection="column"
css={{ gap: 12 }}
>
<CooccurrenceSection cooccurrences={article.cooccurrences} />
<CooccurrenceSection
currentArticleId={query.id}
cooccurrences={article.cooccurrences}
/>
<SideSection>
<SideSectionHeader>{t`Similar messages`}</SideSectionHeader>
{similarArticles.length ? (
Expand Down

0 comments on commit 67c739b

Please sign in to comment.