diff --git a/src/css/pages/SurahIndex.scss b/src/css/pages/SurahIndex.scss index 5da80e5..925055f 100644 --- a/src/css/pages/SurahIndex.scss +++ b/src/css/pages/SurahIndex.scss @@ -100,5 +100,5 @@ body .root .content.theme.ar { } } -@import "themes/moon"; -@import "themes/leaf"; +@import "themes/blue"; +@import "themes/green"; diff --git a/src/css/pages/SurahStream.scss b/src/css/pages/SurahStream.scss index 3491585..ecea8ec 100644 --- a/src/css/pages/SurahStream.scss +++ b/src/css/pages/SurahStream.scss @@ -61,6 +61,20 @@ justify-content: flex-end !important; } +.content.theme { + .row.dropdown-row { + .react-select.theme { + cursor: pointer; + ul li.blue { + display: block; + width: 16px; + height: 16px; + background: #000; + } + } + } +} + .content.theme.en {} .content.theme.ar { @@ -102,5 +116,5 @@ } } -@import "themes/moon"; -@import "themes/leaf"; +@import "themes/blue"; +@import "themes/green"; diff --git a/src/css/themes/blue.scss b/src/css/themes/blue.scss new file mode 100644 index 0000000..a03ade1 --- /dev/null +++ b/src/css/themes/blue.scss @@ -0,0 +1,7 @@ +@import "blue/layout"; +@import "blue/pages/SurahIndex"; +@import "blue/pages/SurahStream"; + +.root .content.theme.blue.ar { + direction: rtl; +} diff --git a/src/css/themes/moon/_colors.scss b/src/css/themes/blue/_colors.scss similarity index 100% rename from src/css/themes/moon/_colors.scss rename to src/css/themes/blue/_colors.scss diff --git a/src/css/themes/moon/_layout.scss b/src/css/themes/blue/_layout.scss similarity index 82% rename from src/css/themes/moon/_layout.scss rename to src/css/themes/blue/_layout.scss index 1362721..df3b1df 100644 --- a/src/css/themes/moon/_layout.scss +++ b/src/css/themes/blue/_layout.scss @@ -1,4 +1,4 @@ -.root .content.theme.moon { +.root .content.theme.blue { @import "colors"; .row.title { diff --git a/src/css/themes/moon/components/_Icon.scss b/src/css/themes/blue/components/_Icon.scss similarity index 100% rename from src/css/themes/moon/components/_Icon.scss rename to src/css/themes/blue/components/_Icon.scss diff --git a/src/css/themes/moon/pages/_SurahIndex.scss b/src/css/themes/blue/pages/_SurahIndex.scss similarity index 86% rename from src/css/themes/moon/pages/_SurahIndex.scss rename to src/css/themes/blue/pages/_SurahIndex.scss index 9f1e734..9d236d8 100644 --- a/src/css/themes/moon/pages/_SurahIndex.scss +++ b/src/css/themes/blue/pages/_SurahIndex.scss @@ -1,5 +1,5 @@ -.root .content.theme.moon { - @import "themes/moon/colors"; +.root .content.theme.blue { + @import "themes/blue/colors"; .row.title { justify-content: center; diff --git a/src/css/themes/moon/pages/_SurahStream.scss b/src/css/themes/blue/pages/_SurahStream.scss similarity index 67% rename from src/css/themes/moon/pages/_SurahStream.scss rename to src/css/themes/blue/pages/_SurahStream.scss index 66a0f66..6244985 100644 --- a/src/css/themes/moon/pages/_SurahStream.scss +++ b/src/css/themes/blue/pages/_SurahStream.scss @@ -1,6 +1,6 @@ -.root .content.theme.moon { - @import "themes/moon/colors"; - @import "themes/moon/components/Icon"; +.root .content.theme.blue { + @import "themes/blue/colors"; + @import "themes/blue/components/Icon"; .row.details { color: $gold-primary; @@ -20,8 +20,8 @@ } } -.root .content.theme.moon.ar { - @import "themes/moon/colors"; +.root .content.theme.blue.ar { + @import "themes/blue/colors"; .row.dropdown-row { line-height: 30px; diff --git a/src/css/themes/green.scss b/src/css/themes/green.scss new file mode 100644 index 0000000..0161f2d --- /dev/null +++ b/src/css/themes/green.scss @@ -0,0 +1,7 @@ +@import "green/layout"; +@import "green/pages/SurahIndex"; +@import "green/pages/SurahStream"; + +.root .content.theme.green.ar { + direction: rtl; +} diff --git a/src/css/themes/leaf/_colors.scss b/src/css/themes/green/_colors.scss similarity index 100% rename from src/css/themes/leaf/_colors.scss rename to src/css/themes/green/_colors.scss diff --git a/src/css/themes/leaf/_layout.scss b/src/css/themes/green/_layout.scss similarity index 55% rename from src/css/themes/leaf/_layout.scss rename to src/css/themes/green/_layout.scss index 9c86036..f5c7dbe 100644 --- a/src/css/themes/leaf/_layout.scss +++ b/src/css/themes/green/_layout.scss @@ -1,11 +1,6 @@ -.root .content.theme.leaf { +.root .content.theme.green { @import "colors"; - .header .image { - background-image: url("/images/leaf.svg"); - background-size: cover; - } - .row.title { color: $green; } diff --git a/src/css/themes/leaf/components/_Icon.scss b/src/css/themes/green/components/_Icon.scss similarity index 100% rename from src/css/themes/leaf/components/_Icon.scss rename to src/css/themes/green/components/_Icon.scss diff --git a/src/css/themes/leaf/pages/_SurahIndex.scss b/src/css/themes/green/pages/_SurahIndex.scss similarity index 86% rename from src/css/themes/leaf/pages/_SurahIndex.scss rename to src/css/themes/green/pages/_SurahIndex.scss index 295ec12..f089602 100644 --- a/src/css/themes/leaf/pages/_SurahIndex.scss +++ b/src/css/themes/green/pages/_SurahIndex.scss @@ -1,5 +1,5 @@ -.root .content.theme.leaf { - @import "themes/leaf/colors"; +.root .content.theme.green { + @import "themes/green/colors"; ul.body.index a { &:active, &:link, &:visited { diff --git a/src/css/themes/leaf/pages/_SurahStream.scss b/src/css/themes/green/pages/_SurahStream.scss similarity index 75% rename from src/css/themes/leaf/pages/_SurahStream.scss rename to src/css/themes/green/pages/_SurahStream.scss index 0154822..eec19ed 100644 --- a/src/css/themes/leaf/pages/_SurahStream.scss +++ b/src/css/themes/green/pages/_SurahStream.scss @@ -1,6 +1,6 @@ -.root .content.theme.leaf { - @import "themes/leaf/colors"; - @import "themes/leaf/components/Icon"; +.root .content.theme.green { + @import "themes/green/colors"; + @import "themes/green/components/Icon"; .row.details { color: $green; @@ -33,8 +33,8 @@ } } -.root .content.theme.leaf.ar { - @import "themes/leaf/colors"; +.root .content.theme.green.ar { + @import "themes/green/colors"; .row.dropdown-row { .surah-name { diff --git a/src/css/themes/leaf.scss b/src/css/themes/leaf.scss deleted file mode 100644 index 1c0c353..0000000 --- a/src/css/themes/leaf.scss +++ /dev/null @@ -1,7 +0,0 @@ -@import "leaf/layout"; -@import "leaf/pages/SurahIndex"; -@import "leaf/pages/SurahStream"; - -.root .content.theme.leaf.ar { - direction: rtl; -} diff --git a/src/css/themes/moon.scss b/src/css/themes/moon.scss deleted file mode 100644 index d861eae..0000000 --- a/src/css/themes/moon.scss +++ /dev/null @@ -1,7 +0,0 @@ -@import "moon/layout"; -@import "moon/pages/SurahIndex"; -@import "moon/pages/SurahStream"; - -.root .content.theme.moon.ar { - direction: rtl; -} diff --git a/src/js/components/LanguageSelect.tsx b/src/js/components/LanguageSelect.tsx index d2ebfa2..c0505f3 100644 --- a/src/js/components/LanguageSelect.tsx +++ b/src/js/components/LanguageSelect.tsx @@ -1,14 +1,21 @@ import React from "react"; -import { Select, SelectOption } from "components/Select"; +import { Select } from "components/Select"; interface Props { locale: string; - onChange: (o: SelectOption) => void; + path?: string; } -export function LanguageSelect({ locale, onChange }: Props) { +export function LanguageSelect({ locale, path = "" }: Props) { return ( - { + const locale = el.props.value; + location.replace([locale, path].join("/")); + }} + > diff --git a/src/js/components/Select.tsx b/src/js/components/Select.tsx index e6ac56d..0181e59 100644 --- a/src/js/components/Select.tsx +++ b/src/js/components/Select.tsx @@ -5,43 +5,20 @@ export type ChangeEvent = React.MouseEvent & { target: HTMLLIElement; }; -export interface SelectOption { - innerText: string; - value: string; - reactEvent: ChangeEvent; -} - interface Props { value: string; children: JSX.Element[]; - onChange: (e: SelectOption) => void; + onChange: (e: JSX.Element) => void; className?: string; } -const findOption = (value: string, children: JSX.Element[]) => { - const activeOption = children.find(o => o.props.value === value); - if (activeOption) { - return activeOption.props.children; - } else { - return null; - } -}; - -const createOption = (e: ChangeEvent, children: JSX.Element[]): SelectOption => { - const { target } = e; - const value = target.getAttribute("data-value")!; - return { - innerText: findOption(value, children), - value, - reactEvent: e, - }; +const find = (option: string, options: JSX.Element[]) => { + return options.find(o => o.props.value === option); }; export function Select({ value, children, onChange, className }: Props) { const [open, setOpen] = useState(false); - const [activeOption, setActiveOption] = useState( - findOption(value, children), - ); + const [activeOption, setActiveOption] = useState(find(value, children)); const openSelect = (e: React.MouseEvent) => { e.stopPropagation(); setOpen(true); @@ -49,9 +26,9 @@ export function Select({ value, children, onChange, className }: Props) { const selectOption = (e: ChangeEvent) => { e.stopPropagation(); const target: HTMLLIElement = e.target; - const option = createOption(e, children); + const option = find(String(target.value), children); onChange(option); - setActiveOption(target.innerText); + setActiveOption(option); setOpen(false); }; @@ -61,15 +38,19 @@ export function Select({ value, children, onChange, className }: Props) { return (
- - {activeOption} - + diff --git a/src/js/components/ThemeSelect.tsx b/src/js/components/ThemeSelect.tsx index 3ea11f4..e1f3b08 100644 --- a/src/js/components/ThemeSelect.tsx +++ b/src/js/components/ThemeSelect.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { Select, SelectOption } from "components/Select"; +import { Select } from "components/Select"; interface Props { setTheme: (theme: string) => void; @@ -11,14 +11,10 @@ export function ThemeSelect({ setTheme, theme }: Props) { ); } diff --git a/src/js/hooks/useTheme.ts b/src/js/hooks/useTheme.ts index ba34f8c..d983d97 100644 --- a/src/js/hooks/useTheme.ts +++ b/src/js/hooks/useTheme.ts @@ -6,13 +6,7 @@ const THEMES: Theme[] = ["blue", "green"]; const DEFAULT_THEME = "blue"; export function useTheme(): [Theme, (t: string) => void] { - const [theme, setTheme] = useState(null); - const cookie = getCookie("theme"); - - useEffect(() => { - const _theme = THEMES.find((theme: Theme) => cookie === theme); - setTheme(_theme || DEFAULT_THEME); - }, []); + const [theme, setTheme] = useState(DEFAULT_THEME); function _setTheme(newTheme: string) { const matchedTheme = THEMES.find((theme: Theme) => newTheme === theme); @@ -22,5 +16,11 @@ export function useTheme(): [Theme, (t: string) => void] { } } + useEffect(() => { + const cookie = getCookie("theme"); + const _theme = THEMES.find((theme: Theme) => cookie === theme); + _setTheme(_theme || DEFAULT_THEME); + }, []); + return [theme, _setTheme]; } diff --git a/src/js/pages/SurahIndex.tsx b/src/js/pages/SurahIndex.tsx index a3cc8c9..f8d3fbd 100644 --- a/src/js/pages/SurahIndex.tsx +++ b/src/js/pages/SurahIndex.tsx @@ -4,7 +4,6 @@ import classNames from "classnames"; import * as Quran from "lib/Quran"; import { useTheme } from "hooks/useTheme"; -import { SelectOption } from "components/Select"; import { ThemeSelect } from "components/ThemeSelect"; import { LanguageSelect } from "components/LanguageSelect"; import { i18n, formatNumber, TFunction } from "lib/i18n"; @@ -17,9 +16,6 @@ interface Props { function SurahIndex({ locale, surahs, t }: Props) { const [theme, setTheme] = useTheme(); - const onLanguageChange = (o: SelectOption) => { - document.location.replace(`/${o.value}/`); - }; return (
@@ -28,7 +24,7 @@ function SurahIndex({ locale, surahs, t }: Props) {
- +
    {surahs.map((surah, key) => ( diff --git a/src/js/pages/SurahStream.tsx b/src/js/pages/SurahStream.tsx index bf86dd7..095d9a1 100644 --- a/src/js/pages/SurahStream.tsx +++ b/src/js/pages/SurahStream.tsx @@ -5,7 +5,6 @@ import classNames from "classnames"; import { useTheme } from "hooks/useTheme"; import { Timer } from "components/Timer"; import { Stream } from "components/Stream"; -import { SelectOption } from "components/Select"; import { ThemeSelect } from "components/ThemeSelect"; import { LanguageSelect } from "components/LanguageSelect"; import { AudioControl } from "components/AudioControl"; @@ -41,15 +40,6 @@ function SurahStream({ node, recitations, locale, paused, t }: Props) { const readyToRender = stream.length > 0; const ayah = stream[stream.length - 1]; const hasCompactLayout = ["ar"].includes(locale); - const onLanguageChange = (o: SelectOption) => { - const locale = o.value; - const params = [["paused", isPaused ? "t" : null]]; - const query = params - .filter(([, v]) => v) - .flatMap(([k, v]) => `${k}=${v}`) - .join("&"); - location.replace(`/${locale}/${surah.slug}/?${query}`); - }; useEffect(() => { setEndOfStream(false); @@ -68,7 +58,7 @@ function SurahStream({ node, recitations, locale, paused, t }: Props) { {hasCompactLayout && ( {surah.localizedName} )} - +
)}