mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-21 19:30:16 +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();
|
||||
|
||||
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",
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user