playground/src/pages/HOME_PAGE/index.tsx   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 0

Size

Lines of Code 133
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 107
mnd 4
bc 4
fnc 0
dl 0
loc 133
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import { useSelector } from "react-redux";
2
3
import { useHomePageTranslation } from "hooks/localization";
4
5
import { getPages } from "@cianciarusocataldo/modular-engine";
6
7
import {
8
  Card,
9
  CodeBox,
10
  Link,
11
  List,
12
  SupportedEnvironment,
13
} from "modular-ui-preview";
14
15
import AppLabel from "app/components/AppLabel";
16
import AppPage from "app/components/AppPage";
17
import RouterLink from "app/components/RouterLink";
18
19
const HomePage = () => {
20
  const t = useHomePageTranslation();
21
  const PATHS = useSelector(getPages);
22
23
  const PARSERS = {
24
    description: (localizedString: string) => {
25
      const splittedString = localizedString.split("#LINK");
26
      return (
27
        <div className="">
28
          {splittedString.map((part, index) => {
29
            if (index % 2 !== 0) {
30
              const splittedPart = part.split("#");
31
32
              return (
33
                <Link to={splittedPart[0]} key={`parsed_link_${index}`} newTab>
34
                  {splittedPart[1]}
35
                </Link>
36
              );
37
            } else {
38
              return <span key={`parsed_link_${index}`}>{part}</span>;
39
            }
40
          })}
41
        </div>
42
      );
43
    },
44
    installation: (localizedString: string) => {
45
      const splittedString = localizedString.split("#CODE");
46
      return (
47
        <div>
48
          {splittedString.map((part, index) => {
49
            if (index % 2 !== 0) {
50
              const splittedPart = part.split("#LANG");
51
52
              return (
53
                <div className="my-2" key={`parsed_code_${index}`}>
54
                  <CodeBox
55
                    environment={
56
                      splittedPart.length > 1
57
                        ? (splittedPart[1] as SupportedEnvironment)
58
                        : undefined
59
                    }
60
                    value={
61
                      splittedPart.length > 1
62
                        ? splittedPart[2]
63
                        : splittedPart[0]
64
                    }
65
                    enhanced
66
                    dark
67
                  />
68
                </div>
69
              );
70
            } else {
71
              return (
72
                <div className="my-2" key={`parsed_code_${index}`}>
73
                  {part}
74
                </div>
75
              );
76
            }
77
          })}
78
        </div>
79
      );
80
    },
81
  } as const;
82
83
  const description = PARSERS.description(t("description"));
84
  const installationGuide = PARSERS.installation(
85
    t("installation", { context: "body" })
86
  );
87
88
  return (
89
    <AppPage>
90
      <AppLabel
91
        key="homepage_header"
92
        className="text-4xl mt-12 mb-5 ml-3"
93
        value={t("title")}
94
      />
95
96
      <div key="homepage_container" className="flex flex-col lg:flex-row">
97
        <div>
98
          <Card shadow body={description} />
99
          <Card
100
            shadow
101
            label={<AppLabel value={t("installation", { context: "title" })} />}
102
            body={installationGuide}
103
          />
104
        </div>
105
        <Card
106
          shadow
107
          header={t("componentsList_header")}
108
          body={
109
            <List
110
              elements={Object.keys(PATHS)
111
                .sort()
112
                .map((routeKey, index) => {
113
                  return (
114
                    <div key={`link_${index}`}>
115
                      <RouterLink
116
                        className="text-gray-700 hover:text-blue-700 py-1 text-lg"
117
                        to={PATHS[routeKey]}
118
                      >
119
                        {routeKey}
120
                      </RouterLink>
121
                    </div>
122
                  );
123
                })}
124
            ></List>
125
          }
126
        />
127
      </div>
128
    </AppPage>
129
  );
130
};
131
132
export default HomePage;
133