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

Patch: Sort tags alphabetically #105

Open
sokolgeo opened this issue Feb 18, 2025 · 8 comments
Open

Patch: Sort tags alphabetically #105

sokolgeo opened this issue Feb 18, 2025 · 8 comments

Comments

@sokolgeo
Copy link

sokolgeo commented Feb 18, 2025

Hi there! My instance of MyTinyTodo uses a lot of tags. By default, the tags are displayed in the tag cloud in random order, which is a real pain to find the tag you want.

GitHub Copilot kindly suggested to insert into src/content/mytinytodo.js , function loadTags the following one-liner to sort the tags alphabetically:

tagsList.sort((a, b) => a.tag.localeCompare(b.tag));

Here is the resulting code of the function loadTags with the one-liner inserted:

function loadTags(listId, callback)
{
    if (flag.showTagsFromAllLists) listId = -1;
    _mtt.db.request('tagCloud', {list:listId}, function(json){
        if (!parseInt(json.total)) tagsList = [];
        else tagsList = json.items;

	// Sort tagsList alphabetically
        tagsList.sort((a, b) => a.tag.localeCompare(b.tag));
	// end of insert
	
        let cloud = '';
        tagsList.forEach( item => {
            // item.tag is escaped with htmlspecialchars()
            cloud += ' <span class="tag" data-tag="' + item.tag + '" data-tag-id="' + item.id + '">' + item.tag + '</span>';
        });
        if (cloud == '') {
            cloud = _mtt.lang.get('noTags');
        }
        $('#tagcloudcontent').html(cloud)
        flag.tagsChanged = false;
        callback();
    });
};

This works great for me, and I think most MyTinyTodos will benefit from an ordered list of tags. What do you think?

@maxpozdeev
Copy link
Owner

maxpozdeev commented Feb 18, 2025

Hi!
I think the code is correct.

By default, the tags are displayed in the tag cloud in random order,

Can you ask copilot how tags are ordered in cloud?

@sokolgeo
Copy link
Author

sokolgeo commented Feb 18, 2025

Before the fix, tags were apparently displayed in "most used first" order in the tag cloud.

It was very difficult to use many tags - finding the right tag in a large list without an alphabetical index was a real pain!

The one-line fix suggested by Copilot works perfectly for me - highly recommended for anyone using tags in MyTinyTodo!

Here is Copilot's answer to the question:

Image

@maxpozdeev
Copy link
Owner

Probably we need an option how to sort tags. And filter.

@maxpozdeev
Copy link
Owner

tagsList.sort((a, b) => a.tag.localeCompare(b.tag));

In the latest codebase this line should be inserted right before this one -

let cloud = '';

@sokolgeo
Copy link
Author

Probably we need an option how to sort tags. And filter.

In a perfect world, yes.

Right now, the default sorting strategy of "most common first" is very confusing! In any large tag cloud on the screen there is no way to find the tag quickly!

To be honest, I do not see any real alternative to the alphabetical sorting in the tag cloud, provided that you are using any significant number of tags.

@maxpozdeev
Copy link
Owner

Order of tags was not changed since the moment a cloud was featured more than 15 years ago. In this ancient times the cloud sorted by tag usage was a popular solution in some cases. Seems the time for a change has come.

@sokolgeo
Copy link
Author

Order of tags was not changed since the moment a cloud was featured more than 15 years ago. In this ancient times the cloud sorted by tag usage was a popular solution in some cases. Seems the time for a change has come.

I understand.

By my count, I have 45 tags in use today. Tag order may not matter to those who use less than a dozen tags, but when you have to choose the right tag from nearly half a hundred options on a screen, there is simply no alternative to alphabetical tag order!

@maxpozdeev
Copy link
Owner

Order of tags in tag cloud will be changed in v2.0

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

No branches or pull requests

2 participants