Skip to content

Commit

Permalink
laurent22#10077 - sort notebooks and tags based on locale
Browse files Browse the repository at this point in the history
  • Loading branch information
cagnusmarlsen committed Mar 8, 2024
1 parent a624568 commit 1ac19c8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/app-desktop/gui/TagList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { useMemo } from 'react';
import { AppState } from '../app.reducer';
import TagItem from './TagItem';
import Setting from '@joplin/lib/models/Setting';

const { connect } = require('react-redux');
const { themeStyle } = require('@joplin/lib/theme');
Expand All @@ -13,6 +14,7 @@ interface Props {
}

function TagList(props: Props) {
const collatorLocale = Setting.value('locale').slice(0, 2);
const style = useMemo(() => {
const theme = themeStyle(props.themeId);

Expand All @@ -29,13 +31,13 @@ function TagList(props: Props) {

const tags = useMemo(() => {
const output = props.items.slice();
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
const collator = new Intl.Collator(collatorLocale, { numeric: true, sensitivity: 'base' });
output.sort((a: any, b: any) => {
return collator.compare(a.title, b.title);
});

return output;
}, [props.items]);
}, [props.items, collatorLocale]);

const tagItems = useMemo(() => {
const output = [];
Expand Down
5 changes: 5 additions & 0 deletions packages/lib/BaseApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ export default class BaseApplication {
refreshNotes = true;
}

if (action.type === 'SETTING_UPDATE_ONE' && action.key === 'locale') {
refreshNotes = true;
doRefreshFolders = 'now';
}

if (action.type === 'SMART_FILTER_SELECT') {
refreshNotes = true;
refreshNotesUseSelectedNoteId = true;
Expand Down
4 changes: 3 additions & 1 deletion packages/lib/components/shared/side-menu-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Folder from '../../models/Folder';
import BaseModel from '../../BaseModel';
import { FolderEntity, TagEntity } from '../../services/database/types';
import { getDisplayParentId, getTrashFolderId } from '../../services/trash';
import Setting from '../../models/Setting';

interface Props {
folders: FolderEntity[];
Expand Down Expand Up @@ -72,7 +73,8 @@ export const renderFolders = (props: Props, renderItem: RenderFolderItem) => {

export const renderTags = (props: Props, renderItem: RenderTagItem) => {
const tags = props.tags.slice();
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
const collatorLocale = Setting.value('locale').slice(0, 2);
const collator = new Intl.Collator(collatorLocale, { numeric: true, sensitivity: 'base' });
tags.sort((a, b) => {
// It seems title can sometimes be undefined (perhaps when syncing
// and before tag has been decrypted?). It would be best to find
Expand Down
6 changes: 5 additions & 1 deletion packages/lib/models/Folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import syncDebugLog from '../services/synchronizer/syncDebugLog';
import ResourceService from '../services/ResourceService';
import { LoadOptions } from './utils/types';
import { getTrashFolder, getTrashFolderId } from '../services/trash';
import Setting from './Setting';
const { substrWithEllipsis } = require('../string-utils.js');

const logger = Logger.create('models/Folder');
Expand All @@ -21,6 +22,8 @@ export interface FolderEntityWithChildren extends FolderEntity {
children?: FolderEntity[];
}



export default class Folder extends BaseItem {
public static tableName() {
return 'folders';
Expand Down Expand Up @@ -298,7 +301,8 @@ export default class Folder extends BaseItem {
}

public static getNaturalSortingCollator() {
return new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
const collatorLocale = Setting.value('locale').slice(0, 2);
return new Intl.Collator(collatorLocale, { numeric: true, sensitivity: 'base' });
}

public static async all(options: FolderLoadOptions = null) {
Expand Down
3 changes: 2 additions & 1 deletion packages/lib/models/Note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,8 @@ export default class Note extends BaseItem {
}

public static getNaturalSortingCollator() {
return new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
const collatorLocale = Setting.value('locale').slice(0, 2);
return new Intl.Collator(collatorLocale, { numeric: true, sensitivity: 'base' });
}

public static async createConflictNote(sourceNote: NoteEntity, changeSource: number): Promise<NoteEntity> {
Expand Down

0 comments on commit 1ac19c8

Please sign in to comment.