UI: Change sort order to show own before incoming shares

This commit is contained in:
Max Berger
2026-05-02 22:24:13 +02:00
parent 16a0592e5d
commit 67aa15b32d
4 changed files with 136 additions and 6 deletions

View File

@@ -103,11 +103,6 @@ export function get_collections(user, password, collection, callback) {
collections.push(parsedCollection);
}
}
collections.sort(function (a, b) {
/** @type {string} */ let ca = a.displayname || a.href;
/** @type {string} */ let cb = b.displayname || b.href;
return ca.localeCompare(cb);
});
callback(collections, null);
} else {
callback(null, "No valid XML received");

View File

@@ -23,6 +23,7 @@ import { delete_collection } from "../api/api.js";
import { get_auth_header } from "../api/common.js";
import { Collection, CollectionType, Permission } from "../models/collection.js";
import { collectionsCache } from "../utils/collections_cache.js";
import { extract_title } from "../utils/collection_utils.js";
import { ErrorHandler } from "../utils/error.js";
import { bytesToHumanReadable, completeHref, get_element, get_element_by_id } from "../utils/misc.js";
import { UrlTextHandler } from "../utils/url_text.js";
@@ -139,6 +140,23 @@ export class CollectionsScene {
* @param {boolean} clear_error
*/
_show_collections(collections, shares, clear_error) {
collections.sort((a, b) => {
const getShare = (col) => (shares || []).find(
s => (s.ShareType === "map") &&
decodeURIComponent(s.PathOrToken || "").replace(/\/+$/, "") === decodeURIComponent(col.href || "").replace(/\/+$/, ""));
const shareA = getShare(a);
const shareB = getShare(b);
const ownedA = !shareA || shareA.Owner === this._user;
const ownedB = !shareB || shareB.Owner === this._user;
if (ownedA && !ownedB) return -1;
if (!ownedA && ownedB) return 1;
return extract_title(a).localeCompare(extract_title(b));
});
/** @type {HTMLElement} */ let navBar = get_element(document, "#logoutview");
let heightOfNavBar = navBar.offsetHeight + "px";
this._html_scene.style.marginTop = heightOfNavBar;

View File

@@ -44,7 +44,7 @@ export function extractUsernameFromPrincipalCollection(principal_collection) {
export function extract_title(collection) {
if (collection.displayname && collection.displayname.length > 0) {
return collection.displayname;
} else if (collection.type = CollectionType.PRINCIPAL) {
} else if (collection.type === CollectionType.PRINCIPAL) {
return extractUsernameFromPrincipalCollection(collection)
} else
return decodeURIComponent(collection.href);