Skip to content

Commit

Permalink
Refactor: update all cache removals
Browse files Browse the repository at this point in the history
  • Loading branch information
emielvanseveren committed Jul 20, 2024
1 parent b9bc4d8 commit 8370091
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 56 deletions.
2 changes: 1 addition & 1 deletion packages/web-main/src/components/CopyModuleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const CopyModuleForm: FC<CopyModuleFormProps> = ({ moduleId, onSuccess })
onSuccess && onSuccess(createdModule.id);
}
} catch (error) {
await removeModule({ id: createdModule.id });
await removeModule({ moduleId: createdModule.id });
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const GameServerCard: FC<GameServerOutputDTO> = ({ id, name, type, reacha
};

const handleOnDelete = () => {
mutate({ id });
mutate({ gameServerId: id });
};

const handleOnCopyClick = (e: MouseEvent) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const ModuleDefinitionCard: FC<IModuleCardProps> = ({ mod }) => {

const handleOnDelete = async (e: MouseEvent) => {
e.stopPropagation();
await mutateAsync({ id: mod.id });
await mutateAsync({ moduleId: mod.id });
setOpenDeleteDialog(false);
};

Expand Down
17 changes: 8 additions & 9 deletions packages/web-main/src/queries/gameserver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
GameServerTestReachabilityDTOAPI,
GameServerTestReachabilityInputDTOTypeEnum,
GameServerUpdateDTO,
IdUuidDTO,
IdUuidDTOAPI,
ImportOutputDTO,
KickPlayerInputDTO,
ModuleInstallationOutputDTO,
Expand Down Expand Up @@ -132,25 +130,26 @@ export const useGameServerUpdate = () => {
};

interface GameServerRemove {
id: string;
gameServerId: string;
}

export const useGameServerRemove = () => {
const apiClient = getApiClient();
const queryClient = useQueryClient();

return mutationWrapper<IdUuidDTO, GameServerRemove>(
useMutation<IdUuidDTO, AxiosError<IdUuidDTOAPI>, GameServerRemove>({
mutationFn: async ({ id }) => (await apiClient.gameserver.gameServerControllerRemove(id)).data.data,
onSuccess: async (removedGameServer: IdUuidDTO) => {
return mutationWrapper<APIOutput, GameServerRemove>(
useMutation<APIOutput, AxiosError<APIOutput>, GameServerRemove>({
mutationFn: async ({ gameServerId }) =>
(await apiClient.gameserver.gameServerControllerRemove(gameServerId)).data,
onSuccess: async (_, { gameServerId }) => {
// remove all cached information of game server list.
await queryClient.invalidateQueries({ queryKey: gameServerKeys.list() });
// remove all cached information about specific game server.
await queryClient.invalidateQueries({
queryKey: gameServerKeys.detail(removedGameServer.id),
queryKey: gameServerKeys.detail(gameServerId),
});
queryClient.removeQueries({
queryKey: gameServerKeys.reachability(removedGameServer.id),
queryKey: gameServerKeys.reachability(gameServerId),
});
},
}),
Expand Down
39 changes: 19 additions & 20 deletions packages/web-main/src/queries/module.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMutation, useQueryClient, queryOptions, infiniteQueryOptions } from '@tanstack/react-query';
import { getApiClient } from 'util/getApiClient';
import {
APIOutput,
BuiltinModule,
CommandCreateDTO,
CommandOutputDTO,
Expand All @@ -18,8 +19,6 @@ import {
HookOutputDTO,
HookOutputDTOAPI,
HookUpdateDTO,
IdUuidDTO,
IdUuidDTOAPI,
ModuleCreateDTO,
ModuleExportDTOAPI,
ModuleOutputArrayDTOAPI,
Expand Down Expand Up @@ -124,9 +123,9 @@ export const useModuleRemove = () => {
const apiClient = getApiClient();
const queryClient = useQueryClient();

return mutationWrapper<IdUuidDTO, ModuleRemove>(
useMutation<IdUuidDTO, AxiosError<IdUuidDTOAPI>, ModuleRemove>({
mutationFn: async ({ moduleId }) => (await apiClient.module.moduleControllerRemove(moduleId)).data.data,
return mutationWrapper<APIOutput, ModuleRemove>(
useMutation<APIOutput, AxiosError<APIOutput>, ModuleRemove>({
mutationFn: async ({ moduleId }) => (await apiClient.module.moduleControllerRemove(moduleId)).data,
onSuccess: async (_, { moduleId }) => {
await queryClient.invalidateQueries({ queryKey: moduleKeys.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.detail(moduleId) });
Expand Down Expand Up @@ -224,10 +223,10 @@ export const useHookRemove = ({ moduleId }) => {
const apiClient = getApiClient();
const queryClient = useQueryClient();

return mutationWrapper<IdUuidDTO, HookRemove>(
useMutation<IdUuidDTO, AxiosError<IdUuidDTOAPI>, HookRemove>({
mutationFn: async ({ hookId }) => (await apiClient.hook.hookControllerRemove(hookId)).data.data,
onSuccess: async (removedHook: IdUuidDTO) => {
return mutationWrapper<APIOutput, HookRemove>(
useMutation<APIOutput, AxiosError<APIOutput>, HookRemove>({
mutationFn: async ({ hookId }) => (await apiClient.hook.hookControllerRemove(hookId)).data,
onSuccess: async (_, { hookId }) => {
await queryClient.invalidateQueries({ queryKey: moduleKeys.hooks.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.export(moduleId) });
queryClient.setQueryData<ModuleOutputDTO>(moduleKeys.detail(moduleId), (prev) => {
Expand All @@ -236,10 +235,10 @@ export const useHookRemove = ({ moduleId }) => {
}
return {
...prev,
hooks: prev.hooks.filter((hook) => hook.id !== removedHook.id),
hooks: prev.hooks.filter((hook) => hook.id !== hookId),
};
});
return queryClient.removeQueries({ queryKey: moduleKeys.hooks.detail(removedHook.id) });
return queryClient.removeQueries({ queryKey: moduleKeys.hooks.detail(hookId) });
},
}),
defaultHookErrorMessages
Expand Down Expand Up @@ -354,9 +353,9 @@ export const useCommandRemove = ({ moduleId }) => {
const apiClient = getApiClient();
const queryClient = useQueryClient();

return mutationWrapper<IdUuidDTO, CommandRemove>(
useMutation<IdUuidDTO, AxiosError<IdUuidDTOAPI>, CommandRemove>({
mutationFn: async ({ commandId }) => (await apiClient.command.commandControllerRemove(commandId)).data.data,
return mutationWrapper<APIOutput, CommandRemove>(
useMutation<APIOutput, AxiosError<APIOutput>, CommandRemove>({
mutationFn: async ({ commandId }) => (await apiClient.command.commandControllerRemove(commandId)).data,
onSuccess: async (_, { commandId }) => {
// invalidate list of commands
await queryClient.invalidateQueries({ queryKey: moduleKeys.commands.list() });
Expand Down Expand Up @@ -458,10 +457,10 @@ export const useCronJobRemove = ({ moduleId }: { moduleId: string }) => {
const apiClient = getApiClient();
const queryClient = useQueryClient();

return mutationWrapper<IdUuidDTO, CronJobRemove>(
useMutation<IdUuidDTO, AxiosError<IdUuidDTOAPI>, CronJobRemove>({
return mutationWrapper<APIOutput, CronJobRemove>(
useMutation<APIOutput, AxiosError<APIOutput>, CronJobRemove>({
mutationFn: async ({ cronJobId }: { cronJobId: string }) =>
(await apiClient.cronjob.cronJobControllerRemove(cronJobId)).data.data,
(await apiClient.cronjob.cronJobControllerRemove(cronJobId)).data,
onSuccess: async (_, { cronJobId }) => {
await queryClient.invalidateQueries({ queryKey: moduleKeys.cronJobs.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.export(moduleId) });
Expand Down Expand Up @@ -555,9 +554,9 @@ export const useFunctionRemove = ({ moduleId }: { moduleId: string }) => {
const apiClient = getApiClient();
const queryClient = useQueryClient();

return mutationWrapper<IdUuidDTO, FunctionRemove>(
useMutation<IdUuidDTO, AxiosError<IdUuidDTOAPI>, FunctionRemove>({
mutationFn: async ({ functionId }) => (await apiClient.function.functionControllerRemove(functionId)).data.data,
return mutationWrapper<APIOutput, FunctionRemove>(
useMutation<APIOutput, AxiosError<APIOutput>, FunctionRemove>({
mutationFn: async ({ functionId }) => (await apiClient.function.functionControllerRemove(functionId)).data,
onSuccess: async (_, { functionId }) => {
await queryClient.invalidateQueries({ queryKey: moduleKeys.functions.list() });
queryClient.setQueryData<ModuleOutputDTO>(moduleKeys.detail(moduleId), (prev) => {
Expand Down
8 changes: 3 additions & 5 deletions packages/web-main/src/queries/role.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
RoleOutputDTO,
RoleCreateInputDTO,
RoleUpdateInputDTO,
IdUuidDTO,
IdUuidDTOAPI,
RoleOutputDTOAPI,
PermissionOutputDTOAPI,
PermissionOutputDTO,
Expand Down Expand Up @@ -104,9 +102,9 @@ export const useRoleRemove = () => {
const apiClient = getApiClient();
const queryClient = useQueryClient();

return mutationWrapper<IdUuidDTO, RoleRemove>(
useMutation<IdUuidDTO, AxiosError<IdUuidDTOAPI>, RoleRemove>({
mutationFn: async ({ roleId }) => (await apiClient.role.roleControllerRemove(roleId)).data.data,
return mutationWrapper<APIOutput, RoleRemove>(
useMutation<APIOutput, AxiosError<APIOutput>, RoleRemove>({
mutationFn: async ({ roleId }) => (await apiClient.role.roleControllerRemove(roleId)).data,
onSuccess: (_, { roleId }) => {
queryClient.invalidateQueries({ queryKey: roleKeys.list() });
queryClient.removeQueries({ queryKey: roleKeys.detail(roleId) });
Expand Down
15 changes: 8 additions & 7 deletions packages/web-main/src/queries/shopListing.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
IdUuidDTO,
APIOutput,
ShopListingCreateDTO,
ShopListingOutputArrayDTOAPI,
ShopListingOutputDTO,
Expand Down Expand Up @@ -55,18 +55,19 @@ export const useShopListingCreate = () => {
};

interface ShopListingDelete {
id: string;
shopListingId: string;
}

export const useShopListingDelete = () => {
const queryClient = useQueryClient();

return mutationWrapper<IdUuidDTO, ShopListingDelete>(
useMutation<IdUuidDTO, AxiosError<IdUuidDTO>, ShopListingDelete>({
mutationFn: async ({ id }) => (await getApiClient().shopListing.shopListingControllerDelete(id)).data,
onSuccess: async ({ id: deletedShopListingId }) => {
return mutationWrapper<APIOutput, ShopListingDelete>(
useMutation<APIOutput, AxiosError<APIOutput>, ShopListingDelete>({
mutationFn: async ({ shopListingId }) =>
(await getApiClient().shopListing.shopListingControllerDelete(shopListingId)).data,
onSuccess: async (_, { shopListingId }) => {
await queryClient.invalidateQueries({ queryKey: shopListingKeys.list() });
queryClient.removeQueries({ queryKey: shopListingKeys.detail(deletedShopListingId) });
queryClient.removeQueries({ queryKey: shopListingKeys.detail(shopListingId) });
},
}),
{}
Expand Down
7 changes: 3 additions & 4 deletions packages/web-main/src/queries/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useMutation, useQueryClient, queryOptions } from '@tanstack/react-query
import { getApiClient } from 'util/getApiClient';
import {
APIOutput,
IdUuidDTO,
LinkPlayerUnauthedInputDTO,
MeOutoutDTO,
UserOutputArrayDTOAPI,
Expand Down Expand Up @@ -134,9 +133,9 @@ export const useUserRemove = () => {
const queryClient = useQueryClient();
const { enqueueSnackbar } = useSnackbar();

return mutationWrapper<IdUuidDTO, UserRemoveInput>(
useMutation<IdUuidDTO, AxiosError<IdUuidDTO>, UserRemoveInput>({
mutationFn: async ({ userId }) => (await apiClient.user.userControllerRemove(userId)).data.data,
return mutationWrapper<APIOutput, UserRemoveInput>(
useMutation<APIOutput, AxiosError<APIOutput>, UserRemoveInput>({
mutationFn: async ({ userId }) => (await apiClient.user.userControllerRemove(userId)).data,
onSuccess: async (_, { userId }) => {
await queryClient.invalidateQueries({ queryKey: userKeys.detail(userId) });
await queryClient.invalidateQueries({ queryKey: userKeys.list() });
Expand Down
8 changes: 4 additions & 4 deletions packages/web-main/src/queries/variable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMutation, useQueryClient, queryOptions } from '@tanstack/react-query';
import { getApiClient } from 'util/getApiClient';
import {
IdUuidDTO,
APIOutput,
VariableCreateDTO,
VariableOutputArrayDTOAPI,
VariableOutputDTO,
Expand Down Expand Up @@ -83,9 +83,9 @@ export const useVariableDelete = () => {
const apiClient = getApiClient();
const queryClient = useQueryClient();

return mutationWrapper<IdUuidDTO, VariableDeleteInput>(
useMutation<IdUuidDTO, AxiosError<VariableOutputDTO>, VariableDeleteInput>({
mutationFn: async ({ variableId }) => (await apiClient.variable.variableControllerDelete(variableId)).data.data,
return mutationWrapper<APIOutput, VariableDeleteInput>(
useMutation<APIOutput, AxiosError<VariableOutputDTO>, VariableDeleteInput>({
mutationFn: async ({ variableId }) => (await apiClient.variable.variableControllerDelete(variableId)).data,
onSuccess: async (_, { variableId }) => {
await queryClient.invalidateQueries({ queryKey: variableKeys.list() });
queryClient.removeQueries({ queryKey: variableKeys.detail(variableId) });
Expand Down
3 changes: 1 addition & 2 deletions packages/web-main/src/routes/_auth/_global/users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ export const UserDeleteDialog: FC<VariableDeleteProps> = ({ user, openDialog, se

const handleOnDelete = async (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.preventDefault();

await mutateAsync({ id: user.id });
await mutateAsync({ userId: user.id });
setOpenDialog(false);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const ShopListingActions: FC<ShopListingActions> = ({ shopListingId, game

const handleOnDeleteConfirmationClick = (e: MouseEvent) => {
e.stopPropagation();
deleteShopListing({ id: shopListingId });
deleteShopListing({ shopListingId });
setOpenDeleteConfirmationDialog(false);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const ShopOrderTableView: FC<ShopOrderTableView> = ({ gameServerId }) =>
to="/gameserver/$gameServerId/shop/listing/$shopListingId/view"
params={{ gameServerId, shopListingId: info.getValue() }}
>
View item
view item
</Link>
),
enableColumnFilter: true,
Expand Down

0 comments on commit 8370091

Please sign in to comment.