diff --git a/components/vikings/SingleField/index.tsx b/components/vikings/SingleField/index.tsx
new file mode 100644
index 0000000..68b4090
--- /dev/null
+++ b/components/vikings/SingleField/index.tsx
@@ -0,0 +1,46 @@
+import styles from "../../../styles/SingleField.module.css";
+
+type Viking = {
+ fullName: string;
+ presenceOfChildren: boolean;
+ age: number;
+ hometown: string;
+ canFightWithSword: boolean;
+ canFightWithAxe: boolean;
+ canFightWithSpear: boolean;
+};
+
+function SingleField(props: { viking: Viking }): JSX.Element {
+ const {
+ fullName,
+ presenceOfChildren,
+ age,
+ hometown,
+ canFightWithSword,
+ canFightWithAxe,
+ canFightWithSpear,
+ } = props.viking;
+
+ return (
+
+ {fullName} |
+ {presenceOfChildren ? "Yes" : "No"} |
+ {age} |
+ {hometown} |
+
+ {" "}
+ {canFightWithSword || canFightWithAxe || canFightWithSpear ? (
+ <>
+ {canFightWithSword && "Sword"}
+ {canFightWithAxe && "Axe"}
+ {canFightWithSpear && "Spear"}
+ >
+ ) : (
+ "None"
+ )}
+ |
+
+ );
+}
+
+export default SingleField;
diff --git a/lib/vikings.ts b/lib/vikings.ts
new file mode 100644
index 0000000..b2abbb3
--- /dev/null
+++ b/lib/vikings.ts
@@ -0,0 +1,62 @@
+type yaml = {
+ name: string;
+ weapon: string;
+ name_of_father: string;
+ has_home_in: string;
+ years_old: number;
+ number_of_children: number;
+};
+type json = {
+ fullName: string;
+ village: string;
+ age: number;
+ valkyrie: string;
+ hasSon: boolean;
+};
+type Viking = {
+ fullName: string;
+ presenceOfChildren: boolean;
+ age: number;
+ hometown: string;
+ canFightWithSword: boolean;
+ canFightWithAxe: boolean;
+ canFightWithSpear: boolean;
+};
+
+function transformData(data: yaml | json): Viking {
+ if ("name" in data) {
+ return {
+ fullName: data.name + " " + data.name_of_father + "son",
+ presenceOfChildren: data.number_of_children > 0,
+ age: data.years_old,
+ hometown: data.has_home_in,
+ canFightWithSword: data.weapon === "sword",
+ canFightWithAxe: data.weapon === "axe",
+ canFightWithSpear: data.weapon === "spear",
+ };
+ } else {
+ return {
+ fullName: data.fullName,
+ presenceOfChildren: data.hasSon,
+ age: data.age,
+ hometown: data.village,
+ canFightWithSword: false,
+ canFightWithAxe: false,
+ canFightWithSpear: false,
+ };
+ }
+}
+
+function getValidVikings(vikings: Viking[]): Viking[] {
+ return vikings.filter((viking) => viking.age > 25 && viking.age < 65);
+}
+
+export default function ValidateMergeYamlJsonData(
+ yaml: [yaml],
+ json: Array
+) {
+ const datayaml = yaml.map((data: yaml) => transformData(data));
+ const datajson = json.map((data: json) => transformData(data));
+
+ return getValidVikings([...datajson, ...datayaml]);
+}
diff --git a/next.config.js b/next.config.js
index ae88795..a3f4713 100644
--- a/next.config.js
+++ b/next.config.js
@@ -2,6 +2,16 @@
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
-}
+};
-module.exports = nextConfig
+module.exports = {
+ nextConfig,
+ webpack: (config) => {
+ config.module.rules.push({
+ test: /\.yaml$/,
+ use: "js-yaml-loader",
+ });
+
+ return config;
+ },
+};
diff --git a/package.json b/package.json
index d1a5824..3739a10 100644
--- a/package.json
+++ b/package.json
@@ -14,9 +14,15 @@
"@types/react-dom": "18.0.9",
"eslint": "8.29.0",
"eslint-config-next": "13.0.6",
+ "js-yaml": "^4.1.0",
"next": "13.0.6",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "4.9.4"
+ },
+ "devDependencies": {
+ "@types/js-yaml": "^4.0.5",
+ "js-yaml-loader": "^1.2.2",
+ "yaml-loader": "^0.8.0"
}
}
diff --git a/pages/api/getVikings.tsx b/pages/api/getVikings.tsx
new file mode 100644
index 0000000..aa3f073
--- /dev/null
+++ b/pages/api/getVikings.tsx
@@ -0,0 +1,16 @@
+// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import ValidateMergeYamlJsonData from "../../lib/vikings";
+
+export default function getVikings(req: NextApiRequest, res: NextApiResponse) {
+ try {
+ res.status(200).json(ValidateMergeYamlJsonData);
+ } catch (err: unknown) {
+ if (typeof err === "string") {
+ res.status(500).json({ message: err });
+ } else {
+ res.status(500).json({ message: "An error occurred" });
+ }
+ }
+}
diff --git a/pages/index.tsx b/pages/index.tsx
index cdffa57..46f37b3 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -1,71 +1,20 @@
-import Head from 'next/head'
-import Image from 'next/image'
-import styles from '../styles/Home.module.css'
+import Head from "next/head";
+import styles from "../styles/Home.module.css";
+import Vikings from "./vikings";
+import getVikings from "./api/getVikings";
export default function Home() {
return (
-
Create Next App
+
Local Host
-
-
-
- Get started by editing{' '}
- pages/index.tsx
-
-
-
+
-
-
- )
+ );
}
diff --git a/pages/vikings/index.tsx b/pages/vikings/index.tsx
new file mode 100644
index 0000000..e5f8e44
--- /dev/null
+++ b/pages/vikings/index.tsx
@@ -0,0 +1,33 @@
+import styles from "../../styles/Vikings.module.css";
+import ValidateMergeYamlJsonData from "../../lib/vikings";
+import yamldata from "../../vikings.yaml";
+import jsondata from "../../vikings.json";
+import SingleField from "../../components/vikings/SingleField";
+const Vikings = () => {
+ const mapVikings = ValidateMergeYamlJsonData(yamldata, jsondata).map(
+ (viking, index) => {
+ return ;
+ }
+ );
+
+ return (
+
+
Załoga na najbliższą wyprawę do Anglii
+
W wyprawie wezmą tylko udział osoby między 25 a 65 rokiem życia
+
+
+
+ Full Name |
+ Has children |
+ Age |
+ HomeTown |
+ Weapon Fighting skills |
+
+ {mapVikings}
+
+
+
+ );
+};
+
+export default Vikings;
diff --git a/styles/Home.module.css b/styles/Home.module.css
index bd50f42..6144c81 100644
--- a/styles/Home.module.css
+++ b/styles/Home.module.css
@@ -1,129 +1,7 @@
-.container {
- padding: 0 2rem;
-}
-
.main {
min-height: 100vh;
- padding: 4rem 0;
- flex: 1;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
-}
-
-.footer {
- display: flex;
flex: 1;
- padding: 2rem 0;
- border-top: 1px solid #eaeaea;
- justify-content: center;
- align-items: center;
-}
-
-.footer a {
display: flex;
justify-content: center;
align-items: center;
- flex-grow: 1;
-}
-
-.title a {
- color: #0070f3;
- text-decoration: none;
-}
-
-.title a:hover,
-.title a:focus,
-.title a:active {
- text-decoration: underline;
-}
-
-.title {
- margin: 0;
- line-height: 1.15;
- font-size: 4rem;
-}
-
-.title,
-.description {
- text-align: center;
-}
-
-.description {
- margin: 4rem 0;
- line-height: 1.5;
- font-size: 1.5rem;
-}
-
-.code {
- background: #fafafa;
- border-radius: 5px;
- padding: 0.75rem;
- font-size: 1.1rem;
- font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
- Bitstream Vera Sans Mono, Courier New, monospace;
-}
-
-.grid {
- display: flex;
- align-items: center;
- justify-content: center;
- flex-wrap: wrap;
- max-width: 800px;
-}
-
-.card {
- margin: 1rem;
- padding: 1.5rem;
- text-align: left;
- color: inherit;
- text-decoration: none;
- border: 1px solid #eaeaea;
- border-radius: 10px;
- transition: color 0.15s ease, border-color 0.15s ease;
- max-width: 300px;
-}
-
-.card:hover,
-.card:focus,
-.card:active {
- color: #0070f3;
- border-color: #0070f3;
-}
-
-.card h2 {
- margin: 0 0 1rem 0;
- font-size: 1.5rem;
-}
-
-.card p {
- margin: 0;
- font-size: 1.25rem;
- line-height: 1.5;
-}
-
-.logo {
- height: 1em;
- margin-left: 0.5rem;
-}
-
-@media (max-width: 600px) {
- .grid {
- width: 100%;
- flex-direction: column;
- }
-}
-
-@media (prefers-color-scheme: dark) {
- .card,
- .footer {
- border-color: #222;
- }
- .code {
- background: #111;
- }
- .logo img {
- filter: invert(1);
- }
}
diff --git a/styles/SingleField.module.css b/styles/SingleField.module.css
new file mode 100644
index 0000000..a81c93b
--- /dev/null
+++ b/styles/SingleField.module.css
@@ -0,0 +1,12 @@
+.td {
+ border: 1px solid #ddd;
+ padding: 8px;
+ border-color: black;
+}
+.tr:nth-child(even) {
+ background-color: #f2f2f2;
+}
+
+.tr:hover {
+ background-color: #ddd;
+}
diff --git a/styles/Vikings.module.css b/styles/Vikings.module.css
new file mode 100644
index 0000000..b7df984
--- /dev/null
+++ b/styles/Vikings.module.css
@@ -0,0 +1,32 @@
+.main {
+ font-family: Arial, Helvetica, sans-serif;
+ border-collapse: collapse;
+ width: 100%;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+}
+
+.td,
+.th {
+ border: 1px solid #ddd;
+ padding: 8px;
+ border-color: black;
+}
+
+.tr:nth-child(even) {
+ background-color: #f2f2f2;
+}
+
+.tr:hover {
+ background-color: #ddd;
+}
+
+.th {
+ padding-top: 12px;
+ padding-bottom: 12px;
+ text-align: left;
+ background-color: #313131;
+ color: white;
+}
diff --git a/styles/globals.css b/styles/globals.css
index 4f18421..f6585da 100644
--- a/styles/globals.css
+++ b/styles/globals.css
@@ -20,7 +20,7 @@ a {
color-scheme: dark;
}
body {
- color: white;
- background: black;
+ color: black;
+ background: white;
}
}
diff --git a/tsconfig.json b/tsconfig.json
index 99710e8..e08d053 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -15,6 +15,6 @@
"jsx": "preserve",
"incremental": true
},
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "types.d.ts"],
"exclude": ["node_modules"]
}
diff --git a/types.d.ts b/types.d.ts
new file mode 100644
index 0000000..6383136
--- /dev/null
+++ b/types.d.ts
@@ -0,0 +1,4 @@
+declare module "*.yaml" {
+ const data: any;
+ export default data;
+}