Skip to content

Commit

Permalink
fix operative creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jaaimino committed Oct 30, 2024
1 parent 761eef4 commit ea63e19
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/hooks/use-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React from "react";
export const API_PATH = "https://ktdash.app/api";

export const request = (endpoint, content) => {
console.log('requesting', endpoint);
return fetch(`${API_PATH}${endpoint}`, {
credentials: "include",
method: "GET",
Expand Down
36 changes: 22 additions & 14 deletions src/pages/roster/modals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,30 @@ export function OperativeModal(props) {
}));
const hiddenKT24Equipment = new Set(['Equipment', 'Universal Equipment']);

const setRandomOperativeName = async (opData) => {
if (!opData) {
const getRandomOperativeName = (opData) => requestText(`/name.php?factionid=${opData.factionid}&killteamid=${opData.killteamid}&fireteamid=${opData.fireteamid}&opid=${opData.opid}`);

const setInitialOperativeData = async (opId) => {
setOperativeId(opId);
let newOpData = {
...operatives[opId],
weapons: [...operatives[opId].weapons.filter((weapon) => !!weapon.isdefault)]
};
if (settings.useoptypeasname !== "y") {
newOpData.opname = await getRandomOperativeName(newOpData);
}
setOperativeData(newOpData);
}

const randomizeOperativeName = async () => {
if (!operativeData) {
return;
}
const randomName = await requestText(`/name.php?factionid=${opData.factionid}&killteamid=${opData.killteamid}&fireteamid=${opData.fireteamid}&opid=${opData.opid}`);
console.log(randomName);

const randomName = await getRandomOperativeName(operativeData);

if (randomName) {
setOperativeData({
...opData,
...operativeData,
opname: randomName
})
}
Expand Down Expand Up @@ -214,20 +229,13 @@ export function OperativeModal(props) {
data={operativeOptions}
value={operativeId}
onChange={(operativeId) => {
setOperativeId(operativeId)
setOperativeData({
...operatives[operativeId],
weapons: []
});
if (settings.useoptypeasname !== "y") {
setRandomOperativeName(operatives[operativeId]);
}
setInitialOperativeData(operativeId);
}}
/>}
<TextInput
label="Operative Name"
placeholder="Operative Name"
rightSection={settings.useoptypeasname === "y" ? <></> : <ActionIcon onClick={() => setRandomOperativeName(operativeData)}><IconRefresh /></ActionIcon>}
rightSection={settings.useoptypeasname === "y" ? <></> : <ActionIcon onClick={() => randomizeOperativeName()}><IconRefresh /></ActionIcon>}
value={operativeData?.opname}
onChange={(e) => {
setOperativeData({
Expand Down

0 comments on commit ea63e19

Please sign in to comment.