Skip to content

Commit 6795bae

Browse files
committed
Fix server state not being updated correctly when adding/removing allocation; closes pterodactyl#2680
1 parent 74e90e0 commit 6795bae

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
66
## v1.1.1
77
### Fixed
88
* Fixes allocation permissions checking on the frontend checking the wrong permission therefore leading to the item never showing up.
9+
* Fixes allocations not updating correctly when added or deleted and switching between pages.
910

1011
## v1.1.0
1112
This release **requires** `Wings@1.1.0` in order to work properly due to breaking internal API changes.

resources/scripts/components/server/network/DeleteAllocationButton.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@ interface Props {
1313
}
1414

1515
const DeleteAllocationButton = ({ allocation }: Props) => {
16-
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
1716
const [ confirm, setConfirm ] = useState(false);
17+
18+
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
19+
const setServerFromState = ServerContext.useStoreActions(actions => actions.server.setServerFromState);
20+
1821
const { mutate } = getServerAllocations();
1922
const { clearFlashes, clearAndAddHttpError } = useFlash();
2023

2124
const deleteAllocation = () => {
2225
clearFlashes('server:network');
2326

2427
mutate(data => data?.filter(a => a.id !== allocation), false);
28+
setServerFromState(s => ({ ...s, allocations: s.allocations.filter(a => a.id !== allocation) }));
29+
2530
deleteServerAllocation(uuid, allocation)
2631
.catch(error => clearAndAddHttpError({ key: 'server:network', error }));
2732
};

resources/scripts/components/server/network/NetworkContainer.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const NetworkContainer = () => {
1919
const allocationLimit = ServerContext.useStoreState(state => state.server.data!.featureLimits.allocations);
2020
// @ts-ignore
2121
const allocations: Allocation[] = ServerContext.useStoreState(state => state.server.data!.allocations, isEqual);
22+
const setServerFromState = ServerContext.useStoreActions(actions => actions.server.setServerFromState);
2223

2324
const { clearFlashes, clearAndAddHttpError } = useFlash();
2425
const { data, error, mutate } = getServerAllocations();
@@ -38,7 +39,10 @@ const NetworkContainer = () => {
3839

3940
setLoading(true);
4041
createServerAllocation(uuid)
41-
.then(allocation => mutate(data?.concat(allocation), false))
42+
.then(allocation => {
43+
setServerFromState(s => ({ ...s, allocations: s.allocations.concat(allocation) }));
44+
return mutate(data?.concat(allocation), false);
45+
})
4246
.catch(error => clearAndAddHttpError({ key: 'server:network', error }))
4347
.then(() => setLoading(false));
4448
};

0 commit comments

Comments
 (0)