Update loaders

This commit is contained in:
0x1eef 2024-10-02 00:10:59 -03:00
parent b829068bd5
commit 8518b5f491
3 changed files with 20 additions and 25 deletions

View file

@ -18,11 +18,18 @@ export function T(phrases: PhraseMap<string>): TFunction {
} }
export function formatNumber( export function formatNumber(
locale: TLocale, locale: TLocale | string,
num: number, num: number,
options = {}, options = {},
): string { ): string {
const numl = locale.name === "ar" ? "ar-SA" : locale.name; const name = (() => {
if (typeof locale === "string") {
return locale;
} else {
return locale.name;
}
})();
const numl = name === "ar" ? "ar-SA" : name;
return new Intl.NumberFormat(numl, { return new Intl.NumberFormat(numl, {
maximumFractionDigits: 1, maximumFractionDigits: 1,
...options, ...options,

View file

@ -3,20 +3,13 @@ import { formatNumber } from "~/lib/t";
(function () { (function () {
const doc = document.documentElement; const doc = document.documentElement;
const rev = doc
.querySelector("meta[name='revision']")!
.getAttribute("content")!;
const locale = {
name: doc.lang,
direction: doc.dir as "rtl" | "ltr",
displayName: "",
};
/* Postman */
const loader: HTMLElement = doc.querySelector(".postman.loader")!; const loader: HTMLElement = doc.querySelector(".postman.loader")!;
const style: HTMLStyleElement = doc.querySelector(".css.postman")!; const style: HTMLStyleElement = doc.querySelector(".css.postman")!;
const progressBar: HTMLProgressElement = loader.querySelector("progress")!; const progressBar: HTMLProgressElement = loader.querySelector("progress")!;
const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!; const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!;
const rev = doc
.querySelector("meta[name='revision']")!
.getAttribute("content")!;
const fonts = (() => { const fonts = (() => {
if (doc.dir === "rtl") { if (doc.dir === "rtl") {
return [ return [
@ -27,6 +20,7 @@ import { formatNumber } from "~/lib/t";
return [item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)")]; return [item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)")];
} }
})(); })();
postman( postman(
item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }), item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }),
item.script(`/js/main/surah-index.js?v=${rev}`, { id: "1" }), item.script(`/js/main/surah-index.js?v=${rev}`, { id: "1" }),
@ -34,7 +28,7 @@ import { formatNumber } from "~/lib/t";
item.progress((percent: number) => { item.progress((percent: number) => {
progressBar.value = percent; progressBar.value = percent;
progressNumber.innerText = formatNumber( progressNumber.innerText = formatNumber(
locale, doc.lang,
Number(percent.toFixed(0)), Number(percent.toFixed(0)),
); );
}), }),

View file

@ -3,21 +3,14 @@ import { formatNumber } from "~/lib/t";
(function () { (function () {
const doc = document.documentElement; const doc = document.documentElement;
const rev = doc
.querySelector("meta[name='revision']")!
.getAttribute("content")!;
const { surahId } = document.querySelector<HTMLElement>(".root")!.dataset;
const locale = {
name: doc.lang,
direction: doc.dir as "rtl" | "ltr",
displayName: "",
};
/* Postman */
const loader = doc.querySelector(".postman.loader")!; const loader = doc.querySelector(".postman.loader")!;
const style = doc.querySelector(".css.postman")!; const style = doc.querySelector(".css.postman")!;
const progressBar = loader.querySelector("progress")!; const progressBar = loader.querySelector("progress")!;
const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!; const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!;
const { surahId } = document.querySelector<HTMLElement>(".root")!.dataset;
const rev = doc
.querySelector("meta[name='revision']")!
.getAttribute("content")!;
const fonts = (() => { const fonts = (() => {
if (doc.dir === "rtl") { if (doc.dir === "rtl") {
return [ return [
@ -29,6 +22,7 @@ import { formatNumber } from "~/lib/t";
return [item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)")]; return [item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)")];
} }
})(); })();
postman( postman(
item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }), item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }),
item.script(`/js/main/surah-stream.js?v=${rev}`, { id: "1" }), item.script(`/js/main/surah-stream.js?v=${rev}`, { id: "1" }),
@ -41,7 +35,7 @@ import { formatNumber } from "~/lib/t";
item.progress((percent: number) => { item.progress((percent: number) => {
progressBar.value = percent; progressBar.value = percent;
progressNumber.innerText = formatNumber( progressNumber.innerText = formatNumber(
locale, doc.lang,
Number(percent.toFixed(0)), Number(percent.toFixed(0)),
); );
}), }),