Skip to content

Commit

Permalink
got carried away and wrote some skill stuff including a classSkill ge…
Browse files Browse the repository at this point in the history
…neration form
  • Loading branch information
Dervalanana committed Dec 16, 2021
1 parent a2d6fee commit e7ce458
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 23 deletions.
19 changes: 19 additions & 0 deletions database.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"posts": [
{
"id": 1,
"title": "json-server",
"author": "typicode"
}
],
"comments": [
{
"id": 1,
"body": "some comment",
"postId": 1
}
],
"profile": {
"name": "typicode"
}
}
2 changes: 1 addition & 1 deletion src/components/Landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Route } from "react-router-dom";

export const Landing = () => {
return <>
<Route exact path="/" >
<Route exact path="/:characterId(/d+)" >
<br />
<br />
<br />
Expand Down
5 changes: 5 additions & 0 deletions src/components/SkillRoutes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react"
import { Route } from "react-router-dom"
import { ClassSkillGenerator } from "./skills/ClassSkillGenerator"
import { Skills } from "./skills/Skills"

export const SkillRoutes = () => {
Expand All @@ -8,5 +9,9 @@ export const SkillRoutes = () => {
<h1>you found the hidden text! zomg</h1>
<Skills />
</Route>
<Route exact path="/classSkillGenerator">
<h1>spacing</h1>
<ClassSkillGenerator />
</Route>
</>
}
7 changes: 4 additions & 3 deletions src/components/characters/Character.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export const Character = () => {
complicateCharacter(document.querySelector(`[name=characterSelect]`).value)
}
const deleteCharacter = () => {
CharacterRepository.delete(document.querySelector(`[name=characterDelete]`).value).then(() => {
document.querySelector(`[name=characterDelete]`).value !== characterId ? //throws a big error if it can't find anything
history.push(`/${document.querySelector(`[name=characterDelete]`).value}/character`) :
const holder = document.querySelector(`[name=characterDelete]`).value
CharacterRepository.delete(parseInt(holder)).then(() => {
holder !== characterId ? //throws a big error if it can't find anything
history.push(`/${characterId}/character`) :
history.push("/character")
syncCharacters()
})
Expand Down
7 changes: 6 additions & 1 deletion src/components/skills/CharacterSelect.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ section, h3{
.flexsidescroll{
display: flex;
overflow-x: scroll;
}
}
.detailColumn1{width:8rem}
.detailColumn2{width:3rem}
.detailColumn3{width:3rem}
.detailColumn4{width:3rem}
.detailColumn5{width:3rem}
30 changes: 30 additions & 0 deletions src/components/skills/ClassSkillGenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import react, { useState, useEffect } from "react";
import SkillsRepository from "../../repositories/SkillsRepository";

export const ClassSkillGenerator = () => {
const[skills, setSkills] = useState([])
useEffect(()=>{SkillsRepository.getAll().then(setSkills)},[])
const createClassSkills = () => {
skills.forEach(skill=> {
const classSkill = {
classId: (parseInt(document.querySelector(`[name=classId]`).value)),
skillId: skill.id,
classSkillProf: (document.querySelector(`[name=skill--${skill.id}]`).checked),
}
SkillsRepository.addClassSkills(classSkill)
})
}


return <>
<h1>1</h1>
<h1>1</h1>
<input name="classId" />
{skills.map(skill=>{
return <div>
{skill.name}<input name={`skill--${skill.id}`} type="checkbox"/>
</div>
})}
<button onClick={createClassSkills}>Submit</button>
</>
}
14 changes: 14 additions & 0 deletions src/components/skills/SkillDetails.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import react from "react";

export const SkillDetails = ({skill}) => {
return <>
<div className="flexside">
<div className="detailColumn1">{skill.name}</div>
<div className="detailColumn2">Total</div>
<div className="detailColumn3">{skill.attribute}</div>
<div className="detailColumn4">Ranks</div>
<div className="detailColumn5">Max Ranks</div>
</div>
</>

}
52 changes: 34 additions & 18 deletions src/components/skills/Skills.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,62 @@
import react from "react";
import react, { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import { SkillDetails } from "./SkillDetails"
import SkillsRepository from "../../repositories/SkillsRepository";
import LevelRepository from "../../repositories/LevelRepository";
import "./CharacterSelect.css"

export const Skills = () => {
const [skills, setSkills] = useState([])
const { characterId } = useParams()
const [levels, setLevels] = useState([])



useEffect(() => {
SkillsRepository.getAll().then(setSkills)
LevelRepository.getComplicated(characterId).then(setLevels)
}, [])

return (
<>
<article>
<h1>Skills</h1>
<h2>Currently Selected character is {"placeholder to call a reference to the current character. should be changed through filepath"}</h2>
<section className="flexside">
<section className="flexdown">
<h3>Level <br/> Row</h3>
<h3>Available <br/>skill <br/>points</h3>
<h3>Level <br /> Row</h3>
<h3>Available <br />skill <br />points</h3>
<div className="flexside">
<h3>Skill name</h3>
<h3>Total</h3>
<h3>Stat</h3>
<h3>Ranks</h3>
<h3>Max Ranks</h3>
<div className="detailColumn1">Skill name</div>
<div className="detailColumn2">Total</div>
<div className="detailColumn3">Stat</div>
<div className="detailColumn4">Ranks</div>
<div className="detailColumn5">Max Ranks</div>
</div>
<div className="flexdown">
{skills.map(skill => <SkillDetails skill={skill} />)}
</div>
</section>
<section className="flexsidescroll">
<div className="flexdown">
<h3>Level<br/>#</h3>
<h3>Skill points <br/>with <br/>live updates</h3>
<h3>double space <br/>for consistency</h3>
<h3>Level<br />#</h3>
<h3>Skill points <br />with <br />live updates</h3>
<h3>double space <br />for consistency</h3>
<h3>Column of skills. All 3 of these are going to be in an indiviudal element that will map through vertically, then that element will be mapped horizonally for multiple levels</h3>
</div>
<div className="flexdown">
<h3>Level<br/>#</h3>
<h3>Skill points <br/>with <br/>live updates</h3>
<h3>double space <br/>for consistency</h3>
<h3>Level<br />#</h3>
<h3>Skill points <br />with <br />live updates</h3>
<h3>double space <br />for consistency</h3>
<h3>Column of skills. All 3 of these are going to be in an indiviudal element that will map through vertically, then that element will be mapped horizonally for multiple levels</h3>
</div>
<div className="flexdown">
<h3>Level<br/>#</h3>
<h3>Skill points <br/>with <br/>live updates</h3>
<h3>double space <br/>for consistency</h3>
<h3>Level<br />#</h3>
<h3>Skill points <br />with <br />live updates</h3>
<h3>double space <br />for consistency</h3>
<h3>Column of skills. All 3 of these are going to be in an indiviudal element that will map through vertically, then that element will be mapped horizonally for multiple levels</h3>
</div>

</section>

</section>
Expand Down
16 changes: 16 additions & 0 deletions src/repositories/LevelRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import SkillsRepository from "./SkillsRepository"
// return animal
// }

const expandClassSkills = ( level, classSkills ) => {
classSkills = classSkills.sort((a,b) => a.skillId - b.skillId) //need to make sure that the array is in skill order for future iteration
level.class.classSkills = classSkills
return level
}

const addComplications = (level) => {
SkillsRepository.getAll().then(res => {
const skills = res
Expand Down Expand Up @@ -83,7 +89,17 @@ export default {
"PUT",
JSON.stringify(updatedLevel)
)
},
async getComplicated(id) {

return await fetchIt(`${Settings.remoteURL}/levels?characterId=${id}&_embed=levelSkills&_expand=class`)
.then(levels => {
levels.forEach(level => {
SkillsRepository.getClassSkills(level.classId).then(classSkills => expandClassSkills(level, classSkills))})
return levels
})
}

// async addAnimalCaretaker(newAnimalCaretaker) { //added function to add caretakers
// return await fetchIt(
// `${Settings.remoteURL}/animalCaretakers`,
Expand Down
10 changes: 10 additions & 0 deletions src/repositories/SkillsRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ export default {
JSON.stringify(levelSkill)
)
},
async addClassSkills(classSkill) {
return await fetchIt(
`${Settings.remoteURL}/classSkills`,
"POST",
JSON.stringify(classSkill)
)
},
async getClassSkills(id){
return await fetchIt(`${Settings.remoteURL}/classSkills?classId=${id}`)
}


// async addAnimalCaretaker(newAnimalCaretaker) { //added function to add caretakers
Expand Down

0 comments on commit e7ce458

Please sign in to comment.