Fix sorting by answer count

This commit is contained in:
MartinBraquet
2026-03-09 13:36:52 +01:00
parent 3c72bca496
commit cae5b96b1e
2 changed files with 3 additions and 2 deletions

View File

@@ -132,6 +132,7 @@ export function CompatibilityQuestionsDisplay(props: {
const sortedAndFilteredAnswers = sortBy(
answers.filter((a) => {
// if (a.id < 10) console.log({a, sort})
const question = compatibilityQuestions.find((q) => q.id === a.question_id)
const comparedAnswer = questionIdToComparedAnswer[a.question_id]
if (question && !isMatchingSearch({...question, answer: a}, searchTerm)) return false

View File

@@ -76,6 +76,7 @@ export function CompatibilitySortWidget(props: {
}
export function compareBySort(a: any, b: any, sort: CompatibilitySort) {
// if (a.id < 10) console.log({a, b, sort})
if (sort === 'random') {
return Math.random() - 0.5
} else if (sort === 'community_importance') {
@@ -83,7 +84,7 @@ export function compareBySort(a: any, b: any, sort: CompatibilitySort) {
const rateB = (b?.community_importance_score ?? 0) / Math.max(b?.answer_count ?? 1, 1)
return rateB - rateA
} else if (sort === 'most_answered') {
return b?.answer_count - a?.answer_count
return (b?.answer_count ?? 0) - (a?.answer_count ?? 0)
} else if (sort === 'newest') {
return (
(b?.created_time ? new Date(b?.created_time).getTime() : 0) -
@@ -96,7 +97,6 @@ export function compareBySort(a: any, b: any, sort: CompatibilitySort) {
}
export function isMatchingSearch(question: any, searchTerm: string) {
console.log(searchTerm, question)
if (searchTerm) {
const searchLower = searchTerm.toLowerCase()