Skip to content

Commit

Permalink
修复一个排序错误
Browse files Browse the repository at this point in the history
  • Loading branch information
zzlb0224 committed Apr 6, 2024
1 parent bcbc4a5 commit d803e8c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
32 changes: 9 additions & 23 deletions src/modules/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import {
sortModified,
sortTags,
sortTags1000Ann100Modified10Asc,
sortTags100Modified10Asc,
sortFixedTags100Modified10Asc,
sortFixedTags10ValuesLength,
sortValuesLength,
} from "../utils/sort";
import { mapDateModified } from "../utils/sort";
function register() {
// if (!getPref("enable")) return;
// ztoolkit.UI.basicOptions.log.disableZLog = true;
Expand Down Expand Up @@ -156,6 +157,7 @@ export class AnnotationPopup {
}, 500);
return div;
}

private async updateDiv(root: HTMLDivElement) {
const doc = this.doc;
if (!doc) return;
Expand All @@ -179,15 +181,10 @@ export class AnnotationPopup {
}
if (getPref("show-relate-tags")) groupByResultIncludeFixedTags(relateTags);
if (getPref("sort") == "2") {
//
relateTags = relateTags
.map((r) => ({
key: r.key,
dateModified: r.values
.map((v) => v.dateModified)
.sort((a, b) => (b > a ? -1 : 1))[0],
values: r.values,
}))
.sort(sortTags100Modified10Asc);
.map(mapDateModified)
.sort(sortFixedTags100Modified10Asc);
} else if (getPref("sort") == "3") {
const itemAnnTags = this.item
? // Zotero.Items.get(this.item.parentItem.getAttachments()).flatMap((f) => f.getAnnotations())
Expand All @@ -197,24 +194,13 @@ export class AnnotationPopup {
.map((a) => a.tag)
.sort(sortAsc)
: [];

relateTags = relateTags
.map((r) => ({
key: r.key,
dateModified: r.values
.map((v) => v.dateModified)
.sort((a, b) => (b > a ? -1 : 1))[0],
values: r.values,
}))
.map(mapDateModified)
.sort(sortTags1000Ann100Modified10Asc(itemAnnTags));
} else {
relateTags = relateTags
.map((r) => ({
key: r.key,
dateModified: r.values
.map((v) => v.dateModified)
.sort((a, b) => (b > a ? -1 : 1))[0],
values: r.values,
}))
.map(mapDateModified)
.sort(sortFixedTags10ValuesLength);
}

Expand Down
14 changes: 13 additions & 1 deletion src/utils/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function sortModified(
return sortAsc(b.dateModified, a.dateModified);
}

export function sortTags100Modified10Asc(
export function sortFixedTags100Modified10Asc(
a: { key: string; dateModified: string },
b: { key: string; dateModified: string },
) {
Expand All @@ -83,3 +83,15 @@ export function sortTags1000Ann100Modified10Asc(tags: string[]) {
sortModified(a, b) * 10 +
sortKey(a, b);
}
export function mapDateModified(r: {
key: string;
values: { dateModified: string; tag: string; type: number }[];
}) {
return {
key: r.key,
dateModified: r.values
.map((v) => v.dateModified)
.sort((a, b) => (a > b ? -1 : 1))[0],
values: r.values,
};
}

0 comments on commit d803e8c

Please sign in to comment.