Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Remove explicit invalidate calls #1445

Merged
merged 2 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ export function DeleteAccountDialog({
},
});
const { t } = useTranslation();
const trpcUtils = trpc.useUtils();
const posthog = usePostHog();
const deleteAccount = trpc.user.delete.useMutation({
onSuccess() {
posthog?.capture("delete account");
trpcUtils.invalidate();
signOut({
callbackUrl: "/login",
});
Expand Down
2 changes: 0 additions & 2 deletions apps/web/src/app/[locale]/(auth)/register/register-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export const RegisterForm = () => {
});

const { handleSubmit, control, getValues, setError, formState } = form;
const queryClient = trpc.useUtils();
const requestRegistration = trpc.auth.requestRegistration.useMutation();
const authenticateRegistration =
trpc.auth.authenticateRegistration.useMutation();
Expand All @@ -68,7 +67,6 @@ export const RegisterForm = () => {
throw new Error("Failed to authenticate user");
}

queryClient.invalidate();

posthog?.identify(res.user.id, {
email: res.user.email,
Expand Down
3 changes: 0 additions & 3 deletions apps/web/src/app/[locale]/auth/login/login-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type PageProps = { magicLink: string; email: string };
export const LoginPage = ({ magicLink, email }: PageProps) => {
const session = useSession();
const posthog = usePostHog();
const trpcUtils = trpc.useUtils();
const magicLinkFetch = useMutation({
mutationFn: async () => {
const res = await fetch(magicLink);
Expand All @@ -32,8 +31,6 @@ export const LoginPage = ({ magicLink, email }: PageProps) => {
email: updatedSession.user.email,
name: updatedSession.user.name,
});

await trpcUtils.invalidate();
}
}

Expand Down
2 changes: 0 additions & 2 deletions apps/web/src/app/[locale]/poll/[urlId]/duplicate-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export function DuplicateDialog({
pollTitle,
...props
}: DialogProps & { pollId: string; pollTitle: string }) {
const queryClient = trpc.useUtils();
const duplicate = trpc.polls.duplicate.useMutation();
const posthog = usePostHog();
const router = useRouter();
Expand Down Expand Up @@ -52,7 +51,6 @@ export function DuplicateDialog({
pollId,
newPollId: res.id,
});
queryClient.invalidate();
router.push(`/poll/${res.id}`);
},
},
Expand Down
8 changes: 3 additions & 5 deletions apps/web/src/components/auth/auth-forms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import { useForm } from "react-hook-form";
import { requiredString } from "../../utils/form-validation";

export const verifyCode = async (options: { email: string; token: string }) => {
const url = `${
window.location.origin
}/api/auth/callback/email?email=${encodeURIComponent(options.email)}&token=${
options.token
}`;
const url = `${window.location.origin
}/api/auth/callback/email?email=${encodeURIComponent(options.email)}&token=${options.token
}`;

const res = await fetch(url);

Expand Down
2 changes: 0 additions & 2 deletions apps/web/src/components/create-poll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export const CreatePoll: React.FunctionComponent = () => {
useUnmount(clear);

const posthog = usePostHog();
const queryClient = trpc.useUtils();
const createPoll = trpc.polls.create.useMutation({
networkMode: "always",
onSuccess: () => {
Expand Down Expand Up @@ -104,7 +103,6 @@ export const CreatePoll: React.FunctionComponent = () => {
last_poll_created_at: new Date().toISOString(),
},
});
queryClient.invalidate();
router.push(`/poll/${res.id}`);
},
},
Expand Down
2 changes: 0 additions & 2 deletions apps/web/src/components/discussion/discussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ function NewCommentForm({

const posthog = usePostHog();

const queryClient = trpc.useUtils();

const session = useUser();

Expand All @@ -88,7 +87,6 @@ function NewCommentForm({

const addComment = trpc.polls.comments.add.useMutation({
onSuccess: () => {
queryClient.polls.comments.invalidate();
posthog?.capture("created comment");
},
onError: (error) => {
Expand Down
2 changes: 0 additions & 2 deletions apps/web/src/components/participant-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,8 @@ const ChangeNameModal = (props: {
onOpenChange: (open: boolean) => void;
}) => {
const posthog = usePostHog();
const queryClient = trpc.useUtils();
const changeName = trpc.polls.participants.rename.useMutation({
onSuccess: (_, { participantId, newName }) => {
queryClient.polls.participants.invalidate();
posthog?.capture("changed name", {
participantId,
oldName: props.oldName,
Expand Down
5 changes: 0 additions & 5 deletions apps/web/src/components/poll/manage-poll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function PauseResumeToggle() {
status: "live",
};
});
queryClient.polls.invalidate();
},
});
const pause = trpc.polls.pause.useMutation({
Expand All @@ -63,7 +62,6 @@ function PauseResumeToggle() {
status: "paused",
};
});
queryClient.polls.invalidate();
},
});

Expand Down Expand Up @@ -139,9 +137,6 @@ const ManagePoll: React.FunctionComponent<{
};
});
},
onSuccess: () => {
queryClient.polls.invalidate();
},
});

const [showDeletePollDialog, setShowDeletePollDialog] = React.useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ export const DeletePollDialog: React.FunctionComponent<{
urlId: string;
}> = ({ open, onOpenChange, urlId }) => {
const posthog = usePostHog();
const queryClient = trpc.useUtils();
const router = useRouter();
const deletePoll = trpc.polls.delete.useMutation({
onSuccess: () => {
queryClient.polls.invalidate();
posthog?.capture("deleted poll");
onOpenChange(false);
router.replace("/polls");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,7 @@ export const FinalizePollForm = ({

export function FinalizePollDialog(props: DialogProps) {
const poll = usePoll();
const queryClient = trpc.useUtils();
const scheduleEvent = trpc.polls.book.useMutation({
onSuccess: () => {
queryClient.invalidate();
},
});
const scheduleEvent = trpc.polls.book.useMutation();
return (
<Dialog {...props}>
<DialogContent size="2xl">
Expand Down
4 changes: 0 additions & 4 deletions apps/web/src/components/poll/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const useAddParticipantMutation = () => {
];
},
);
queryClient.polls.participants.list.invalidate({ pollId });
posthog?.capture("add participant", {
pollId,
name,
Expand Down Expand Up @@ -83,7 +82,6 @@ export const useDeleteParticipantMutation = () => {
);
},
onSuccess: (_, { participantId }) => {
queryClient.polls.participants.list.invalidate({ pollId: poll.id });
posthog?.capture("remove participant", {
pollId: poll.id,
participantId,
Expand All @@ -93,11 +91,9 @@ export const useDeleteParticipantMutation = () => {
};

export const useUpdatePollMutation = () => {
const queryClient = trpc.useUtils();
const posthog = usePostHog();
return trpc.polls.update.useMutation({
onSuccess: (_data, { urlId }) => {
queryClient.polls.invalidate();
posthog?.capture("updated poll", {
id: urlId,
});
Expand Down
10 changes: 4 additions & 6 deletions apps/web/src/components/poll/notifications-toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const NotificationsToggle: React.FunctionComponent = () => {
return [...oldWatchers, { userId: user.id }];
},
);
queryClient.polls.invalidate();
},
});

Expand All @@ -69,7 +68,6 @@ const NotificationsToggle: React.FunctionComponent = () => {
return oldWatchers.filter(({ userId }) => userId !== user.id);
},
);
queryClient.polls.invalidate();
},
});

Expand Down Expand Up @@ -126,11 +124,11 @@ const NotificationsToggle: React.FunctionComponent = () => {
values={{
value: isWatching
? t("notificationsOn", {
defaultValue: "On",
})
defaultValue: "On",
})
: t("notificationsOff", {
defaultValue: "Off",
}),
defaultValue: "Off",
}),
}}
/>
)}
Expand Down
Loading