diff --git a/src/css/components/TheQuran/Shape.scss b/src/css/components/TheQuran/Shape.scss new file mode 100644 index 000000000..c8cfc82ea --- /dev/null +++ b/src/css/components/TheQuran/Shape.scss @@ -0,0 +1,38 @@ +.shape-box { + display: flex; + align-items: center; + justify-content: center; + flex-direction: row; + width: 24px; + height: 24px; + border-radius: 5px; + background: #606850; + cursor: pointer; + +} + +.shape-box .play-shape { + position: relative; + left: 1px; + width: 12px; + height: 12px; + background: #FFF; + clip-path: polygon(0 0, 100% 50%, 0 100%); +} + +.shape-box .pause-shape { + width: 3px; + height: 12px; + background: #FFF; + clip-path: stroke-box; + + &:first-child { + position: relative; + right: 2px; + } + + &:last-child { + position: relative; + left: 1.5px; + } +} diff --git a/src/css/surah.scss b/src/css/surah.scss index ffc0768e6..4eef80aaa 100644 --- a/src/css/surah.scss +++ b/src/css/surah.scss @@ -1,5 +1,6 @@ @import "fonts"; @import "components/Select"; +@import "components/TheQuran/Shape"; $black: #454545; @@ -104,17 +105,24 @@ body { } .surah .timer { - margin: 0 auto; display: flex; justify-content: center; flex-direction: column; font-size: 65%; - font-family: "Roboto Mono Regular"; + font-family: "Kanit Regular"; text-align: center; - width: 30px; + width: 32px; + height: 18px; font-weight: bold; - border-radius: 10px; - padding: 3px; + border-radius: 5px; + padding: 2px; + position: relative; + top: 4px; + } + + .surah.ar .timer { + position: relative; + top: 2px; } } diff --git a/src/css/themes/moon.scss b/src/css/themes/moon.scss index 6649a59af..83f4b86be 100644 --- a/src/css/themes/moon.scss +++ b/src/css/themes/moon.scss @@ -24,9 +24,13 @@ } } - .timer { + .surah-row .timer { color: $white; - background-color: lighten($gold, 5%); + background: $gold; + } + + .surah-row .container.shape { + background: $gold; } } diff --git a/src/js/components/Select.tsx b/src/js/components/Select.tsx index c98b570b7..6576839f5 100644 --- a/src/js/components/Select.tsx +++ b/src/js/components/Select.tsx @@ -35,8 +35,7 @@ const createOption = (e: ChangeEvent, children: JSX.Element[]): SelectOption => }; }; -export function Select(props: Props) { - const { children, className, value, onChange } = props; +export function Select({ value, children, onChange, className }: Props) { const [open, setOpen] = useState(false); const [activeOption, setActiveOption] = useState(findOption(value, children)); const openSelect = (e: React.MouseEvent) => { diff --git a/src/js/components/TheQuran/LanguageSelect.tsx b/src/js/components/TheQuran/LanguageSelect.tsx index 893666fb9..a697db02c 100644 --- a/src/js/components/TheQuran/LanguageSelect.tsx +++ b/src/js/components/TheQuran/LanguageSelect.tsx @@ -6,13 +6,15 @@ interface Props { locale: string surah: Surah stream: Ayah[] + isPaused: boolean } -export function LanguageSelect(props: Props) { - const { locale, surah, stream } = props; +export function LanguageSelect({ locale, surah, stream, isPaused }: Props) { const changeLanguage = (o: SelectOption) => { const locale = o.value; - location.replace(`/${locale}/${surah.slug}/?ayah=${stream.length}`); + location.replace( + `/${locale}/${surah.slug}/?ayah=${stream.length}&paused=${isPaused ? 't' : 'f'}` + ); }; return ( diff --git a/src/js/components/TheQuran/Shape.tsx b/src/js/components/TheQuran/Shape.tsx new file mode 100644 index 000000000..250ab6e27 --- /dev/null +++ b/src/js/components/TheQuran/Shape.tsx @@ -0,0 +1,22 @@ +import React from 'react'; + +interface Props { + onClick: () => void +} + +export function PlayShape({ onClick }: Props) { + return ( +
+
+
+ ); +} + +export function PauseShape({ onClick }: Props) { + return ( +
+
+
+
+ ); +} diff --git a/src/js/components/TheQuran/Stream.tsx b/src/js/components/TheQuran/Stream.tsx index ce5d546b2..7d8d158e2 100644 --- a/src/js/components/TheQuran/Stream.tsx +++ b/src/js/components/TheQuran/Stream.tsx @@ -10,12 +10,13 @@ interface Props { locale: Locale slice: Slice endOfStream: boolean + isPaused: boolean } -export function Stream({ surah, stream, locale, slice, endOfStream }: Props) { +export function Stream({ surah, stream, locale, slice, endOfStream, isPaused }: Props) { const n = numbers(locale); const s = strings(locale); - const className = classNames('stream', { 'scroll-y': endOfStream }); + const className = classNames('stream', { 'scroll-y': endOfStream || isPaused }); const ayat = stream.map((ayah: Ayah) => { return (
  • diff --git a/src/js/components/TheQuran/Timer.tsx b/src/js/components/TheQuran/Timer.tsx index ae2b332db..e312ba056 100644 --- a/src/js/components/TheQuran/Timer.tsx +++ b/src/js/components/TheQuran/Timer.tsx @@ -7,19 +7,22 @@ interface Props { locale: Locale stream: Ayat setStream: (stream: Ayat) => void + isPaused: boolean } -export function Timer ({ surah, stream, setStream, locale }: Props) { +export function Timer ({ surah, stream, setStream, locale, isPaused }: Props) { const ayah = stream[stream.length - 1]; const [ms, setMs] = useState(ayah.readTimeMs); useEffect(() => setMs(ayah.readTimeMs), [ayah.id]); useEffect(() => { - if (ms <= 0) { + if (isPaused) { + return; + } else if (ms <= 0) { setStream([...stream, surah.ayat[ayah.id.number]]); } else { setTimeout(() => setMs(ms - 100), 100); } - }, [ms]); + }, [ms, isPaused]); return (
    {numberToDecimal(ms / 1000, locale)} diff --git a/src/js/lib/i18n.ts b/src/js/lib/i18n.ts index f77d76a09..5bb18d95f 100644 --- a/src/js/lib/i18n.ts +++ b/src/js/lib/i18n.ts @@ -66,6 +66,6 @@ export function numberToDecimal(number: number, locale: Locale): string { const s = strings(locale); const n = numbers(locale); return decimal.split('.') - .map((num: Digit) => n(num)) - .join(s('decimal')); + .map((num: Digit) => n(num)) + .join(` ${s('decimal')} `); } diff --git a/src/js/pages/TheSurahPage.tsx b/src/js/pages/TheSurahPage.tsx index 552a34e60..e7c0ea97f 100644 --- a/src/js/pages/TheSurahPage.tsx +++ b/src/js/pages/TheSurahPage.tsx @@ -6,6 +6,7 @@ import { Timer } from 'components/TheQuran/Timer'; import { Stream } from 'components/TheQuran/Stream'; import { ThemeSelect } from 'components/TheQuran/ThemeSelect'; import { LanguageSelect } from 'components/TheQuran/LanguageSelect'; +import { PlayShape, PauseShape } from 'components/TheQuran/Shape'; import { Locale, Surah } from 'lib/Quran'; import { Slice } from 'lib/Quran/slice'; @@ -13,12 +14,14 @@ interface Props { locale: Locale surahId: number slice: Slice + paused: boolean } -function TheSurahPage({ locale, surahId, slice }: Props) { +function TheSurahPage({ locale, surahId, slice, paused }: Props) { const path = `/${locale}/${surahId}/surah.json`; const node: HTMLScriptElement = document.querySelector(`script[src="${path}"]`); const [stream, setStream] = useState([]); + const [isPaused, setIsPaused] = useState(paused); const [theme, setTheme] = useState(getCookie('theme') || 'moon'); const [surah] = useState(Surah.fromDOMNode(locale, node)); const readyToRender = stream.length > 0; @@ -52,11 +55,16 @@ function TheSurahPage({ locale, surahId, slice }: Props) { {readyToRender && (
    - +
    )} {readyToRender && ( -
    +
    {surahName} {surah.transliteratedName}
    @@ -68,27 +76,36 @@ function TheSurahPage({ locale, surahId, slice }: Props) { stream={stream} locale={locale} endOfStream={endOfStream} + isPaused={isPaused} /> } - {readyToRender && !endOfStream && ( - - )} +
    + { readyToRender && isPaused && !endOfStream && + setIsPaused(false)}/> } + { readyToRender && !isPaused && !endOfStream && + setIsPaused(true)}/> } + { readyToRender && !endOfStream && + } +
    ); } (function() { + const toBoolean = (str: string | null): boolean => ['1', 't', 'true', 'yes'].includes(str); const rootBox: HTMLElement = document.querySelector('.root-box'); const locale = rootBox.getAttribute('data-locale') as Locale; const surahId = parseInt(rootBox.getAttribute('data-surah-id')); const params = new URLSearchParams(location.search); const slice = Slice.fromParam(params.get('ayah')); + const paused = toBoolean(params.get('paused')); ReactDOM .createRoot(rootBox) @@ -97,6 +114,7 @@ function TheSurahPage({ locale, surahId, slice }: Props) { locale={locale} surahId={surahId} slice={slice} + paused={paused} /> ); })();