remove unnecessary fetches of api (#960)
* skip repeating fetch of user on session changes * fix some issues on integrationspull/961/head
parent
c2c37b701e
commit
59e25ad04e
|
@ -37,15 +37,8 @@ import { useViewerI18n } from "./I18nLanguageHandler";
|
||||||
import Logo from "./Logo";
|
import Logo from "./Logo";
|
||||||
|
|
||||||
function useMeQuery() {
|
function useMeQuery() {
|
||||||
const [session] = useSession();
|
|
||||||
const meQuery = trpc.useQuery(["viewer.me"]);
|
const meQuery = trpc.useQuery(["viewer.me"]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// refetch if sesion changes
|
|
||||||
meQuery.refetch();
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [session]);
|
|
||||||
|
|
||||||
return meQuery;
|
return meQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { ReactNode, useEffect, useState } from "react";
|
import { Fragment, ReactNode, useState } from "react";
|
||||||
import { useMutation } from "react-query";
|
import { useMutation } from "react-query";
|
||||||
|
|
||||||
import { QueryCell } from "@lib/QueryCell";
|
import { QueryCell } from "@lib/QueryCell";
|
||||||
|
@ -56,13 +56,15 @@ function ConnectIntegration(props: { type: string; render: (renderProps: ButtonB
|
||||||
window.location.href = json.url;
|
window.location.href = json.url;
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
});
|
});
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, _setIsModalOpen] = useState(false);
|
||||||
|
|
||||||
// refetch intergrations when modal closes
|
|
||||||
const utils = trpc.useContext();
|
const utils = trpc.useContext();
|
||||||
useEffect(() => {
|
|
||||||
|
const setIsModalOpen: typeof _setIsModalOpen = (v) => {
|
||||||
|
_setIsModalOpen(v);
|
||||||
|
// refetch intergrations on modal toggles
|
||||||
|
|
||||||
utils.invalidateQueries(["viewer.integrations"]);
|
utils.invalidateQueries(["viewer.integrations"]);
|
||||||
}, [isModalOpen, utils]);
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -340,8 +342,8 @@ export default function IntegrationsPage() {
|
||||||
{data.connectedCalendars.length > 0 && (
|
{data.connectedCalendars.length > 0 && (
|
||||||
<>
|
<>
|
||||||
<List>
|
<List>
|
||||||
{data.connectedCalendars.map((item, index) => (
|
{data.connectedCalendars.map((item) => (
|
||||||
<li key={index}>
|
<Fragment key={item.credentialId}>
|
||||||
{item.calendars ? (
|
{item.calendars ? (
|
||||||
<IntegrationListItem
|
<IntegrationListItem
|
||||||
{...item.integration}
|
{...item.integration}
|
||||||
|
@ -385,7 +387,7 @@ export default function IntegrationsPage() {
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</li>
|
</Fragment>
|
||||||
))}
|
))}
|
||||||
</List>
|
</List>
|
||||||
<ShellSubHeading
|
<ShellSubHeading
|
||||||
|
|
Loading…
Reference in New Issue