fix(backlinks): list not refreshing & not reacting to all changes

This commit is contained in:
Elian Doran 2025-12-02 13:30:37 +02:00
parent 5ae67fda7f
commit 10910ac2ed
No known key found for this signature in database

View File

@ -19,6 +19,7 @@ import NoteLink from "./react/NoteLink";
import RawHtml from "./react/RawHtml"; import RawHtml from "./react/RawHtml";
import { ViewTypeOptions } from "./collections/interface"; import { ViewTypeOptions } from "./collections/interface";
import attributes from "../services/attributes"; import attributes from "../services/attributes";
import LoadResults from "../services/load_results";
export interface FloatingButtonContext { export interface FloatingButtonContext {
parentComponent: Component; parentComponent: Component;
@ -321,13 +322,7 @@ function Backlinks({ note, isDefaultViewMode }: FloatingButtonContext) {
useEffect(() => refresh(), [ note ]); useEffect(() => refresh(), [ note ]);
useTriliumEvent("entitiesReloaded", ({ loadResults }) => { useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
loadResults.getAttributeRows().some(attr => if (needsRefresh(note, loadResults)) refresh();
attr.type === "relation" &&
attr.name === "internalLink" &&
attributes.isAffecting(attr, note))
{
refresh();
}
}); });
// Determine the max height of the container. // Determine the max height of the container.
@ -353,18 +348,18 @@ function Backlinks({ note, isDefaultViewMode }: FloatingButtonContext) {
{popupOpen && ( {popupOpen && (
<div ref={backlinksContainerRef} className="backlinks-items dropdown-menu" style={{ display: "block" }}> <div ref={backlinksContainerRef} className="backlinks-items dropdown-menu" style={{ display: "block" }}>
<BacklinksList noteId={note.noteId} /> <BacklinksList note={note} />
</div> </div>
)} )}
</div> </div>
); );
} }
function BacklinksList({ noteId }: { noteId: string }) { function BacklinksList({ note }: { note: FNote }) {
const [ backlinks, setBacklinks ] = useState<BacklinksResponse>([]); const [ backlinks, setBacklinks ] = useState<BacklinksResponse>([]);
useEffect(() => { function refresh() {
server.get<BacklinksResponse>(`note-map/${noteId}/backlinks`).then(async (backlinks) => { server.get<BacklinksResponse>(`note-map/${note.noteId}/backlinks`).then(async (backlinks) => {
// prefetch all // prefetch all
const noteIds = backlinks const noteIds = backlinks
.filter(bl => "noteId" in bl) .filter(bl => "noteId" in bl)
@ -372,7 +367,12 @@ function BacklinksList({ noteId }: { noteId: string }) {
await froca.getNotes(noteIds); await froca.getNotes(noteIds);
setBacklinks(backlinks); setBacklinks(backlinks);
}); });
}, [ noteId ]); }
useEffect(() => refresh(), [ note ]);
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
if (needsRefresh(note, loadResults)) refresh();
});
return backlinks.map(backlink => ( return backlinks.map(backlink => (
<div> <div>
@ -392,3 +392,9 @@ function BacklinksList({ noteId }: { noteId: string }) {
</div> </div>
)); ));
} }
function needsRefresh(note: FNote, loadResults: LoadResults) {
return loadResults.getAttributeRows().some(attr =>
attr.type === "relation" &&
attributes.isAffecting(attr, note));
}