mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 03:40:14 +00:00
Use filter API for download queue
This commit is contained in:
parent
93822fc43c
commit
46c6e7e925
@ -4,8 +4,8 @@ import { getTAUrl } from "./constants";
|
|||||||
|
|
||||||
const TA_BASE_URL = getTAUrl();
|
const TA_BASE_URL = getTAUrl();
|
||||||
|
|
||||||
export const getDownloads = async (token: string, ignoredStatus: boolean): Promise<Download> => {
|
export const getDownloads = async (token: string, filter: boolean): Promise<Download> => {
|
||||||
const response = await fetch(`${TA_BASE_URL.server}/api/download/?filter=${ignoredStatus ? 'ignore' : 'pending'}`, {
|
const response = await fetch(`${TA_BASE_URL.server}/api/download/?filter=${filter ? 'ignore' : 'pending'}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -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)
|
getDownloads(session.ta_token.token, false)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -48,33 +48,38 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
|||||||
|
|
||||||
const Download: NextPage = () => {
|
const Download: NextPage = () => {
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
|
|
||||||
|
const [ignoredStatus, setIgnoredStatus] = useState<IgnoredStatus>(false);
|
||||||
|
const [formHidden, setFormHidden] = useState<FormHidden>(true);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: downloads,
|
data: downloads,
|
||||||
error,
|
error,
|
||||||
isLoading,
|
isLoading,
|
||||||
refetch,
|
refetch,
|
||||||
} = useQuery(
|
} = useQuery(
|
||||||
["downloads", session.ta_token.token],
|
["downloads", session.ta_token.token, ignoredStatus],
|
||||||
() => getDownloads(session.ta_token.token, ignoredStatus),
|
() => getDownloads(session.ta_token.token, ignoredStatus),
|
||||||
{
|
{
|
||||||
enabled: !!session?.ta_token?.token,
|
enabled: !!session?.ta_token?.token,
|
||||||
refetchInterval: 1500,
|
// refetchInterval: 1500,
|
||||||
refetchIntervalInBackground: false,
|
// refetchIntervalInBackground: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const [viewStyle, setViewStyle] = useState<ViewStyle>(downloads?.config?.default_view?.downloads);
|
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) => {
|
const handleSetViewstyle = (selectedViewStyle: ViewStyle) => {
|
||||||
setViewStyle(selectedViewStyle);
|
setViewStyle(selectedViewStyle);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSetIgnoredStatus = (selectedIgnoredStatus: IgnoredStatus) => {
|
const handleSetIgnoredStatus = (selectedIgnoredStatus: IgnoredStatus) => {
|
||||||
|
// ignoredStatus = !ignoredStatus;
|
||||||
setIgnoredStatus(selectedIgnoredStatus);
|
setIgnoredStatus(selectedIgnoredStatus);
|
||||||
refetch();
|
refetch();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleSetFormHidden = (selectedFormHidden: FormHidden) => {
|
const handleSetFormHidden = (selectedFormHidden: FormHidden) => {
|
||||||
setFormHidden(selectedFormHidden);
|
setFormHidden(selectedFormHidden);
|
||||||
|
Loading…
Reference in New Issue
Block a user