mytinytodo icon indicating copy to clipboard operation
mytinytodo copied to clipboard

Patch: Sort tags alphabetically

Open sokolgeo opened this issue 1 week ago • 8 comments

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?

sokolgeo avatar Feb 18 '25 13:02 sokolgeo