Quorafind / Obsidian-Daily-Notes-Editor

A plugin for you to edit a bunch of daily notes in one page(inline), which works similar to Roam Research's default daily note view.
165 stars 8 forks source link

[Bug]: Sort order of files? #17

Closed derekvan closed 1 month ago

derekvan commented 1 year ago

Bug Description

Can you make the files sort in chronological order? Mine seem to be sorted in a random order.

Relevant Screenshot

No response

To Reproduce

No response

Obsidian Version

1.0.3

Which editor are you using?

Checklist

Quorafind commented 1 year ago

Could you tell me whether you use default daily note plugin or periodic notes plugin? And could you show me your daily note title format, like YYYY-MM-DD ?

derekvan commented 1 year ago

I'm using the core Daily notes plugin, as well as the Calendar plugin (but not periodic notes). And the title format is YYYY-MM-DD

Quorafind commented 1 year ago

thanks for information, I will look into this. Btw, how many daily notes do you have?

derekvan commented 1 year ago

Maybe around 450

On Tue, Nov 15, 2022 at 7:38 AM Boninall @.***> wrote:

thanks for information, I will look into this. Btw, how many daily notes do you have?

— Reply to this email directly, view it on GitHub https://github.com/Quorafind/Obsidian-Daily-Notes-Editor/issues/17#issuecomment-1315253040, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGZLZK4BVCPH3DPKUE3OJDWIN72VANCNFSM6AAAAAASAJHYPQ . You are receiving this because you authored the thread.Message ID: @.***>

danrthompson commented 1 year ago

Same here - it's not rendering in any particular order for me. They are rendering, just in a random order.

I'm using periodic notes and my date format is also "YYYY-MM-DD". Here are the first five notes in order in case that helps: 2022-09-20 2022-11-29 2022-11-10 2022-12-01 2022-11-26

I have 76 daily notes, FWIW

danrthompson commented 1 year ago

BTW, thank you so much for making this!!!!!!! I love Obsidian but this was one of the features I missed from Roam

mrjano commented 1 year ago

Hi, same issue here in Obsidian 1.1.6. I'm also using YYYY-MM-DD as the format for my daily notes, thanks in advance

jhawk1988 commented 1 year ago

i'm seeing the same issue but using YYYYMMDD as the format for my daily notes.

jloh commented 1 year ago

I'm seeing the same issue currently. Daily notes are named YYYY-MM-DD but title is # {{DATE:dddd Do MMMM YYYY}} (ie whats the H1 in the file) if that matters.

I've noticed mine become out of order if I delete one from two days ago then recreate it. For some reason it ends up above ones from a later date.

I'm on Obsidian 1.1.6 if that helps. I use the Periodic Notes plugin, not the default Daily Notes plugin.

joshuarudd commented 1 year ago

I'm having the same issue where the sort order seems to be random. Sometimes it changes to show different notes at the top. I notice this especially on the Obsidian mobile app for iOS and iPadOS, but it's also happening on the desktop app.

One other thing to note is that my daily notes are broken down into subfolders by year and month:

One reason these go so far back is because I've ported journal entries from other systems into Obsidian, so some of the older entries have newer file creation dates. I'm not sure whether this make a difference, but figured I'd mention it.

Drazhar commented 1 year ago

I have the same issue. Really nice plugin, but with a random order, it's pretty useless unfortunately 😔

I also tried to look at the code, but couldn't find the part where the notes are read from the folders. Thought it shouldn't be too hard to fix, that the notes are ordered by filename. Unfortunately I was wrong 😅

matthiashaldimann commented 1 year ago

This bug remains unfixed. It's a real pity, as it effectively renders this otherwise very useful plugin unusable. Are there any plans to fix it?

Coffeeling commented 1 year ago

Can confirm, suffer from the bug as well. Up to date Obsidian, YYYY-MM-DD Daily Note format.

happytk commented 1 year ago

