summaryrefslogtreecommitdiff
path: root/packages/prosody-ui/src/fonts/useLangFont.tsx
blob: 36fa60372cd6789a2674e8f44021aca73b4d2977 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React, { useEffect, useState, type ReactNode } from "react";
import fontIcon from "../assets/icons/font.svg";
import { getScriptPredictor } from "glotscript";

function useLangFont({ text }: { text: string }) {
  useEffect(() => {
    const predictor = getScriptPredictor();
    const res = predictor(text);
    console.log("script predicted", res);
    setScript(res[0]);
  }, [text]);
  const [script, setScript] = useState<string | null>(null);
  const [fontIdx, setFont] = useState(0);
  const fontCount = 6;
  function changeFont() {
    if (fontIdx === fontCount) setFont(0);
    else setFont((prev) => prev + 1);
  }
  // if (script === "Hani") return {}
}
// function FontChanger({
//   lang,
//   children,
// }: {
//   lang: string;
//   children: ReactNode;
// }) {
//   useEffect(() => {}, []);
//   const [script, setScript] = useState("Latn");
//   const [fontIdx, setFont] = useState(0);
//   const fontCount = 6;
//   function changeFont() {
//     if (fontIdx === fontCount) setFont(0);
//     else setFont((prev) => prev + 1);
//   }
//   return (
//     <div className="font-changer" lang={script}>
//       <img className="font-icon cp" onClick={changeFont} src={fontIcon} />
//       {children}
//     </div>
//   );
// }

export default useLangFont;