remove unnecessary fetches of api (#960)

* skip repeating fetch of user on session changes
* fix some issues on integrations
This commit is contained in:
Alex Johansson 2021-10-15 00:00:50 +02:00 committed by GitHub
parent c2c37b701e
commit 59e25ad04e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 16 deletions

View File

@ -37,15 +37,8 @@ import { useViewerI18n } from "./I18nLanguageHandler";
import Logo from "./Logo";
function useMeQuery() {
const [session] = useSession();
const meQuery = trpc.useQuery(["viewer.me"]);
useEffect(() => {
// refetch if sesion changes
meQuery.refetch();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [session]);
return meQuery;
}

View File

@ -1,5 +1,5 @@
import Image from "next/image";
import { ReactNode, useEffect, useState } from "react";
import { Fragment, ReactNode, useState } from "react";
import { useMutation } from "react-query";
import { QueryCell } from "@lib/QueryCell";
@ -56,13 +56,15 @@ function ConnectIntegration(props: { type: string; render: (renderProps: ButtonB
window.location.href = json.url;
setIsLoading(true);
});
const [isModalOpen, setIsModalOpen] = useState(false);
// refetch intergrations when modal closes
const [isModalOpen, _setIsModalOpen] = useState(false);
const utils = trpc.useContext();
useEffect(() => {
const setIsModalOpen: typeof _setIsModalOpen = (v) => {
_setIsModalOpen(v);
// refetch intergrations on modal toggles
utils.invalidateQueries(["viewer.integrations"]);
}, [isModalOpen, utils]);
};
return (
<>
@ -340,8 +342,8 @@ export default function IntegrationsPage() {
{data.connectedCalendars.length > 0 && (
<>
<List>
{data.connectedCalendars.map((item, index) => (
<li key={index}>
{data.connectedCalendars.map((item) => (
<Fragment key={item.credentialId}>
{item.calendars ? (
<IntegrationListItem
{...item.integration}
@ -385,7 +387,7 @@ export default function IntegrationsPage() {
}
/>
)}
</li>
</Fragment>
))}
</List>
<ShellSubHeading