Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicity in the list view (notes are sometimes showed twice) #36

Open
jankoweb opened this issue Jun 1, 2024 · 2 comments
Open

Duplicity in the list view (notes are sometimes showed twice) #36

jankoweb opened this issue Jun 1, 2024 · 2 comments

Comments

@jankoweb
Copy link

jankoweb commented Jun 1, 2024

Why are some notes duplicated in a list view? How can I deal with it?
image

My chronology setting:
image

@jankoweb jankoweb changed the title Duplicity in list view Duplicity in the list view (notes are sometimes showed twice) Jun 1, 2024
@mbw8421
Copy link

mbw8421 commented Jul 14, 2024

It looks like the function that gets the notes is built with the default calendar view in mind so when passed to the NotesList component there can be duplicates due to different timestamps. As the notes look to already be sorted by most recent you could filter the NotesList items array within the component to ensure only the first occurrence of each unique file is rendered. Something like the below.

import { PaneType, TFile } from "obsidian";
import * as React from "react";
import { CalendarItem } from "../CalendarType";
import { NoteAttributes } from "../TimeIndex";
import { NoteView } from "./NoteView";

export const NotesList = ({ calItem, items, onOpen }: {
    calItem: CalendarItem,
    items: NoteAttributes[],
    onOpen: (note: TFile, paneType: PaneType | boolean) => void
}) => {

    // Filter to get unique items based on note.path
    const uniqueItems = items.filter((item, index, self) =>
        index === self.findIndex(t => t.note.path === item.note.path)
    );

    return (
        <div className="chronology-noteslist-container">
            <div className="chronology-noteslist-wrapper">
                {uniqueItems.map(item =>
                    <NoteView key={item.note.path + item.attribute} item={item} onOpen={onOpen} extraInfo={false} />
                )}
            </div>
        </div>
    );
}

export default NotesList;

P.S. I am not a JS dev so this method might be horribly inefficient, looks like O(n^2) due to the nested loop.

@marconoris
Copy link

I have the same issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants