diff --git a/src/hooks/useApi.js b/src/hooks/useApi.js new file mode 100644 index 0000000..8566d58 --- /dev/null +++ b/src/hooks/useApi.js @@ -0,0 +1,21 @@ +import axios from "axios"; +import { useState } from "react"; + +const useApi = () => { + const [data, setData] = useState(); + + const getFromApi = async (url) => { + await axios + .get(`${process.env.REACT_APP_API_URL}/${url}`) + .then((response) => { + return setData(response.data); + }) + .catch((error) => { + console.error("Error :", error); + }); + }; + + return { getFromApi, data }; +}; + +export default useApi; diff --git a/src/pages/Dev/index.js b/src/pages/Dev/index.js new file mode 100644 index 0000000..13b5b1c --- /dev/null +++ b/src/pages/Dev/index.js @@ -0,0 +1,196 @@ +import "./style.css"; + +import axios from "axios"; +import { useEffect, useState } from "react"; + +import Container from "../../layouts/Container"; +import jutsus from "../../data/jutsuData"; + +const Dev = () => { + const [data, setData] = useState(); + const [_foundryId, setFoundryId] = useState(); + const [name, setName] = useState(); + const [img, setImg] = useState(); + const [level, setLvl] = useState(); + const [element, setElem] = useState(); + const [description, setDesc] = useState(); + const [duration, setDuration] = useState(); + const [range, setRange] = useState(); + const [uses, setUses] = useState(); + const [chakraCost, setChakraCost] = useState(); + const [actionType, setActionType] = useState(); + const [criticalThreshold, setCritical] = useState(); + const [damages, setDamages] = useState(); + const [scaleFormula, setScaleFormula] = useState(); + const [statSave, setSave] = useState(); + const [concentration, setConcentration] = useState(); + const [scaling, setScaling] = useState(); + + useEffect(() => { + setFoundryId(data?.foundry_id); + setName(data?.name); + setImg(data?.img); + setLvl(data?.system ? data.system.level : data?.level); + setElem(); + setDesc(data?.system ? data.system.description.value : data?.description); + setDuration(data?.duration); + setRange(data?.range); + setUses(); + setChakraCost(); + setActionType(); + setCritical(); + setDamages(); + setScaleFormula(); + setSave(); + setConcentration(); + setScaling(); + }, [data]); + + // uses: { + // amount: Number, + // max: Number, + // type: { + // type: mongoose.Schema.Types.ObjectId, + // ref: "restType", + // }, + // }, + // chakraCost: Number, + // actionType: { + // type: mongoose.Schema.Types.ObjectId, + // ref: "actionType", + // }, + // criticalThreshold: String, + // damages: [String], + // scaleFormula: String, + // statSave: { + // targetAbility: { + // type: mongoose.Schema.Types.ObjectId, + // ref: "Ability", + // }, + // sourceAbility: { + // type: mongoose.Schema.Types.ObjectId, + // ref: "Ability", + // }, + // }, + // concentration: Boolean, + // scaling: { + // available: Boolean, + // formula: String, + // }, + // }) + const handlePost = (data) => { + // You need to modify the JSON so it appears to be the same as the MOdel in DB + + // const body = { + // _foundryId, + // name, + // img, + // level, + // element, + // description, + // duration : {units: duration.units, value: duration.value}, + // range, + // uses, + // chakraCost, + // actionType, + // criticalThreshold, + // damages, + // scaleFormula, + // statSave, + // concentration, + // scaling, + // }; + + axios + .post("http://localhost:8080/jutsu/new", data) + .then((response) => { + console.log("Post successful", response.data); + }) + .catch((error) => { + console.error("Error posting data:", error); + }); + }; + + const handleSaveData = () => { + localStorage.setItem("jutsuData", JSON.stringify(data)); + window.alert("data saved in locale storage"); + }; + + return ( + +
+ {jutsus?.map((el, id) => ( + + ))} +
+ +
+

id : {data?.foundry_id}

+

Item Name

+ + + { + setLvl(e.target.value); + }} + /> +
+ { + setDuration({ ...duration, value: e.target.value }); + }} + /> + { + setDuration({ ...duration, units: e.target.value }); + }} + /> +
+ { + setRange(e.target.value); + }} + /> +
+ + +
+ ); +}; + +export default Dev; diff --git a/src/pages/Dev/style.css b/src/pages/Dev/style.css new file mode 100644 index 0000000..50e5bc2 --- /dev/null +++ b/src/pages/Dev/style.css @@ -0,0 +1,22 @@ +.devDataPicker { + display: flex; + justify-content: space-between; + flex-wrap: wrap; + gap: 1rem; + margin-top: 1rem; +} + +.devDataPicker button { + width: 18rem; + border: none; + outline: 0; + background-color: var(--hanzo-gan); + color: white; + border-radius: 4px; +} + +.devEdit { + border: 1px solid black; + margin: 2rem; + padding: 0 2rem; +} \ No newline at end of file diff --git a/src/pages/Home/index.js b/src/pages/Home/index.js index 4b48505..8fca04d 100644 --- a/src/pages/Home/index.js +++ b/src/pages/Home/index.js @@ -1,7 +1,42 @@ import "./styles.css"; +import { useEffect } from "react"; + +import Container from "../../layouts/Container"; +import useApi from "../../hooks/useApi"; + const Home = () => { - return
home
; + const { data, getFromApi } = useApi(); + + useEffect(() => { + getFromApi("clan"); + }, [getFromApi]); + + if (!data) { + return ( +
+

Loading...

+
+ ); + } else { + return ( +
+ + {data?.map((el, id) => { + return ( +
+
+ {el.img && } +

{el.name}

+
+

{el.description}

+
+ ); + })} +
+
+ ); + } }; export default Home; diff --git a/src/pages/Home/styles.css b/src/pages/Home/styles.css index f8ab51b..767da28 100644 --- a/src/pages/Home/styles.css +++ b/src/pages/Home/styles.css @@ -1 +1,38 @@ -.home {} \ No newline at end of file +.home { + margin: 1rem 0; +} + +.home .container { + display: flex; + flex-direction: row; + flex-wrap: wrap; + gap: 1rem; +} + +.testCard { + flex: max(300px, 100% / 3 - 30px); + padding: 2rem; + max-width: 30rem; + background-color: var(--classy-base); + color: black; + border-radius: 10px; + margin-bottom: 10px; +} + +.testCard>* { + margin-bottom: 10px; +} + +.section>img { + border-radius: 10px; + object-fit: cover; +} + +.section { + display: flex; + flex-direction: row; + align-items: start; + justify-content: flex-start; + flex-wrap: wrap; + gap: 1rem; +} \ No newline at end of file