diff --git a/frontends/etiquette_flask/templates/photo.html b/frontends/etiquette_flask/templates/photo.html index 5259104..3ba3250 100644 --- a/frontends/etiquette_flask/templates/photo.html +++ b/frontends/etiquette_flask/templates/photo.html @@ -327,6 +327,7 @@ function add_photo_tag_callback(response) li.appendChild(tag_object); li.appendChild(remove_button); this_tags.appendChild(li); + sort_tag_objects(); } function remove_photo_tag_form(photo_id, tagname) @@ -382,6 +383,23 @@ function add_remove_photo_tag_callback(response) common.create_message_bubble(message_area, message_positivity, message_text, 8000); } +function sort_tag_objects() +{ + const tag_list = document.getElementById("this_tags"); + const lis = Array.from(tag_list.children).filter(el => el.getElementsByClassName("tag_object").length); + function compare(li1, li2) + { + const tag1 = li1.querySelector(".tag_object:last-of-type").innerText; + const tag2 = li2.querySelector(".tag_object:last-of-type").innerText; + return tag1 < tag2 ? -1 : 1; + } + lis.sort(compare); + for (const li of lis) + { + tag_list.appendChild(li); + } +} + function generate_thumbnail_callback(response) { if (response.meta.status == 200)