query cache settings, somehow still fetching logs again sometimes
This commit is contained in:
parent
6683af7f5d
commit
ed7c5023df
8 changed files with 23 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { Button, TextField } from "@material-ui/core";
|
import { Button, TextField } from "@material-ui/core";
|
||||||
import React, { FormEvent, useContext } from "react";
|
import React, { FormEvent, useContext } from "react";
|
||||||
|
import { useQueryCache } from "react-query";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { store } from "../store";
|
import { store } from "../store";
|
||||||
import { Settings } from "./Settings";
|
import { Settings } from "./Settings";
|
||||||
|
@ -28,6 +29,7 @@ const FiltersWrapper = styled.div`
|
||||||
|
|
||||||
export function Filters() {
|
export function Filters() {
|
||||||
const { setCurrents, state } = useContext(store);
|
const { setCurrents, state } = useContext(store);
|
||||||
|
const queryCache = useQueryCache();
|
||||||
|
|
||||||
const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
|
const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -35,7 +37,11 @@ export function Filters() {
|
||||||
if (e.target instanceof HTMLFormElement) {
|
if (e.target instanceof HTMLFormElement) {
|
||||||
const data = new FormData(e.target);
|
const data = new FormData(e.target);
|
||||||
|
|
||||||
setCurrents(data.get("channel") as string | null, data.get("username") as string | null);
|
const channel = data.get("channel") as string | null;
|
||||||
|
const username = data.get("username") as string | null;
|
||||||
|
|
||||||
|
queryCache.invalidateQueries(`${channel}:${username}`);
|
||||||
|
setCurrents(channel, username);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { useContext } from "react";
|
import { useContext } from "react";
|
||||||
import { useQuery } from "react-query";
|
import { useQuery } from "react-query";
|
||||||
import { isUserId } from "../services/isUserId";
|
import { isUserId } from "../services/isUserId";
|
||||||
import { store } from "../store";
|
import { QueryDefaults, store } from "../store";
|
||||||
|
|
||||||
export type AvailableLogs = Array<{ month: string, year: string }>;
|
export type AvailableLogs = Array<{ month: string, year: string }>;
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ export function useAvailableLogs(channel: string | null, username: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
});
|
}, QueryDefaults);
|
||||||
|
|
||||||
return data ?? [];
|
return data ?? [];
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
import { useQuery } from "react-query";
|
import { useQuery } from "react-query";
|
||||||
|
import { QueryDefaults } from "../store";
|
||||||
import { BttvChannelEmotesResponse } from "../types/Bttv";
|
import { BttvChannelEmotesResponse } from "../types/Bttv";
|
||||||
import { ThirdPartyEmote } from "../types/ThirdPartyEmote";
|
import { ThirdPartyEmote } from "../types/ThirdPartyEmote";
|
||||||
|
|
||||||
|
@ -11,7 +12,7 @@ export function useBttvChannelEmotes(channelId: string): Array<ThirdPartyEmote>
|
||||||
return fetch(`https://api.betterttv.net/3/cached/users/twitch/${channelId}`).then(res =>
|
return fetch(`https://api.betterttv.net/3/cached/users/twitch/${channelId}`).then(res =>
|
||||||
res.json() as Promise<BttvChannelEmotesResponse>
|
res.json() as Promise<BttvChannelEmotesResponse>
|
||||||
);
|
);
|
||||||
});
|
}, QueryDefaults);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { useQuery } from "react-query";
|
import { useQuery } from "react-query";
|
||||||
|
import { QueryDefaults } from "../store";
|
||||||
import { BttvGlobalEmotesResponse } from "../types/Bttv";
|
import { BttvGlobalEmotesResponse } from "../types/Bttv";
|
||||||
import { ThirdPartyEmote } from "../types/ThirdPartyEmote";
|
import { ThirdPartyEmote } from "../types/ThirdPartyEmote";
|
||||||
|
|
||||||
|
@ -7,7 +8,7 @@ export function useBttvGlobalEmotes(): Array<ThirdPartyEmote> {
|
||||||
return fetch("https://api.betterttv.net/3/cached/emotes/global").then(res =>
|
return fetch("https://api.betterttv.net/3/cached/emotes/global").then(res =>
|
||||||
res.json() as Promise<BttvGlobalEmotesResponse>
|
res.json() as Promise<BttvGlobalEmotesResponse>
|
||||||
);
|
);
|
||||||
});
|
}, QueryDefaults);
|
||||||
|
|
||||||
if (isLoading || !data) {
|
if (isLoading || !data) {
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { useQuery } from "react-query";
|
import { useQuery } from "react-query";
|
||||||
|
import { QueryDefaults } from "../store";
|
||||||
import { EmoteSet, FfzChannelEmotesResponse } from "../types/Ffz";
|
import { EmoteSet, FfzChannelEmotesResponse } from "../types/Ffz";
|
||||||
import { ThirdPartyEmote } from "../types/ThirdPartyEmote";
|
import { ThirdPartyEmote } from "../types/ThirdPartyEmote";
|
||||||
|
|
||||||
|
@ -11,7 +12,7 @@ export function useFfzChannelEmotes(channelId: string): Array<ThirdPartyEmote> {
|
||||||
return fetch(`https://api.frankerfacez.com/v1/room/id/${channelId}`).then(res =>
|
return fetch(`https://api.frankerfacez.com/v1/room/id/${channelId}`).then(res =>
|
||||||
res.json() as Promise<FfzChannelEmotesResponse>
|
res.json() as Promise<FfzChannelEmotesResponse>
|
||||||
);
|
);
|
||||||
});
|
}, QueryDefaults);
|
||||||
|
|
||||||
if (isLoading || !data?.sets) {
|
if (isLoading || !data?.sets) {
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { useQuery } from "react-query";
|
import { useQuery } from "react-query";
|
||||||
|
import { QueryDefaults } from "../store";
|
||||||
import { EmoteSet, FfzGlobalEmotesResponse } from "../types/Ffz";
|
import { EmoteSet, FfzGlobalEmotesResponse } from "../types/Ffz";
|
||||||
import { ThirdPartyEmote } from "../types/ThirdPartyEmote";
|
import { ThirdPartyEmote } from "../types/ThirdPartyEmote";
|
||||||
|
|
||||||
|
@ -7,7 +8,7 @@ export function useFfzGlobalEmotes(): Array<ThirdPartyEmote> {
|
||||||
return fetch("https://api.frankerfacez.com/v1/set/global").then(res =>
|
return fetch("https://api.frankerfacez.com/v1/set/global").then(res =>
|
||||||
res.json() as Promise<FfzGlobalEmotesResponse>
|
res.json() as Promise<FfzGlobalEmotesResponse>
|
||||||
);
|
);
|
||||||
});
|
}, QueryDefaults);
|
||||||
|
|
||||||
if (isLoading || !data?.sets) {
|
if (isLoading || !data?.sets) {
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { useContext } from "react";
|
import { useContext } from "react";
|
||||||
import { useQuery } from "react-query";
|
import { useQuery } from "react-query";
|
||||||
import { isUserId } from "../services/isUserId";
|
import { isUserId } from "../services/isUserId";
|
||||||
import { store } from "../store";
|
import { QueryDefaults, store } from "../store";
|
||||||
import { Emote, LogMessage, UserLogResponse } from "../types/log";
|
import { Emote, LogMessage, UserLogResponse } from "../types/log";
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ export function useLog(channel: string, username: string, year: string, month: s
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
});
|
}, QueryDefaults);
|
||||||
|
|
||||||
return data ?? [];
|
return data ?? [];
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,3 +78,7 @@ const StateProvider = ({ children }: { children: JSX.Element }): JSX.Element =>
|
||||||
};
|
};
|
||||||
|
|
||||||
export { store, StateProvider };
|
export { store, StateProvider };
|
||||||
|
|
||||||
|
export const QueryDefaults = {
|
||||||
|
staleTime: 5 * 60 * 1000,
|
||||||
|
};
|
Loading…
Add table
Reference in a new issue