Replace noise-y generic types

This commit is contained in:
0x1eef 2024-05-01 08:07:00 -03:00
parent 644b19b8d4
commit d62e34dd3e
9 changed files with 31 additions and 31 deletions

View file

@ -1,8 +1,8 @@
type TLocale = "ar" | "en";
type TAyat = Ayah<TAyah>[];
type TAyat = Ayah[];
type TQuran = {
locale: TLocale;
surahs: Surah<TSurah>[];
surahs: Surah[];
}
type TSurah = {
readonly id: number;
@ -16,17 +16,17 @@ type TAyah = {
body: string;
}
class Quran<T extends TQuran> {
class Quran {
locale: TLocale;
surahs: Surah<TSurah>[];
surahs: Surah[];
constructor(self: T) {
constructor(self: TQuran) {
this.locale = self.locale;
this.surahs = self.surahs;
}
}
class Surah<T extends TSurah> {
class Surah {
readonly id: number;
readonly name: string;
readonly numberOfAyah: number;
@ -34,7 +34,7 @@ class Surah<T extends TSurah> {
readonly utf8: { codepoints: number[] };
readonly ayat: TAyat
constructor(self: T) {
constructor(self: TSurah) {
this.id = self.id;
this.name = self.name;
this.numberOfAyah = self.numberOfAyah;
@ -53,12 +53,12 @@ class Surah<T extends TSurah> {
}
}
class Ayah<T extends TAyah> {
class Ayah {
readonly id: number;
readonly body: string;
ms: number;
constructor(self: T) {
constructor(self: TAyah) {
this.id = self.id;
this.body = self.body;
this.ms = 0;

View file

@ -1,5 +1,5 @@
import type { Surah, TSurah, Ayah, TAyah } from "Quran";
import React, { useEffect, useMemo, useState } from "react";
import React, { useEffect, useState } from "react";
import type { Surah, Ayah } from "Quran";
import { SoundOnIcon, SoundOffIcon } from "~/components/Icon";
export type TAudioStatus = "play" | "pause" | "wait" | "end";
@ -8,8 +8,8 @@ type Maybe<T> = T | null | undefined;
type TChangeFuncs = [() => void, () => void];
type Props = {
audio: HTMLAudioElement;
surah: Surah<TSurah>;
ayah: Maybe<Ayah<TAyah>>;
surah: Surah;
ayah: Maybe<Ayah>;
hidden?: boolean;
onStatusChange?: (s: TAudioStatus, fns: TChangeFuncs) => void;
};

View file

@ -1,11 +1,11 @@
import React, { useEffect, useMemo, useRef } from "react";
import { Surah, Ayah, TAyah, TAyat, TSurah, TLocale } from "Quran";
import type { Surah, Ayah, TAyat, TLocale } from "Quran";
import { AudioControl } from "~/components/AudioControl";
import { formatNumber, TFunction } from "~/lib/t";
import classNames from "classnames";
type Props = {
surah: Surah<TSurah>;
surah: Surah;
stream: TAyat;
locale: TLocale;
endOfStream: boolean;
@ -35,7 +35,7 @@ export function Stream({
)}
ref={ref}
>
{stream.map((ayah: Ayah<TAyah>) => {
{stream.map((ayah: Ayah) => {
return (
<li
key={ayah.id}

View file

@ -1,12 +1,12 @@
import React from "react";
import { TFunction } from "~/lib/t";
import type { TLocale, TSurah, Surah } from "Quran";
import type { Surah, TLocale } from "Quran";
type Props = {
t: TFunction;
locale: TLocale;
setIndex: (k: Surah<TSurah>[]) => void;
surahs: Surah<TSurah>[];
setIndex: (k: Surah[]) => void;
surahs: Surah[];
};
export function Filter({ t, locale, setIndex, surahs }: Props) {

View file

@ -1,5 +1,5 @@
import React, { useRef, useState, useEffect } from "react";
import { TLocale, TSurah, Surah } from "Quran";
import type { Surah, TLocale } from "Quran";
import { useTheme } from "~/hooks/useTheme";
import { formatNumber, TFunction } from "~/lib/t";
import { RightArrow } from "~/components/Icon";
@ -9,13 +9,13 @@ import classNames from "classnames";
type Props = {
locale: TLocale;
surahs: Surah<TSurah>[];
surahs: Surah[];
t: TFunction;
};
export function SurahIndex({ locale, surahs, t }: Props) {
const [theme, setTheme] = useTheme();
const [index, setIndex] = useState<Surah<TSurah>[]>(surahs);
const [index, setIndex] = useState<Surah[]>(surahs);
const ref = useRef<HTMLDivElement>();
const ltr = locale === "en";

View file

@ -1,6 +1,6 @@
import React, { useState, useEffect, useMemo, useRef } from "react";
import classNames from "classnames";
import { Surah, Ayah, TAyah, TSurah, TAyat, TLocale } from "Quran";
import type { Surah, Ayah, TAyat, TLocale } from "Quran";
import { useTheme } from "~/hooks/useTheme";
import { Timer } from "~/components/Timer";
import { Stream } from "~/components/Stream";
@ -17,7 +17,7 @@ import { TFunction } from "~/lib/t";
type Maybe<T> = T | null | undefined;
type Props = {
surah: Surah<TSurah>;
surah: Surah;
locale: TLocale;
t: TFunction;
};
@ -32,7 +32,7 @@ export function SurahStream({ surah, locale, t }: Props) {
const ref = useRef<HTMLDivElement>();
const audio = useMemo(() => new Audio(), []);
const readyToRender = stream.length > 0;
const ayah: Maybe<Ayah<TAyah>> = stream[stream.length - 1];
const ayah: Maybe<Ayah> = stream[stream.length - 1];
useEffect(() => {
if (ref.current) {

View file

@ -1,11 +1,11 @@
import React, { useEffect } from "react";
import { Surah, Ayah, TAyah, TSurah, TLocale, TAyat } from "Quran";
import type { Surah, Ayah, TLocale, TAyat } from "Quran";
import { formatNumber } from "~/lib/t";
type Maybe<T> = T | null | undefined;
type Props = {
surah: Surah<TSurah>;
surah: Surah;
locale: TLocale;
stream: TAyat;
setStream: (stream: TAyat) => void;
@ -27,8 +27,8 @@ export function Timer({
ms,
setMs,
}: Props) {
const ayah: Maybe<Ayah<TAyah>> = stream[stream.length - 1];
const lastAyah: Maybe<Ayah<TAyah>> = surah.ayat[surah.ayat.length - 1];
const ayah: Maybe<Ayah> = stream[stream.length - 1];
const lastAyah: Maybe<Ayah> = surah.ayat[surah.ayat.length - 1];
useEffect(() => {
if (!ayah) {

View file

@ -8,7 +8,7 @@ import { SurahIndex } from "~/components/SurahIndex";
const root: HTMLElement = document.querySelector(".root")!;
const locale = root.getAttribute("data-locale") as TLocale;
const t = T(require("@json/t.json"));
const surahs: Surah<TSurah>[] = require("@json/surahs").map(
const surahs: Surah[] = require("@json/surahs").map(
(e: TSurah) => new Surah(e),
);
ReactDOM.createRoot(root).render(

View file

@ -23,7 +23,7 @@ import { SurahStream } from "~/components/SurahStream";
}
for (let i = 0; i < surah.ayat.length; i++) {
const ayah = surah.ayat[i];
const [_, ms] = blob2[i];
const [, ms] = blob2[i];
ayah.ms = ms * 1000;
}