-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve surah list naming and search
- Loading branch information
Showing
5 changed files
with
692 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,48 @@ | ||
import surahListByApi from "./surah-list-by-api"; | ||
import surahListKemenag from "./surah-list-kemenag"; | ||
import surahListCorrections from "./corrections"; | ||
import createFuzzySearch from "@nozbe/microfuzz"; | ||
import { normalizeLatinText } from "src/lib/search-helper"; | ||
|
||
const surahList = []; | ||
|
||
surahListByApi.forEach(item => { | ||
const kemenag = surahListKemenag[item.id] ?? null; | ||
const correction = surahListCorrections[item.id] ?? null; | ||
|
||
surahList.push({ | ||
id: item.id, | ||
versesCount: item.verses_count, | ||
bismillahPre: item.bismillah_pre, | ||
nameArabic: correction?.nameArabic ?? item.name_arabic, | ||
nameSimple: correction?.nameSimple ?? item.name_simple, | ||
nameTranslated: correction?.nameTranslated ?? item.translated_name.name, | ||
nameArabic: correction?.nameArabic ?? kemenag?.nameArabic, | ||
nameSimple: correction?.nameSimple ?? kemenag?.nameSimple, | ||
nameTranslated: correction?.nameTranslated ?? kemenag?.nameTranslated, | ||
pages: item.pages | ||
}); | ||
}); | ||
|
||
const getFilteredSurahList = keyword => { | ||
if (!keyword) { | ||
return surahList; | ||
} | ||
|
||
const q = normalizeLatinText(keyword); | ||
const fuzzySearch = createFuzzySearch(surahList, { | ||
getText: item => [item.nameSimple, item.nameArabic, item.nameTranslated] | ||
}); | ||
|
||
const filtered = fuzzySearch(q).map(item => { | ||
return { | ||
...item.item | ||
}; | ||
}); | ||
|
||
// Keep order | ||
filtered.sort((a, b) => a.id - b.id); | ||
|
||
return filtered; | ||
}; | ||
|
||
export { surahList, getFilteredSurahList }; | ||
|
||
export default surahList; |
Oops, something went wrong.