feat: added a twist
This commit is contained in:
21
frontend/src/hooks/useBacklinks.ts
Normal file
21
frontend/src/hooks/useBacklinks.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { useMemo } from "react";
|
||||
import { useGraph } from "@/hooks/useGraph";
|
||||
|
||||
export interface BacklinkPage {
|
||||
name: string;
|
||||
title: string | null;
|
||||
}
|
||||
|
||||
export function useBacklinks(currentSlug: string | undefined): BacklinkPage[] {
|
||||
const { data } = useGraph();
|
||||
return useMemo(() => {
|
||||
if (!data || !currentSlug) return [];
|
||||
const nodeMap = new Map(data.nodes.map((n) => [n.id, n]));
|
||||
return data.edges
|
||||
.filter((e) => e.target === currentSlug)
|
||||
.map((e) => ({
|
||||
name: e.source,
|
||||
title: nodeMap.get(e.source)?.title ?? null,
|
||||
}));
|
||||
}, [data, currentSlug]);
|
||||
}
|
||||
Reference in New Issue
Block a user