https://github.com/Quorafind/Obsidian-Daily-Notes-Editor/blob/7bfd75da82b365f2be6f939ea6eaf01f0b6e431f/src/component/DailyNoteEditorView.svelte#L23-L27

Probably this is a bug from obsidian api. I cannot sure. But could be fixed by adding sort function like this

    $: if(hasMore && !hasFetch) {
        cacheDailyNotes = getAllDailyNotes();
        for (const string in cacheDailyNotes) {
            allDailyNotes.push(<TFile>cacheDailyNotes[string]);
        }
        // @ts-ignore
        allDailyNotes.sort((a, b) => {
            if (a.name == b.name) return 0;
            else if (a.name > b.name) return -1;
            else if (a.name < b.name) return 1;
        })
        hasFetch = true;
        checkDailyNote();
    }
MohamedOsman1998 commented 1 year ago

@happytk yeah thanks it should be something as simple as that. does this exact code work?

razinm commented 7 months ago

https://github.com/Quorafind/Obsidian-Daily-Notes-Editor/blob/7bfd75da82b365f2be6f939ea6eaf01f0b6e431f/src/component/DailyNoteEditorView.svelte#L23-L27

Probably this is a bug from obsidian api. I cannot sure. But could be fixed by adding sort function like this

    $: if(hasMore && !hasFetch) {
        cacheDailyNotes = getAllDailyNotes();
        for (const string in cacheDailyNotes) {
            allDailyNotes.push(<TFile>cacheDailyNotes[string]);
        }
        // @ts-ignore
        allDailyNotes.sort((a, b) => {
            if (a.name == b.name) return 0;
            else if (a.name > b.name) return -1;
            else if (a.name < b.name) return 1;
        })
        hasFetch = true;
        checkDailyNote();
    }

Unfortunately implementing this didn't do anything for me. The plugin is exactly what I wanted but like others have mentioned it becomes useless if it isn't able to sort the daily notes properly.

This is the only plugin that has come remotely close to the functionality I have been looking for.

ruanimal commented 4 months ago

same problem.

it worked fine at first, when I have 10+ daily notes. but after I migrate logseq daily notes to obsidian, notes number increase to 250, the notes order was wrong. then I restart obsidian, the order seems to be right again.

austinm911 commented 3 months ago

Using periodic notes with 88 daily note files, this plugin is showing my notes out of order.

davmre commented 2 months ago

I tried @happytk's solution and it does in fact work for me. @razinm is it possible something went wrong so you might not have actually been testing the modified code?

It looks like cacheDailyNotes returned from the API is a Record<string,TFile>. I am not a TypeScript or JavaScript expert but I'm guessing this is analogous to record/map types in other languages where there's no guarantee on ordering of elements, i.e., the order of iteration might depend on system implementation details? That would imply that we need an explicit sort if we do want to guarantee an ordered array of notes (allDailyNotes). It looks like the string keys are date representations of the form day-2024-04-06T00:00:00-07:00 so it's sufficient to just sort them in descending order.

I think it's slightly cleaner to do this as the list is constructed (vs after the fact as in @happytk 's solution):

$: if (hasMore && !hasFetch) {
        cacheDailyNotes = getAllDailyNotes();
        // Build notes list by date in descending order.
        for (const string of Object.keys(cacheDailyNotes).sort().reverse()) {
            allDailyNotes.push(<TFile>cacheDailyNotes[string]);
        }
        hasFetch = true;
        checkDailyNote();
}

but the result should be equivalent in either case. I've created a PR implementing this solution. Comments welcome from anyone who actually knows anything about JavaScript and/or Obsidian plugin development. :-)

razinm commented 2 months ago

@davmre It is very possible that something might have gone wrong. I am not a dev at all and i had to figure out on my own how to compile it after adding happytks suggestions. 🤣

Well, struggling similarly now, i get a build error, i had forgrotten what i had done to fix it 😅

Quorafind commented 1 month ago

Please try again and see if this issue remains.

flyisland commented 1 month ago

Please try again and see if this issue remains.

The order is fine now with the latest version!