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 9743e934d3
commit 9d793c6c7d
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 { setupSearchFilters, setupInfoModal } from './setupListeners';
import { parseReferences } from './wordManagement'; import { parseReferences } from './wordManagement';
import { renderAd } from '../ads'; import { renderAd } from '../ads';
import { sortWords } from './wordManagement';
export function renderAll() { export function renderAll() {
renderTheme(); renderTheme();
renderDictionaryDetails(); renderDictionaryDetails();
renderPartsOfSpeech(); renderPartsOfSpeech();
sortWords();
renderWords(); renderWords();
} }

View File

@ -1,4 +1,15 @@
import { wordExists, getHomonymnIndexes } from "./utilities"; 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) { export function parseReferences(detailsMarkdown) {
const references = detailsMarkdown.match(/\{\{.+?\}\}/g); const references = detailsMarkdown.match(/\{\{.+?\}\}/g);