From 717e11944e0a7a89f9161fa2d2ca3dc92adb6b45 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Tue, 30 Jan 2024 18:33:26 -0300 Subject: [PATCH] Add filter to SurahIndex.tsx --- src/css/pages/SurahIndex.scss | 7 +++++ src/css/themes/blue/pages/_SurahIndex.scss | 6 ++++ src/css/themes/green/pages/_SurahIndex.scss | 20 +++++++++---- src/i18n.json | 2 ++ src/js/components/SurahIndexFilter.tsx | 32 +++++++++++++++++++++ src/js/pages/SurahIndex.tsx | 12 ++++++-- 6 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/js/components/SurahIndexFilter.tsx diff --git a/src/css/pages/SurahIndex.scss b/src/css/pages/SurahIndex.scss index 62b75c8..0491ee7 100644 --- a/src/css/pages/SurahIndex.scss +++ b/src/css/pages/SurahIndex.scss @@ -56,6 +56,7 @@ body .root .content.theme { } footer { + flex-wrap: unset; a { display: flex; flex-direction: row; @@ -66,6 +67,11 @@ body .root .content.theme { padding: 0 0 0 7px; } } + input { + padding: 10px; + border-radius: 10px; + border: 1px solid #000; + } } } @@ -94,6 +100,7 @@ body .root .content.theme.ar { } footer { + flex-direction: unset; font-family: "Mada Regular"; a span { padding: 0 7px 0 0; diff --git a/src/css/themes/blue/pages/_SurahIndex.scss b/src/css/themes/blue/pages/_SurahIndex.scss index ae6ede1..003b6ba 100644 --- a/src/css/themes/blue/pages/_SurahIndex.scss +++ b/src/css/themes/blue/pages/_SurahIndex.scss @@ -29,6 +29,12 @@ font-weight: bold; } } + input { + border: 1px solid $primary-color; + &:focus { + outline-color: $primary-color; + } + } } } diff --git a/src/css/themes/green/pages/_SurahIndex.scss b/src/css/themes/green/pages/_SurahIndex.scss index 04cbbdc..c0a0d87 100644 --- a/src/css/themes/green/pages/_SurahIndex.scss +++ b/src/css/themes/green/pages/_SurahIndex.scss @@ -14,13 +14,21 @@ } } - footer a { - &:active, &:link, &:visited { - color: $green1; - text-decoration: none; + footer { + a { + &:active, &:link, &:visited { + color: $green1; + text-decoration: none; + } + &:hover { + font-weight: bold; + } } - &:hover { - font-weight: bold; + input { + border: 1px solid $green1; + &:focus { + outline-color: $green1; + } } } } diff --git a/src/i18n.json b/src/i18n.json index e633d6e..17747d5 100644 --- a/src/i18n.json +++ b/src/i18n.json @@ -5,6 +5,7 @@ "surah": "Surah", "ayah": "Ayah", "comma": ",", + "filter": "Filter", "meta": { "index": {"description": "Explore the chapters of The Noble Quran. Browse a list of chapters and choose a chapter you can read and listen to. Enhance your understanding of a sacred text."}, "stream": {"description": "Experience The Noble Quran. Read and listen to a single chapter with a verse streamed at regular intervals. Immerse yourself in a sacred text in a unique way."} @@ -134,6 +135,7 @@ "surah": "سورة", "ayah": "آية", "comma": "،", + "filter": "تصفية", "meta": { "index": { "description": "استكشف فصول القرآن الكريم. تصفح قائمة بالفصول واختر فصلاً يمكنك قراءته والاستماع إليه. قم بتعزيز فهمك لنص مقدس." diff --git a/src/js/components/SurahIndexFilter.tsx b/src/js/components/SurahIndexFilter.tsx new file mode 100644 index 0000000..f017572 --- /dev/null +++ b/src/js/components/SurahIndexFilter.tsx @@ -0,0 +1,32 @@ +import React from "react"; +import { TFunction } from "lib/i18n"; +import * as Quran from "lib/Quran"; + +type Props = { + t: TFunction; + locale: Quran.Locale; + setIndex: (k: Quran.Surah[]) => void; + surahs: Quran.Surah[]; +}; + +export function SurahIndexFilter({ t, locale, setIndex, surahs }: Props) { + const onInput = (e: React.ChangeEvent) => { + const { + target: { value }, + } = e; + if (value === "") { + setIndex(surahs); + } else { + const regexp = new RegExp(value, "i"); + const newIndex = surahs.filter( + surah => + regexp.test(surah.localizedName) || regexp.test(String(surah.id)), + ); + setIndex(newIndex); + } + }; + + return ( + + ); +} diff --git a/src/js/pages/SurahIndex.tsx b/src/js/pages/SurahIndex.tsx index 95900a7..b750af1 100644 --- a/src/js/pages/SurahIndex.tsx +++ b/src/js/pages/SurahIndex.tsx @@ -1,4 +1,4 @@ -import React, { useRef, useEffect } from "react"; +import React, { useRef, useState, useEffect } from "react"; import ReactDOM from "react-dom/client"; import classNames from "classnames"; @@ -8,6 +8,7 @@ import { ThemeSelect } from "components/ThemeSelect"; import { LanguageSelect } from "components/LanguageSelect"; import { i18n, formatNumber, TFunction } from "lib/i18n"; import { RightArrow } from "components/Icon"; +import { SurahIndexFilter } from "components/SurahIndexFilter"; interface Props { locale: Quran.Locale; @@ -17,6 +18,7 @@ interface Props { function SurahIndex({ locale, surahs, t }: Props) { const [theme, setTheme] = useTheme(); + const [index, setIndex] = useState(surahs); const ref = useRef(); useEffect(() => { @@ -41,7 +43,7 @@ function SurahIndex({ locale, surahs, t }: Props) {