Skip to content

Commit 68950d4

Browse files
committed
feat: Disable cache for api request
1 parent 9c7f466 commit 68950d4

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

src/hooks/useMyAccount.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ import { useQuery } from "@tanstack/react-query";
22
import { useRedmineApi } from "../provider/RedmineApiProvider";
33
import useSettings from "./useSettings";
44

5-
const useMyAccount = () => {
5+
type Options = {
6+
staleTime?: number;
7+
};
8+
9+
const useMyAccount = ({ staleTime }: Options = {}) => {
610
const { settings } = useSettings();
711
const redmineApi = useRedmineApi();
812

913
const myAccountQuery = useQuery({
1014
queryKey: ["myAccount", settings.redmineURL, settings.redmineApiKey],
1115
queryFn: () => redmineApi.getMyAccount(),
12-
retryOnMount: false,
16+
retry: 1,
17+
...(staleTime && { staleTime }),
1318
});
1419

1520
return {

src/pages/SettingsPage.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const SettingsPage = () => {
3737
const [editRedmineInstance, setEditRedmineInstance] = useState(false);
3838
const [saved, setSaved] = useState(false);
3939

40-
const myAccount = useMyAccount();
40+
const myAccount = useMyAccount({ staleTime: 1000 * 10 });
4141

4242
useEffect(() => {
4343
formik.current?.setValues(settings);
@@ -299,8 +299,8 @@ const Info = () => {
299299
legend={
300300
<>
301301
<a href="https://chrome.google.com/webstore/detail/redmine-time-tracking/ldcanhhkffokndenejhafhlkapflgcjg" target="_blank" tabIndex={-1} className="hover:underline">
302-
{name}
303-
</a>
302+
{name}
303+
</a>
304304
<span className="mx-1 text-xs">-</span>
305305
<a href="https://github.com/CrawlerCode/redmine-time-tracking/releases" target="_blank" tabIndex={-1} className="hover:underline">
306306
v{version_name || version}
@@ -314,11 +314,11 @@ const Info = () => {
314314
GitHub
315315
</a>
316316

317-
<a href="https://github.com/CrawlerCode/redmine-time-tracking/issues" target="_blank" tabIndex={-1} className="hover:underline">
317+
<a href="https://github.com/CrawlerCode/redmine-time-tracking/issues" target="_blank" tabIndex={-1} className="hover:underline">
318318
<FontAwesomeIcon icon={faBug} className="mr-1" />
319-
<FormattedMessage id="settings.info.report-an-issue" />
320-
</a>
321-
</div>
319+
<FormattedMessage id="settings.info.report-an-issue" />
320+
</a>
321+
</div>
322322
</Fieldset>
323323
</div>
324324
</>

src/provider/QueryClientProvider.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const CACHE_TIME = 1000 * 60 * 60 * 24; // 24 hours
1313
const queryClient = new QueryClient({
1414
defaultOptions: {
1515
queries: {
16-
refetchOnWindowFocus: true,
1716
gcTime: CACHE_TIME,
1817
staleTime: 1000 * 60 * 60, // 1 hour
1918
},

src/provider/RedmineApiProvider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const RedmineApiProvider = ({ children }: { children: ReactNode }) => {
1616
baseURL: settings.redmineURL,
1717
headers: {
1818
"X-Redmine-API-Key": settings.redmineApiKey,
19+
"cache-control": "no-store",
1920
},
2021
})
2122
)

0 commit comments

Comments
 (0)