Sort words in public view correctly
This commit is contained in:
parent
9743e934d3
commit
9d793c6c7d
|
@ -6,11 +6,13 @@ import { showSection } from './displayToggles';
|
|||
import { setupSearchFilters, setupInfoModal } from './setupListeners';
|
||||
import { parseReferences } from './wordManagement';
|
||||
import { renderAd } from '../ads';
|
||||
import { sortWords } from './wordManagement';
|
||||
|
||||
export function renderAll() {
|
||||
renderTheme();
|
||||
renderDictionaryDetails();
|
||||
renderPartsOfSpeech();
|
||||
sortWords();
|
||||
renderWords();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,15 @@
|
|||
import { wordExists, getHomonymnIndexes } from "./utilities";
|
||||
import removeDiacritics from "../StackOverflow/removeDiacritics";
|
||||
|
||||
export function sortWords() {
|
||||
const { sortByDefinition } = window.currentDictionary.settings;
|
||||
const sortBy = sortByDefinition ? 'definition' : 'name';
|
||||
|
||||
window.currentDictionary.words.sort((wordA, wordB) => {
|
||||
if (removeDiacritics(wordA[sortBy]).toLowerCase() === removeDiacritics(wordB[sortBy]).toLowerCase()) return 0;
|
||||
return removeDiacritics(wordA[sortBy]).toLowerCase() > removeDiacritics(wordB[sortBy]).toLowerCase() ? 1 : -1;
|
||||
});
|
||||
}
|
||||
|
||||
export function parseReferences(detailsMarkdown) {
|
||||
const references = detailsMarkdown.match(/\{\{.+?\}\}/g);
|
||||
|
|
Loading…
Reference in New Issue