l-min-components 1.0.814 → 1.0.820

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "l-min-components",
3
- "version": "1.0.814",
3
+ "version": "1.0.820",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -153,7 +153,7 @@ const AppMainLayout = () => {
153
153
  const currentPlan = userPlanData?.data?.current_plan;
154
154
  const planState = userPlanData?.data?.state;
155
155
 
156
- const { textSchema, setDefaultLang, defaultLang, findText } =
156
+ const { textSchema, setDefaultLang, defaultLang, findText, isLoading, setIsLoading } =
157
157
  useTranslation();
158
158
  // //console.log(findText());
159
159
  return (
@@ -164,6 +164,8 @@ const AppMainLayout = () => {
164
164
  findText,
165
165
  defaultLang,
166
166
  setDefaultLang,
167
+ isLoading,
168
+ setIsLoading,
167
169
  setRightComponent,
168
170
  setRightLayout,
169
171
  generalData,
@@ -25,8 +25,7 @@ const Banner = () => {
25
25
  {findText("Learn languages, anytime, anywhere.")}
26
26
  </BannerTitle>
27
27
  <BannerSubtitle>
28
- {findText(`Join millions of users from all over the world to learn foreign
29
- languages`)}
28
+ {findText(`Join millions of users from all over the world to learn foreign languages`)}
30
29
  </BannerSubtitle>
31
30
  <BannerImage src={BannerImg} alt="Banner" />
32
31
  <Button
@@ -23,7 +23,7 @@ import {
23
23
  CountryFlagGroup,
24
24
  } from "./index.styled";
25
25
  import useHeader from "./getHeaderDetails";
26
- import { OutletContext } from "..";
26
+ import { FullPageLoader, OutletContext } from "..";
27
27
  import { useLocation } from "react-router-dom";
28
28
  import usFlag from "../../assets/images/usFlag.png";
29
29
  import LanguageDropdown from "./languageDropdown";
@@ -67,6 +67,8 @@ const HeaderComponent = (props) => {
67
67
  notificationMarkReadData,
68
68
  findText,
69
69
  defaultLang,
70
+ isLoading,
71
+ setIsLoading,
70
72
  } = useContext(OutletContext);
71
73
  const [selectedAccount, setSelectedAccount] = useState();
72
74
  const { setDefaultAccount, handleSetDefaultAccount } = useHeader();
@@ -391,12 +393,15 @@ const HeaderComponent = (props) => {
391
393
 
392
394
  return (
393
395
  <Navbar>
396
+ {isLoading && <FullPageLoader hasBackground={true} />}
397
+
394
398
  <img src={logo} alt="Learngual logo" />
395
399
  <Nav
396
400
  onClick={() => {
397
401
  setLanguageDropdown();
398
402
  setIsOpen();
399
- }}>
403
+ }}
404
+ >
400
405
  <li>
401
406
  <a className={isHomePage() ? "active" : ""}>
402
407
  <BookIcon /> {getNavLinkLabel()}
@@ -421,7 +426,8 @@ const HeaderComponent = (props) => {
421
426
  className={
422
427
  window.location.pathname.includes("settings") ? "active" : ""
423
428
  }
424
- style={{ cursor: "pointer" }}>
429
+ style={{ cursor: "pointer" }}
430
+ >
425
431
  <SettingIcon /> {findText("Settings")}
426
432
  </a>
427
433
  </li>
@@ -435,7 +441,8 @@ const HeaderComponent = (props) => {
435
441
  className={
436
442
  window.location.pathname.includes("notifications") ? "active" : ""
437
443
  }
438
- style={{ cursor: "pointer" }}>
444
+ style={{ cursor: "pointer" }}
445
+ >
439
446
  {unreadNotificationData?.data?.count > 0 ? (
440
447
  <NotificationIcon />
441
448
  ) : (
@@ -450,7 +457,8 @@ const HeaderComponent = (props) => {
450
457
  onClick={() => {
451
458
  setLanguageDropdown();
452
459
  setIsOpen();
453
- }}>
460
+ }}
461
+ >
454
462
  {!isDeveloper && ( // when developer and on staging, don't show
455
463
  <SearchInputGroup>
456
464
  <SearchIcon />
@@ -479,7 +487,8 @@ const HeaderComponent = (props) => {
479
487
  onClick={() => {
480
488
  setLanguageDropdown(!languageDropdown);
481
489
  setIsOpen();
482
- }}>
490
+ }}
491
+ >
483
492
  <img src={currentFlag || usFlag} alt="" />
484
493
  <ArrowDownIcon />
485
494
  </div>
@@ -497,7 +506,8 @@ const HeaderComponent = (props) => {
497
506
  setIsOpen(!isOpen);
498
507
  setLanguageDropdown();
499
508
  }}
500
- ref={secondContainerRef}>
509
+ ref={secondContainerRef}
510
+ >
501
511
  <div className="user-img-container">
502
512
  <img
503
513
  src={selectedAccount?.profile_photo?.url || avatar}
@@ -21,8 +21,15 @@ import { DebounceInput } from "react-debounce-input";
21
21
  *
22
22
  */
23
23
  const LanguageDropdown = ({ languageDropdown, setLanguageDropdown }) => {
24
- const { setGeneralData, generalData, defaultLang, setDefaultLang, findText } =
25
- useContext(OutletContext);
24
+ const {
25
+ setGeneralData,
26
+ generalData,
27
+ defaultLang,
28
+ setDefaultLang,
29
+ findText,
30
+ isLoading,
31
+ setIsLoading,
32
+ } = useContext(OutletContext);
26
33
  const languagesData = [
27
34
  {
28
35
  name: "English",
@@ -104,12 +111,17 @@ const LanguageDropdown = ({ languageDropdown, setLanguageDropdown }) => {
104
111
  filteredData.length > 0 &&
105
112
  filteredData?.map((item, index) => (
106
113
  <p
114
+ key={index}
107
115
  className="language_dropdown_item"
108
116
  onClick={() => {
109
117
  setLanguageDropdown();
110
118
  setDefaultLang(item?.slug);
119
+ item?.slug === defaultLang
120
+ ? setIsLoading(false)
121
+ : setIsLoading(true);
111
122
  localStorage.setItem("defaultLang", JSON.stringify(item));
112
- }}>
123
+ }}
124
+ >
113
125
  <img src={item?.flag} alt="" /> <span>{item?.name}</span>
114
126
  </p>
115
127
  ))}
@@ -118,12 +130,17 @@ const LanguageDropdown = ({ languageDropdown, setLanguageDropdown }) => {
118
130
  <>
119
131
  {languagesData?.map((item, idx) => (
120
132
  <p
133
+ key={idx}
121
134
  className="language_dropdown_item"
122
135
  onClick={() => {
123
136
  setLanguageDropdown();
124
137
  setDefaultLang(item?.slug);
138
+ item?.slug === defaultLang
139
+ ? setIsLoading(false)
140
+ : setIsLoading(true);
125
141
  localStorage.setItem("defaultLang", JSON.stringify(item));
126
- }}>
142
+ }}
143
+ >
127
144
  <img src={item?.flag} alt="" />{" "}
128
145
  <span>{findText(`${item?.name}`)}</span>
129
146
  </p>
@@ -13,7 +13,7 @@ import ButtonComponent from "../button";
13
13
  import { useLocation, useNavigate } from "react-router-dom";
14
14
  import usFlag from "../../assets/images/usFlag.png";
15
15
  import koreanFlag from "../../assets/images/koreaFlag.png";
16
- import { OutletContext } from "..";
16
+ import { FullPageLoader, OutletContext } from "..";
17
17
  import useTranslation from "../../hooks/useTranslation";
18
18
 
19
19
  /**
@@ -88,6 +88,7 @@ const HeaderComponentTwo = (props) => {
88
88
  setLanguageDropdown();
89
89
  }}
90
90
  >
91
+ {props?.isLoading && <FullPageLoader hasBackground={true} />}
91
92
  <img src={logo} alt="Learngual logo" onClick={handleLogoClick} />
92
93
  {/* <Nav2>
93
94
  <li>
@@ -119,8 +120,13 @@ const HeaderComponentTwo = (props) => {
119
120
  <ul className="dropdown_list" ref={containerRef}>
120
121
  {languagesData?.map((item, idx) => (
121
122
  <li
123
+ key={idx}
122
124
  onClick={() => {
123
125
  setLanguageDropdown();
126
+ props.setIsLoading(true)
127
+ item?.slug === props?.defaultLang
128
+ ? props?.setIsLoading(false)
129
+ : props?.setIsLoading(true);
124
130
  props?.setDefaultLang(item?.slug);
125
131
  localStorage.setItem("defaultLang", JSON.stringify(item));
126
132
  }}
@@ -50,4 +50,4 @@ export { default as GraphMap } from './GraphMap';
50
50
  export { default as AdminRolesPermissions } from './AdminRolesPermission';
51
51
  export { default as AdminCreateRolesPermissions } from './AdminRolesPermission/create';
52
52
  export { default as MobileLayout } from './mobileLayout';
53
-
53
+ export { default as useTranslation } from '../hooks/useTranslation'
@@ -7,18 +7,16 @@ const useTranslation = () => {
7
7
  const screenId = btoa(window.location.href);
8
8
  const value = JSON?.parse(localStorage.getItem("defaultLang"));
9
9
 
10
- const [defaultLang, setDefaultLang] = useState(value?.slug ?? "en");
10
+ const [defaultLang, setDefaultLang] = useState(value?.slug);
11
+ const [isLoading, setIsLoading] = useState(false);
11
12
  /**
12
13
  * @type {{key: string; value: string; updatedAt: string; screenId: string}[]}
13
14
  */
14
15
  const textSchema = useLiveQuery(
15
16
  async () =>
16
- db[defaultLang.toLowerCase()]
17
- .where("screenId")
18
- .equals(screenId)
19
- .toArray(),
17
+ db[defaultLang?.toLowerCase()]?.toArray(),
20
18
  [defaultLang]
21
- );
19
+ ) ?? []
22
20
  const findText = useCallback(
23
21
  (str, kwarg = {}) => {
24
22
  // add text to db if not exist
@@ -37,13 +35,13 @@ const useTranslation = () => {
37
35
  (x, y) => ({ ...x, [y.key]: y.value }),
38
36
  {}
39
37
  );
40
- return schema[str] ?? str;
38
+ return schema[str];
41
39
  },
42
40
  [textSchema, defaultLang]
43
41
  );
44
42
 
45
43
  useEffect(() => {
46
- loadTranslations(defaultLang);
44
+ loadTranslations(defaultLang, setIsLoading);
47
45
  }, [defaultLang]);
48
46
 
49
47
  return {
@@ -52,6 +50,8 @@ const useTranslation = () => {
52
50
  setDefaultLang,
53
51
  defaultLang,
54
52
  findText,
53
+ isLoading,
54
+ setIsLoading
55
55
  };
56
56
  };
57
57
 
@@ -1,7 +1,7 @@
1
1
  import { db } from "./db";
2
2
  import axios from "./axiosConfig";
3
3
 
4
- async function loadTranslations(language = "ko") {
4
+ async function loadTranslations(language = "ko", setIsLoading) {
5
5
  await new Promise((resolve) => {
6
6
  //check if loading else resolve
7
7
  if (document.readyState === "complete") {
@@ -16,7 +16,7 @@ async function loadTranslations(language = "ko") {
16
16
  * @typedef {{text: string; screenId: string; updatedAt: string}} WORDS
17
17
  * @type {WORDS[]}
18
18
  */
19
- const words = await db.words.where({ screenId }).toArray();
19
+ const words = await db.words.toArray();
20
20
  const texts = words.map((x) => x.text); // list of texts
21
21
 
22
22
  /**
@@ -28,6 +28,8 @@ async function loadTranslations(language = "ko") {
28
28
  /**
29
29
  * @type {{ data: {has_translated: boolean; result: string[]} }}
30
30
  */
31
+
32
+ try {
31
33
  const res = await axios({
32
34
  url: "/iam/v1/utils/translate/",
33
35
  method: "POST",
@@ -54,6 +56,12 @@ async function loadTranslations(language = "ko") {
54
56
  );
55
57
 
56
58
  return translations;
59
+
60
+ } catch (error) {
61
+ console.error("clg Error fetching data:", error);
62
+ } finally {
63
+ setIsLoading(false);
64
+ }
57
65
  }
58
66
 
59
67
  export function extractBracedText(text) {