Obsidian-Daily-Notes-Editor icon indicating copy to clipboard operation
Obsidian-Daily-Notes-Editor copied to clipboard

[Bug]: Sort order of files?

Open derekvan opened this issue 2 years ago • 20 comments

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?

  • [X] New Editor
  • [ ] Legacy Editor

Checklist

  • [X] I updated to the latest version of the plugin.

derekvan avatar Nov 14 '22 22:11 derekvan

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 ?

Quorafind avatar Nov 15 '22 01:11 Quorafind

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

derekvan avatar Nov 15 '22 12:11 derekvan

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

Quorafind avatar Nov 15 '22 12:11 Quorafind

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: @.***>

derekvan avatar Nov 15 '22 14:11 derekvan

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 avatar Dec 03 '22 00:12 danrthompson

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

danrthompson avatar Dec 03 '22 00:12 danrthompson

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

mrjano avatar Dec 17 '22 16:12 mrjano

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

jhawk1988 avatar Dec 19 '22 11:12 jhawk1988

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.

jloh avatar Dec 19 '22 13:12 jloh

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.

  • I'm using Periodic Notes v0.0.17
  • The date format is YYYY-MM-DD
  • I have over 2,000 daily notes
  • Obsidian v1.1.9

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

  • 02 Areas
    • Journal
      • 1996
      • 2023
        • 01
          • 2023-01-10.md

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.

joshuarudd avatar Jan 10 '23 19:01 joshuarudd

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 😅

Drazhar avatar Jan 31 '23 15:01 Drazhar

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?

matthiashaldimann avatar Apr 08 '23 10:04 matthiashaldimann

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

Coffeeling avatar May 25 '23 12:05 Coffeeling

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();
    }

happytk avatar Jun 19 '23 02:06 happytk

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

MohamedOsman1998 avatar Jun 29 '23 19:06 MohamedOsman1998

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.

razinm avatar Nov 12 '23 05:11 razinm

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.

ruanimal avatar Feb 26 '24 01:02 ruanimal

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

austinm911 avatar Mar 21 '24 03:03 austinm911

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. :-)

davmre avatar Apr 06 '24 22:04 davmre

@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 😅

razinm avatar Apr 07 '24 12:04 razinm

Please try again and see if this issue remains.

Quorafind avatar May 24 '24 23:05 Quorafind

Please try again and see if this issue remains.

The order is fine now with the latest version!

flyisland avatar May 25 '24 03:05 flyisland