Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(request): abort obj request after going to new path #227

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/hooks/usePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useRouter } from "./useRouter"

let first_fetch = true

let cancelObj: Canceler
let cancelList: Canceler
export function addOrUpdateQuery(
key: string,
Expand Down Expand Up @@ -79,7 +80,15 @@ export const resetGlobalPage = () => {
}
export const usePath = () => {
const { pathname, to } = useRouter()
const [, getObj] = useFetch((path: string) => fsGet(path, password()))
const [, getObj] = useFetch((path: string) =>
fsGet(
path,
password(),
new axios.CancelToken((c) => {
cancelObj = c
}),
),
)
const pagination = getPagination()
if (pagination.type === "pagination" && getQueryVariable("page")) {
globalPage = parseInt(getQueryVariable("page"))
Expand All @@ -102,7 +111,7 @@ export const usePath = () => {
page.index,
page.size,
arg?.force,
new axios.CancelToken(function executor(c) {
new axios.CancelToken((c) => {
cancelList = c
}),
)
Expand All @@ -127,6 +136,7 @@ export const usePath = () => {
// if not, fetch get then determine if it is dir or file
const handlePathChange = (path: string, rp?: boolean, force?: boolean) => {
log(`handle [${path}] change`)
cancelObj?.()
cancelList?.()
retry_pass = rp ?? false
handleErr("")
Expand Down
15 changes: 11 additions & 4 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ import { r } from "."
export const fsGet = (
path: string = "/",
password = "",
cancelToken?: CancelToken,
): Promise<FsGetResp> => {
return r.post("/fs/get", {
path: path,
password: password,
})
return r.post(
"/fs/get",
{
path: path,
password: password,
},
{
cancelToken: cancelToken,
},
)
}
export const fsList = (
path: string = "/",
Expand Down