Skip to content

Commit

Permalink
Fix: #368 sidebar sort (#371)
Browse files Browse the repository at this point in the history
Fix #368
  • Loading branch information
GeoffreyChen777 authored Feb 6, 2024
1 parent 30fdf1f commit 55ce4c7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
25 changes: 24 additions & 1 deletion app/renderer/services/querysentence-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export class QuerySentenceService {
)
parseViewTree(
data: ICategorizerCollection | IPaperSmartFilterCollection,
type: CategorizerType | PaperSmartFilterType
type: CategorizerType | PaperSmartFilterType,
sortBy: string,
sortOrder: string
): ViewTreeNode {
if (data.length === 0) {
return {
Expand Down Expand Up @@ -124,6 +126,10 @@ export class QuerySentenceService {
this._DAG2Tree(graph, rootID),
`0-${rootID}`
);

// Sort the view tree
this._sortViewTree(viewTree, sortBy, sortOrder);

return viewTree;
}

Expand Down Expand Up @@ -209,6 +215,23 @@ export class QuerySentenceService {

return { updatedTree, viewTree };
}

private _sortViewTree(
viewTree: ViewTreeNode,
sortBy: string,
sortOrder: string
) {
viewTree.children.sort((a: ViewTreeNode, b: ViewTreeNode) => {
if (sortOrder === "asce") {
return a[sortBy] > b[sortBy] ? 1 : -1;
} else {
return a[sortBy] < b[sortBy] ? 1 : -1;
}
});
viewTree.children.forEach((child) => {
this._sortViewTree(child, sortBy, sortOrder);
});
}
}

export interface ViewTreeNode {
Expand Down
12 changes: 9 additions & 3 deletions app/renderer/ui/sidebar-view/sidebar-library-view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const tags = inject<Ref<ICategorizerCollection>>("tags");
const tagsViewTree = computed(() => {
return querySentenceService.parseViewTree(
tags?.value || [],
CategorizerType.PaperTag
CategorizerType.PaperTag,
prefState.sidebarSortBy,
prefState.sidebarSortOrder
);
});
Expand All @@ -46,15 +48,19 @@ const foldersViewTree = computed(() => {
const linked = prefState.pluginLinkedFolder;
return querySentenceService.parseViewTree(
folders?.value || [],
CategorizerType.PaperFolder
CategorizerType.PaperFolder,
prefState.sidebarSortBy,
prefState.sidebarSortOrder
);
});
const smartfilters = inject<Ref<IPaperSmartFilterCollection>>("smartfilters");
const smartfiltersViewTree = computed(() => {
return querySentenceService.parseViewTree(
smartfilters?.value || [],
PaperSmartFilterType.smartfilter
PaperSmartFilterType.smartfilter,
prefState.sidebarSortBy,
prefState.sidebarSortOrder
);
});
Expand Down

0 comments on commit 55ce4c7

Please sign in to comment.