Sort words in public view correctly

This commit is contained in:
Robbie Antenesse 2019-06-06 11:47:21 -06:00 committed by Robbie Antenesse
parent b8ca61d3fe
commit 9fe0da58db
2 changed files with 13 additions and 0 deletions

View File

@ -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();
}

View File

@ -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);