Skip to content

Commit

Permalink
Add roster reset
Browse files Browse the repository at this point in the history
  • Loading branch information
jaaimino committed Oct 29, 2024
1 parent dae2156 commit d8dc5b7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
53 changes: 51 additions & 2 deletions src/pages/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,55 @@ export default function Dashboard() {
const killteam = roster?.killteam;
const isNarrativeEquipment = (equip) => equip.eqid.includes('BS-') || equip.eqid.includes('BH-');
const groupedEquipment = groupBy(roster?.rostereqs?.filter(equip => !isNarrativeEquipment(equip)), 'eqcategory');
const handleResetDashboard = React.useCallback(() => {
const updatedRoster = {
"userid": userData.userid,
"rosterid": roster.rosterid,
"rostername": roster.rostername,
"factionid": roster.factionid,
"killteamid": roster.killteamid,
"seq": roster.seq,
"notes": roster.notes,
"CP": 2,
"TP": 1,
"VP": 2,
"RP": 0,
"ployids": "",
"portraitcopyok": roster.portraitcopyok,
"keyword": roster.keyword,
"reqpts": roster.reqpts,
"stratnotes": roster.stratnotes,
"eqnotes": roster.eqnotes,
"specopnotes": roster.specopnotes
};
setRoster({
...roster,
...updatedRoster,
operatives: roster.operatives.map((operative) => ({
...operative,
curW: operative.W
})),
ployids: ""
});
roster.operatives.forEach((op) => {
api.request(`/rosteroperative.php`, {
method: "POST",
body: JSON.stringify({
...op,
curW: op.W
})
})
})
api.request(`/roster.php`, {
method: "POST",
body: JSON.stringify(updatedRoster)
})
notifications.show({
title: 'Reset Dashboard',
message: `Dashboard successfully reset.`,
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [roster]);
const handleUpdateOperatives = React.useCallback((operatives) => {
const oldOperatives = keyBy(roster.operatives, 'rosteropid');
setRoster({
Expand Down Expand Up @@ -214,7 +263,7 @@ export default function Dashboard() {
{
icon: <IconRefresh />,
text: "Reset",
onClick: () => { }
onClick: () => handleResetDashboard()
}
] : [])
]
Expand All @@ -226,7 +275,7 @@ export default function Dashboard() {
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [canEdit, handleShowSelectOperatives]);
}, [canEdit, handleShowSelectOperatives, handleResetDashboard]);
if (isFetchinigTeam) {
return (<LoadingOverlay visible={isFetchinigTeam} />);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dashboard/modals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function MiniOperativeCard(props) {
const { operative, onChange = () => { } } = props;
const [settings] = useLocalStorage({ key: 'settings', defaultValue: DEFAULT_SETTINGS });
return (
<Paper withBorder p="sm" style={{ cursor: 'pointer' }} onClick={() => onChange(operative, !!operative.hidden)}>
<Paper withBorder p="sm" style={{ cursor: 'pointer', userSelect: 'none' }} onClick={() => onChange(operative, !!operative.hidden)}>
<Stack gap={5}>
<Group>
<Checkbox.Indicator checked={!operative.hidden} />
Expand Down

0 comments on commit d8dc5b7

Please sign in to comment.