Use filter API for download queue

This commit is contained in:
n8detar 2022-04-17 16:32:10 -07:00
parent 93822fc43c
commit 46c6e7e925
2 changed files with 14 additions and 9 deletions

View File

@ -4,8 +4,8 @@ import { getTAUrl } from "./constants";
const TA_BASE_URL = getTAUrl();
export const getDownloads = async (token: string, ignoredStatus: boolean): Promise<Download> => {
const response = await fetch(`${TA_BASE_URL.server}/api/download/?filter=${ignoredStatus ? 'ignore' : 'pending'}`, {
export const getDownloads = async (token: string, filter: boolean): Promise<Download> => {
const response = await fetch(`${TA_BASE_URL.server}/api/download/?filter=${filter ? 'ignore' : 'pending'}`, {
headers: {
Accept: "application/json",
"Content-Type": "application/json",

View File

@ -34,7 +34,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
};
}
await queryClient.prefetchQuery(["downloads", session.ta_token.token], () =>
await queryClient.prefetchQuery(["downloads", session.ta_token.token, false], () =>
getDownloads(session.ta_token.token, false)
);
@ -48,33 +48,38 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const Download: NextPage = () => {
const { data: session } = useSession();
const [ignoredStatus, setIgnoredStatus] = useState<IgnoredStatus>(false);
const [formHidden, setFormHidden] = useState<FormHidden>(true);
const {
data: downloads,
error,
isLoading,
refetch,
} = useQuery(
["downloads", session.ta_token.token],
["downloads", session.ta_token.token, ignoredStatus],
() => getDownloads(session.ta_token.token, ignoredStatus),
{
enabled: !!session?.ta_token?.token,
refetchInterval: 1500,
refetchIntervalInBackground: false,
// refetchInterval: 1500,
// refetchIntervalInBackground: false,
}
);
const [viewStyle, setViewStyle] = useState<ViewStyle>(downloads?.config?.default_view?.downloads);
const [ignoredStatus, setIgnoredStatus] = useState<IgnoredStatus>(false);
const [formHidden, setFormHidden] = useState<FormHidden>(true);
const handleSetViewstyle = (selectedViewStyle: ViewStyle) => {
setViewStyle(selectedViewStyle);
};
const handleSetIgnoredStatus = (selectedIgnoredStatus: IgnoredStatus) => {
// ignoredStatus = !ignoredStatus;
setIgnoredStatus(selectedIgnoredStatus);
refetch();
};
const handleSetFormHidden = (selectedFormHidden: FormHidden) => {
setFormHidden(selectedFormHidden);