mirror of
https://github.com/OpenListTeam/OpenList-Frontend.git
synced 2026-03-13 11:20:24 +00:00
chore: fix typo
This commit is contained in:
3
.prettierrc
Normal file
3
.prettierrc
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"semi": false
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
import { Portal } from "solid-js/web";
|
import { Portal } from "solid-js/web";
|
||||||
import { useLoading, useRouter } from "~/hooks";
|
import { useLoading, useRouter } from "~/hooks";
|
||||||
import { globalStyles } from "./theme";
|
import { globalStyles } from "./theme";
|
||||||
import { bus, r, handleRrespWithoutAuthAndNotify, base_path } from "~/utils";
|
import { bus, r, handleRespWithoutAuthAndNotify, base_path } from "~/utils";
|
||||||
import { setSettings } from "~/store";
|
import { setSettings } from "~/store";
|
||||||
import { Error, FullScreenLoading } from "~/components";
|
import { Error, FullScreenLoading } from "~/components";
|
||||||
import { MustUser } from "./MustUser";
|
import { MustUser } from "./MustUser";
|
||||||
@@ -46,7 +46,7 @@ const App: Component = () => {
|
|||||||
loadedLangs.add(initialLang);
|
loadedLangs.add(initialLang);
|
||||||
})(),
|
})(),
|
||||||
(async () => {
|
(async () => {
|
||||||
handleRrespWithoutAuthAndNotify(
|
handleRespWithoutAuthAndNotify(
|
||||||
(await r.get("/public/settings")) as Resp<Record<string, string>>,
|
(await r.get("/public/settings")) as Resp<Record<string, string>>,
|
||||||
setSettings,
|
setSettings,
|
||||||
setErr
|
setErr
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ import { createSignal, JSXElement, Match, Switch } from "solid-js";
|
|||||||
import { Error, FullLoading, FullScreenLoading } from "~/components";
|
import { Error, FullLoading, FullScreenLoading } from "~/components";
|
||||||
import { useFetch } from "~/hooks";
|
import { useFetch } from "~/hooks";
|
||||||
import { setUser } from "~/store";
|
import { setUser } from "~/store";
|
||||||
import { r, handleRresp } from "~/utils";
|
import { r, handleResp } from "~/utils";
|
||||||
|
|
||||||
const MustUser = (props: { children: JSXElement }) => {
|
const MustUser = (props: { children: JSXElement }) => {
|
||||||
const [loading, data] = useFetch(() => r.get("/me"));
|
const [loading, data] = useFetch(() => r.get("/me"));
|
||||||
const [err, setErr] = createSignal<string>();
|
const [err, setErr] = createSignal<string>();
|
||||||
(async () => {
|
(async () => {
|
||||||
// const resp: Resp<User> = await data();
|
// const resp: Resp<User> = await data();
|
||||||
handleRresp(await data(), setUser, setErr);
|
handleResp(await data(), setUser, setErr);
|
||||||
})();
|
})();
|
||||||
return (
|
return (
|
||||||
<Switch fallback={props.children}>
|
<Switch fallback={props.children}>
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import {
|
|||||||
import { useFetch, useT } from "~/hooks";
|
import { useFetch, useT } from "~/hooks";
|
||||||
import { getMainColor, password } from "~/store";
|
import { getMainColor, password } from "~/store";
|
||||||
import { Obj, Resp } from "~/types";
|
import { Obj, Resp } from "~/types";
|
||||||
import { pathBase, handleRresp, hoverColor, pathJoin, fsDirs } from "~/utils";
|
import { pathBase, handleResp, hoverColor, pathJoin, fsDirs } from "~/utils";
|
||||||
|
|
||||||
export interface FolderTreeProps {
|
export interface FolderTreeProps {
|
||||||
onChange: (path: string) => void;
|
onChange: (path: string) => void;
|
||||||
@@ -68,7 +68,7 @@ const FolderTreeNode = (props: { path: string }) => {
|
|||||||
const load = async () => {
|
const load = async () => {
|
||||||
if (children().length > 0) return;
|
if (children().length > 0) return;
|
||||||
const resp: Resp<Obj[]> = await fetchDirs();
|
const resp: Resp<Obj[]> = await fetchDirs();
|
||||||
handleRresp(resp, setChildren);
|
handleResp(resp, setChildren);
|
||||||
};
|
};
|
||||||
const { isOpen, onToggle } = createDisclosure();
|
const { isOpen, onToggle } = createDisclosure();
|
||||||
const active = () => value() === props.path;
|
const active = () => value() === props.path;
|
||||||
|
|||||||
@@ -1,46 +1,44 @@
|
|||||||
import axios, { Canceler } from "axios";
|
import axios, { Canceler } from "axios"
|
||||||
import { createSignal } from "solid-js";
|
|
||||||
import {
|
import {
|
||||||
appendObjs,
|
appendObjs,
|
||||||
getSettingNumber,
|
|
||||||
password,
|
password,
|
||||||
ObjStore,
|
ObjStore,
|
||||||
State,
|
State,
|
||||||
getPagination,
|
getPagination,
|
||||||
objStore,
|
objStore,
|
||||||
} from "~/store";
|
} from "~/store"
|
||||||
import {
|
import {
|
||||||
fsGet,
|
fsGet,
|
||||||
fsList,
|
fsList,
|
||||||
handleRrespWithoutNotify,
|
handleRespWithoutNotify,
|
||||||
log,
|
log,
|
||||||
notify,
|
notify,
|
||||||
pathJoin,
|
pathJoin,
|
||||||
} from "~/utils";
|
} from "~/utils"
|
||||||
import { useFetch } from "./useFetch";
|
import { useFetch } from "./useFetch"
|
||||||
import { useRouter } from "./useRouter";
|
import { useRouter } from "./useRouter"
|
||||||
|
|
||||||
let cancelList: Canceler;
|
let cancelList: Canceler
|
||||||
const IsDirRecord: Record<string, boolean> = {};
|
const IsDirRecord: Record<string, boolean> = {}
|
||||||
let globalPage = 1;
|
let globalPage = 1
|
||||||
export const usePath = () => {
|
export const usePath = () => {
|
||||||
const { pathname, searchParams } = useRouter();
|
const { pathname, searchParams } = useRouter()
|
||||||
const [, getObj] = useFetch((path: string) => fsGet(path, password()));
|
const [, getObj] = useFetch((path: string) => fsGet(path, password()))
|
||||||
const pagination = getPagination();
|
const pagination = getPagination()
|
||||||
if (pagination.type === "pagination" && searchParams.page) {
|
if (pagination.type === "pagination" && searchParams.page) {
|
||||||
globalPage = parseInt(searchParams.page);
|
globalPage = parseInt(searchParams.page)
|
||||||
}
|
}
|
||||||
const [, getObjs] = useFetch(
|
const [, getObjs] = useFetch(
|
||||||
(arg?: {
|
(arg?: {
|
||||||
path: string;
|
path: string
|
||||||
index?: number;
|
index?: number
|
||||||
size?: number;
|
size?: number
|
||||||
force?: boolean;
|
force?: boolean
|
||||||
}) => {
|
}) => {
|
||||||
const page = {
|
const page = {
|
||||||
index: arg?.index,
|
index: arg?.index,
|
||||||
size: arg?.size,
|
size: arg?.size,
|
||||||
};
|
}
|
||||||
// setSearchParams(page);
|
// setSearchParams(page);
|
||||||
return fsList(
|
return fsList(
|
||||||
arg?.path,
|
arg?.path,
|
||||||
@@ -49,62 +47,62 @@ export const usePath = () => {
|
|||||||
page.size,
|
page.size,
|
||||||
arg?.force,
|
arg?.force,
|
||||||
new axios.CancelToken(function executor(c) {
|
new axios.CancelToken(function executor(c) {
|
||||||
cancelList = c;
|
cancelList = c
|
||||||
})
|
})
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
// set a path must be a dir
|
// set a path must be a dir
|
||||||
const setPathAs = (path: string, dir = true, push = false) => {
|
const setPathAs = (path: string, dir = true, push = false) => {
|
||||||
if (push) {
|
if (push) {
|
||||||
path = pathJoin(pathname(), path);
|
path = pathJoin(pathname(), path)
|
||||||
}
|
}
|
||||||
if (dir) {
|
if (dir) {
|
||||||
IsDirRecord[path] = true;
|
IsDirRecord[path] = true
|
||||||
} else {
|
} else {
|
||||||
delete IsDirRecord[path];
|
delete IsDirRecord[path]
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// record is second time password is wrong
|
// record is second time password is wrong
|
||||||
let retry_pass = false;
|
let retry_pass = false
|
||||||
// handle pathname change
|
// handle pathname change
|
||||||
// if confirm current path is dir, fetch List directly
|
// if confirm current path is dir, fetch List directly
|
||||||
// if not, fetch get then determine if it is dir or file
|
// if not, fetch get then determine if it is dir or file
|
||||||
const handlePathChange = (path: string, rp?: boolean, force?: boolean) => {
|
const handlePathChange = (path: string, rp?: boolean, force?: boolean) => {
|
||||||
log(`handle [${path}] change`);
|
log(`handle [${path}] change`)
|
||||||
cancelList?.();
|
cancelList?.()
|
||||||
retry_pass = rp ?? false;
|
retry_pass = rp ?? false
|
||||||
handleErr("");
|
handleErr("")
|
||||||
if (IsDirRecord[path]) {
|
if (IsDirRecord[path]) {
|
||||||
handleFolder(path, globalPage, undefined, undefined, force);
|
handleFolder(path, globalPage, undefined, undefined, force)
|
||||||
} else {
|
} else {
|
||||||
handleObj(path);
|
handleObj(path)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// handle enter obj that don't know if it is dir or file
|
// handle enter obj that don't know if it is dir or file
|
||||||
const handleObj = async (path: string) => {
|
const handleObj = async (path: string) => {
|
||||||
ObjStore.setState(State.FetchingObj);
|
ObjStore.setState(State.FetchingObj)
|
||||||
const resp = await getObj(path);
|
const resp = await getObj(path)
|
||||||
handleRrespWithoutNotify(
|
handleRespWithoutNotify(
|
||||||
resp,
|
resp,
|
||||||
(data) => {
|
(data) => {
|
||||||
ObjStore.setObj(data);
|
ObjStore.setObj(data)
|
||||||
ObjStore.setProvider(data.provider);
|
ObjStore.setProvider(data.provider)
|
||||||
if (data.is_dir) {
|
if (data.is_dir) {
|
||||||
setPathAs(path);
|
setPathAs(path)
|
||||||
handleFolder(path, globalPage);
|
handleFolder(path, globalPage)
|
||||||
} else {
|
} else {
|
||||||
ObjStore.setReadme(data.readme);
|
ObjStore.setReadme(data.readme)
|
||||||
ObjStore.setRelated(data.related ?? []);
|
ObjStore.setRelated(data.related ?? [])
|
||||||
ObjStore.setRawUrl(data.raw_url);
|
ObjStore.setRawUrl(data.raw_url)
|
||||||
ObjStore.setState(State.File);
|
ObjStore.setState(State.File)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleErr
|
handleErr
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
// change enter a folder or turn page or load more
|
// change enter a folder or turn page or load more
|
||||||
const handleFolder = async (
|
const handleFolder = async (
|
||||||
@@ -115,55 +113,55 @@ export const usePath = () => {
|
|||||||
force?: boolean
|
force?: boolean
|
||||||
) => {
|
) => {
|
||||||
if (!size) {
|
if (!size) {
|
||||||
size = pagination.size;
|
size = pagination.size
|
||||||
}
|
}
|
||||||
if (size !== undefined && pagination.type === "all") {
|
if (size !== undefined && pagination.type === "all") {
|
||||||
size = undefined;
|
size = undefined
|
||||||
}
|
}
|
||||||
globalPage = index ?? 1;
|
globalPage = index ?? 1
|
||||||
ObjStore.setState(append ? State.FetchingMore : State.FetchingObjs);
|
ObjStore.setState(append ? State.FetchingMore : State.FetchingObjs)
|
||||||
const resp = await getObjs({ path, index, size, force });
|
const resp = await getObjs({ path, index, size, force })
|
||||||
handleRrespWithoutNotify(
|
handleRespWithoutNotify(
|
||||||
resp,
|
resp,
|
||||||
(data) => {
|
(data) => {
|
||||||
if (append) {
|
if (append) {
|
||||||
appendObjs(data.content);
|
appendObjs(data.content)
|
||||||
} else {
|
} else {
|
||||||
ObjStore.setObjs(data.content ?? []);
|
ObjStore.setObjs(data.content ?? [])
|
||||||
ObjStore.setTotal(data.total);
|
ObjStore.setTotal(data.total)
|
||||||
}
|
}
|
||||||
ObjStore.setReadme(data.readme);
|
ObjStore.setReadme(data.readme)
|
||||||
ObjStore.setWrite(data.write);
|
ObjStore.setWrite(data.write)
|
||||||
ObjStore.setState(State.Folder);
|
ObjStore.setState(State.Folder)
|
||||||
},
|
},
|
||||||
handleErr
|
handleErr
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleErr = (msg: string, code?: number) => {
|
const handleErr = (msg: string, code?: number) => {
|
||||||
if (code === 403) {
|
if (code === 403) {
|
||||||
ObjStore.setState(State.NeedPassword);
|
ObjStore.setState(State.NeedPassword)
|
||||||
if (retry_pass) {
|
if (retry_pass) {
|
||||||
notify.error(msg);
|
notify.error(msg)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ObjStore.setErr(msg);
|
ObjStore.setErr(msg)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
const pageChange = (index?: number, size?: number, append = false) => {
|
const pageChange = (index?: number, size?: number, append = false) => {
|
||||||
handleFolder(pathname(), index, size, append);
|
handleFolder(pathname(), index, size, append)
|
||||||
};
|
}
|
||||||
return {
|
return {
|
||||||
handlePathChange,
|
handlePathChange,
|
||||||
setPathAs: setPathAs,
|
setPathAs: setPathAs,
|
||||||
refresh: (retry_pass?: boolean, force?: boolean) => {
|
refresh: (retry_pass?: boolean, force?: boolean) => {
|
||||||
handlePathChange(pathname(), retry_pass, force);
|
handlePathChange(pathname(), retry_pass, force)
|
||||||
},
|
},
|
||||||
pageChange: pageChange,
|
pageChange: pageChange,
|
||||||
page: globalPage,
|
page: globalPage,
|
||||||
loadMore: () => {
|
loadMore: () => {
|
||||||
pageChange(globalPage + 1, undefined, true);
|
pageChange(globalPage + 1, undefined, true)
|
||||||
},
|
},
|
||||||
allLoaded: () => globalPage >= Math.ceil(objStore.total / pagination.size),
|
allLoaded: () => globalPage >= Math.ceil(objStore.total / pagination.size),
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { MaybeLoading } from "~/components";
|
|||||||
import { useFetch, useRouter } from "~/hooks";
|
import { useFetch, useRouter } from "~/hooks";
|
||||||
import { password } from "~/store";
|
import { password } from "~/store";
|
||||||
import { Resp } from "~/types";
|
import { Resp } from "~/types";
|
||||||
import { handleRresp, r } from "~/utils";
|
import { handleResp, r } from "~/utils";
|
||||||
|
|
||||||
const AliDocPreview = () => {
|
const AliDocPreview = () => {
|
||||||
const { pathname } = useRouter();
|
const { pathname } = useRouter();
|
||||||
@@ -17,7 +17,7 @@ const AliDocPreview = () => {
|
|||||||
);
|
);
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
const resp = await post();
|
const resp = await post();
|
||||||
handleRresp(resp, (data) => {
|
handleResp(resp, (data) => {
|
||||||
const docOptions = aliyun.config({
|
const docOptions = aliyun.config({
|
||||||
mount: document.querySelector("#office-preview")!,
|
mount: document.querySelector("#office-preview")!,
|
||||||
url: data.preview_url,
|
url: data.preview_url,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { MonacoEditorLoader } from "~/components/MonacoEditor";
|
|||||||
import { useFetch, useFetchText, useRouter, useT } from "~/hooks";
|
import { useFetch, useFetchText, useRouter, useT } from "~/hooks";
|
||||||
import { objStore, userCan } from "~/store";
|
import { objStore, userCan } from "~/store";
|
||||||
import { EmptyResp } from "~/types";
|
import { EmptyResp } from "~/types";
|
||||||
import { handleRresp, notify, r } from "~/utils";
|
import { handleResp, notify, r } from "~/utils";
|
||||||
|
|
||||||
const TextEditor = () => {
|
const TextEditor = () => {
|
||||||
const [content] = useFetchText();
|
const [content] = useFetchText();
|
||||||
@@ -45,7 +45,7 @@ const TextEditor = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const resp = await save();
|
const resp = await save();
|
||||||
handleRresp(resp, () => {
|
handleResp(resp, () => {
|
||||||
notify.success(t("global.save_success"));
|
notify.success(t("global.save_success"));
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createDisclosure } from "@hope-ui/solid";
|
import { createDisclosure } from "@hope-ui/solid";
|
||||||
import { ModalInput } from "~/components";
|
import { ModalInput } from "~/components";
|
||||||
import { useFetch, useRouter, useT } from "~/hooks";
|
import { useFetch, useRouter, useT } from "~/hooks";
|
||||||
import { addAria2, bus, handleRrespWithNotifySuccess } from "~/utils";
|
import { addAria2, bus, handleRespWithNotifySuccess } from "~/utils";
|
||||||
import { onCleanup } from "solid-js";
|
import { onCleanup } from "solid-js";
|
||||||
|
|
||||||
export const Aria2 = () => {
|
export const Aria2 = () => {
|
||||||
@@ -28,7 +28,7 @@ export const Aria2 = () => {
|
|||||||
tips={t("home.toolbar.add_aria2-tips")}
|
tips={t("home.toolbar.add_aria2-tips")}
|
||||||
onSubmit={async (urls) => {
|
onSubmit={async (urls) => {
|
||||||
const resp = await ok(pathname(), urls.split("\n"));
|
const resp = await ok(pathname(), urls.split("\n"));
|
||||||
handleRrespWithNotifySuccess(resp, () => {
|
handleRespWithNotifySuccess(resp, () => {
|
||||||
onClose();
|
onClose();
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { onCleanup } from "solid-js";
|
|||||||
import { ModalFolderChoose } from "~/components";
|
import { ModalFolderChoose } from "~/components";
|
||||||
import { useFetch, usePath, useRouter } from "~/hooks";
|
import { useFetch, usePath, useRouter } from "~/hooks";
|
||||||
import { selectedObjs } from "~/store";
|
import { selectedObjs } from "~/store";
|
||||||
import { bus, fsCopy, fsMove, handleRrespWithNotifySuccess } from "~/utils";
|
import { bus, fsCopy, fsMove, handleRespWithNotifySuccess } from "~/utils";
|
||||||
|
|
||||||
export const Copy = () => {
|
export const Copy = () => {
|
||||||
const { isOpen, onOpen, onClose } = createDisclosure();
|
const { isOpen, onOpen, onClose } = createDisclosure();
|
||||||
@@ -30,7 +30,7 @@ export const Copy = () => {
|
|||||||
dst,
|
dst,
|
||||||
selectedObjs().map((obj) => obj.name)
|
selectedObjs().map((obj) => obj.name)
|
||||||
);
|
);
|
||||||
handleRrespWithNotifySuccess(resp, () => {
|
handleRespWithNotifySuccess(resp, () => {
|
||||||
refresh();
|
refresh();
|
||||||
onClose();
|
onClose();
|
||||||
});
|
});
|
||||||
@@ -64,7 +64,7 @@ export const Move = () => {
|
|||||||
dst,
|
dst,
|
||||||
selectedObjs().map((obj) => obj.name)
|
selectedObjs().map((obj) => obj.name)
|
||||||
);
|
);
|
||||||
handleRrespWithNotifySuccess(resp, () => {
|
handleRespWithNotifySuccess(resp, () => {
|
||||||
refresh();
|
refresh();
|
||||||
onClose();
|
onClose();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
import { onCleanup } from "solid-js";
|
import { onCleanup } from "solid-js";
|
||||||
import { useFetch, usePath, useRouter, useT } from "~/hooks";
|
import { useFetch, usePath, useRouter, useT } from "~/hooks";
|
||||||
import { selectedObjs } from "~/store";
|
import { selectedObjs } from "~/store";
|
||||||
import { bus, fsRemove, handleRrespWithNotifySuccess } from "~/utils";
|
import { bus, fsRemove, handleRespWithNotifySuccess } from "~/utils";
|
||||||
|
|
||||||
export const Delete = () => {
|
export const Delete = () => {
|
||||||
const t = useT();
|
const t = useT();
|
||||||
@@ -56,7 +56,7 @@ export const Delete = () => {
|
|||||||
pathname(),
|
pathname(),
|
||||||
selectedObjs().map((obj) => obj.name)
|
selectedObjs().map((obj) => obj.name)
|
||||||
);
|
);
|
||||||
handleRrespWithNotifySuccess(resp, () => {
|
handleRespWithNotifySuccess(resp, () => {
|
||||||
refresh();
|
refresh();
|
||||||
onClose();
|
onClose();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createDisclosure } from "@hope-ui/solid";
|
import { createDisclosure } from "@hope-ui/solid";
|
||||||
import { ModalInput } from "~/components";
|
import { ModalInput } from "~/components";
|
||||||
import { useFetch, usePath, useRouter } from "~/hooks";
|
import { useFetch, usePath, useRouter } from "~/hooks";
|
||||||
import { bus, fsMkdir, handleRrespWithNotifySuccess, pathJoin } from "~/utils";
|
import { bus, fsMkdir, handleRespWithNotifySuccess, pathJoin } from "~/utils";
|
||||||
import { onCleanup } from "solid-js";
|
import { onCleanup } from "solid-js";
|
||||||
|
|
||||||
export const Mkdir = () => {
|
export const Mkdir = () => {
|
||||||
@@ -26,7 +26,7 @@ export const Mkdir = () => {
|
|||||||
loading={loading()}
|
loading={loading()}
|
||||||
onSubmit={async (name) => {
|
onSubmit={async (name) => {
|
||||||
const resp = await ok(pathJoin(pathname(), name));
|
const resp = await ok(pathJoin(pathname(), name));
|
||||||
handleRrespWithNotifySuccess(resp, () => {
|
handleRespWithNotifySuccess(resp, () => {
|
||||||
refresh();
|
refresh();
|
||||||
onClose();
|
onClose();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useFetch, usePath, useRouter } from "~/hooks";
|
|||||||
import {
|
import {
|
||||||
bus,
|
bus,
|
||||||
fsNewFile,
|
fsNewFile,
|
||||||
handleRrespWithNotifySuccess,
|
handleRespWithNotifySuccess,
|
||||||
pathJoin,
|
pathJoin,
|
||||||
} from "~/utils";
|
} from "~/utils";
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ export const NewFile = () => {
|
|||||||
loading={loading()}
|
loading={loading()}
|
||||||
onSubmit={async (name) => {
|
onSubmit={async (name) => {
|
||||||
const resp = await ok(pathJoin(pathname(), name));
|
const resp = await ok(pathJoin(pathname(), name));
|
||||||
handleRrespWithNotifySuccess(resp, () => {
|
handleRespWithNotifySuccess(resp, () => {
|
||||||
refresh();
|
refresh();
|
||||||
onClose();
|
onClose();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { oneChecked, selectedObjs } from "~/store";
|
|||||||
import {
|
import {
|
||||||
bus,
|
bus,
|
||||||
fsRename,
|
fsRename,
|
||||||
handleRrespWithNotifySuccess,
|
handleRespWithNotifySuccess,
|
||||||
notify,
|
notify,
|
||||||
pathJoin,
|
pathJoin,
|
||||||
} from "~/utils";
|
} from "~/utils";
|
||||||
@@ -43,7 +43,7 @@ export const Rename = () => {
|
|||||||
pathJoin(pathname(), selectedObjs()[0].name),
|
pathJoin(pathname(), selectedObjs()[0].name),
|
||||||
name
|
name
|
||||||
);
|
);
|
||||||
handleRrespWithNotifySuccess(resp, () => {
|
handleRespWithNotifySuccess(resp, () => {
|
||||||
refresh();
|
refresh();
|
||||||
onClose();
|
onClose();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
import { createSignal, Show } from "solid-js";
|
import { createSignal, Show } from "solid-js";
|
||||||
import { SwitchColorMode, SwitchLnaguageWhite } from "~/components";
|
import { SwitchColorMode, SwitchLnaguageWhite } from "~/components";
|
||||||
import { useFetch, useT, useTitle, useRouter } from "~/hooks";
|
import { useFetch, useT, useTitle, useRouter } from "~/hooks";
|
||||||
import { changeToken, r, notify, handleRrespWithoutNotify } from "~/utils";
|
import { changeToken, r, notify, handleRespWithoutNotify } from "~/utils";
|
||||||
import { Resp } from "~/types";
|
import { Resp } from "~/types";
|
||||||
import LoginBg from "./LoginBg";
|
import LoginBg from "./LoginBg";
|
||||||
import { createStorageSignal } from "@solid-primitives/storage";
|
import { createStorageSignal } from "@solid-primitives/storage";
|
||||||
@@ -49,7 +49,7 @@ const Login = () => {
|
|||||||
localStorage.removeItem("password");
|
localStorage.removeItem("password");
|
||||||
}
|
}
|
||||||
const resp = await data();
|
const resp = await data();
|
||||||
handleRrespWithoutNotify(
|
handleRespWithoutNotify(
|
||||||
resp,
|
resp,
|
||||||
(data) => {
|
(data) => {
|
||||||
notify.success(t("login.success"));
|
notify.success(t("login.success"));
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
HStack,
|
HStack,
|
||||||
} from "@hope-ui/solid";
|
} from "@hope-ui/solid";
|
||||||
import { useT } from "~/hooks";
|
import { useT } from "~/hooks";
|
||||||
import { handleRresp, notify } from "~/utils";
|
import { handleResp, notify } from "~/utils";
|
||||||
|
|
||||||
export interface DeletePopoverProps {
|
export interface DeletePopoverProps {
|
||||||
name: string;
|
name: string;
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import { Dynamic } from "solid-js/web";
|
|||||||
import { useFetch, useT } from "~/hooks";
|
import { useFetch, useT } from "~/hooks";
|
||||||
import { Resp } from "~/types";
|
import { Resp } from "~/types";
|
||||||
import {
|
import {
|
||||||
handleRrespWithNotifySuccess,
|
handleRespWithNotifySuccess,
|
||||||
handleRrespWithoutNotify,
|
handleRespWithoutNotify,
|
||||||
notify,
|
notify,
|
||||||
r,
|
r,
|
||||||
} from "~/utils";
|
} from "~/utils";
|
||||||
@@ -35,13 +35,13 @@ export const Messenger = () => {
|
|||||||
const [recieved, setRecieved] = createStore<Message[]>([]);
|
const [recieved, setRecieved] = createStore<Message[]>([]);
|
||||||
const get = async () => {
|
const get = async () => {
|
||||||
const resp: Resp<Message> = await getR();
|
const resp: Resp<Message> = await getR();
|
||||||
handleRrespWithoutNotify(resp, (msg) => {
|
handleRespWithoutNotify(resp, (msg) => {
|
||||||
setRecieved(produce((msgs) => msgs.push(msg)));
|
setRecieved(produce((msgs) => msgs.push(msg)));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const send = async () => {
|
const send = async () => {
|
||||||
const resp = await sendR();
|
const resp = await sendR();
|
||||||
handleRrespWithNotifySuccess(resp);
|
handleRespWithNotifySuccess(resp);
|
||||||
};
|
};
|
||||||
const getInterval = setInterval(get, 1000);
|
const getInterval = setInterval(get, 1000);
|
||||||
onCleanup(() => clearInterval(getInterval));
|
onCleanup(() => clearInterval(getInterval));
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
} from "@hope-ui/solid";
|
} from "@hope-ui/solid";
|
||||||
import { MaybeLoading, FolderChooseInput } from "~/components";
|
import { MaybeLoading, FolderChooseInput } from "~/components";
|
||||||
import { useFetch, useRouter, useT } from "~/hooks";
|
import { useFetch, useRouter, useT } from "~/hooks";
|
||||||
import { handleRresp, notify, r } from "~/utils";
|
import { handleResp, notify, r } from "~/utils";
|
||||||
import { Resp, Meta, EmptyResp } from "~/types";
|
import { Resp, Meta, EmptyResp } from "~/types";
|
||||||
import { createStore } from "solid-js/store";
|
import { createStore } from "solid-js/store";
|
||||||
import { For, Show } from "solid-js";
|
import { For, Show } from "solid-js";
|
||||||
@@ -103,7 +103,7 @@ const AddOrEdit = () => {
|
|||||||
|
|
||||||
const initEdit = async () => {
|
const initEdit = async () => {
|
||||||
const resp = await loadMeta();
|
const resp = await loadMeta();
|
||||||
handleRresp(resp, setMeta);
|
handleResp(resp, setMeta);
|
||||||
};
|
};
|
||||||
if (id) {
|
if (id) {
|
||||||
initEdit();
|
initEdit();
|
||||||
@@ -168,7 +168,7 @@ const AddOrEdit = () => {
|
|||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const resp = await ok();
|
const resp = await ok();
|
||||||
// TODO mybe can use handleRrespWithNotifySuccess
|
// TODO mybe can use handleRrespWithNotifySuccess
|
||||||
handleRresp(resp, () => {
|
handleResp(resp, () => {
|
||||||
notify.success(t("global.save_success"));
|
notify.success(t("global.save_success"));
|
||||||
back();
|
back();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
useRouter,
|
useRouter,
|
||||||
useT,
|
useT,
|
||||||
} from "~/hooks";
|
} from "~/hooks";
|
||||||
import { handleRresp, notify, r } from "~/utils";
|
import { handleResp, notify, r } from "~/utils";
|
||||||
import { Meta, PageResp } from "~/types";
|
import { Meta, PageResp } from "~/types";
|
||||||
import { DeletePopover } from "../common/DeletePopover";
|
import { DeletePopover } from "../common/DeletePopover";
|
||||||
import { Wether } from "~/components";
|
import { Wether } from "~/components";
|
||||||
@@ -31,7 +31,7 @@ const Metas = () => {
|
|||||||
const [metas, setMetas] = createSignal<Meta[]>([]);
|
const [metas, setMetas] = createSignal<Meta[]>([]);
|
||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
const resp: PageResp<Meta> = await getMetas();
|
const resp: PageResp<Meta> = await getMetas();
|
||||||
handleRresp(resp, (data) => setMetas(data.content));
|
handleResp(resp, (data) => setMetas(data.content));
|
||||||
};
|
};
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ const Metas = () => {
|
|||||||
loading={deleting() === meta.id}
|
loading={deleting() === meta.id}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const resp = await deleteMeta(meta.id);
|
const resp = await deleteMeta(meta.id);
|
||||||
handleRresp(resp, () => {
|
handleResp(resp, () => {
|
||||||
notify.success(t("global.delete_success"));
|
notify.success(t("global.delete_success"));
|
||||||
refresh();
|
refresh();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useFetch, useT, useRouter, useManageTitle } from "~/hooks";
|
import { useFetch, useT, useRouter, useManageTitle } from "~/hooks";
|
||||||
import { Group, SettingItem, Resp } from "~/types";
|
import { Group, SettingItem, Resp } from "~/types";
|
||||||
import { r, notify, getTarget, handleRresp } from "~/utils";
|
import { r, notify, getTarget, handleResp } from "~/utils";
|
||||||
import { createStore } from "solid-js/store";
|
import { createStore } from "solid-js/store";
|
||||||
import { Button, HStack, VStack } from "@hope-ui/solid";
|
import { Button, HStack, VStack } from "@hope-ui/solid";
|
||||||
import { createSignal, Index } from "solid-js";
|
import { createSignal, Index } from "solid-js";
|
||||||
@@ -20,7 +20,7 @@ const CommonSettings = (props: CommonSettingsProps) => {
|
|||||||
const [settings, setSettings] = createStore<SettingItem[]>([]);
|
const [settings, setSettings] = createStore<SettingItem[]>([]);
|
||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
const resp: Resp<SettingItem[]> = await getSettings();
|
const resp: Resp<SettingItem[]> = await getSettings();
|
||||||
handleRresp(resp, setSettings);
|
handleResp(resp, setSettings);
|
||||||
};
|
};
|
||||||
refresh();
|
refresh();
|
||||||
const [saveLoading, saveSettings] = useFetch(() =>
|
const [saveLoading, saveSettings] = useFetch(() =>
|
||||||
@@ -43,7 +43,7 @@ const CommonSettings = (props: CommonSettingsProps) => {
|
|||||||
`/admin/setting/delete?key=${item().key}`
|
`/admin/setting/delete?key=${item().key}`
|
||||||
);
|
);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
handleRresp(resp, () => {
|
handleResp(resp, () => {
|
||||||
notify.success(t("global.delete_success"));
|
notify.success(t("global.delete_success"));
|
||||||
refresh();
|
refresh();
|
||||||
});
|
});
|
||||||
@@ -64,7 +64,7 @@ const CommonSettings = (props: CommonSettingsProps) => {
|
|||||||
loading={saveLoading()}
|
loading={saveLoading()}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const resp: Resp<{}> = await saveSettings();
|
const resp: Resp<{}> = await saveSettings();
|
||||||
handleRresp(resp, () => notify.success(t("global.save_success")));
|
handleResp(resp, () => notify.success(t("global.save_success")));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t("global.save")}
|
{t("global.save")}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { createSignal } from "solid-js";
|
|||||||
import { MaybeLoading } from "~/components";
|
import { MaybeLoading } from "~/components";
|
||||||
import { useFetch, useManageTitle, useT, useUtil } from "~/hooks";
|
import { useFetch, useManageTitle, useT, useUtil } from "~/hooks";
|
||||||
import { Resp, Group, SettingItem } from "~/types";
|
import { Resp, Group, SettingItem } from "~/types";
|
||||||
import { handleRresp, notify, r } from "~/utils";
|
import { handleResp, notify, r } from "~/utils";
|
||||||
import { Item } from "./SettingItem";
|
import { Item } from "./SettingItem";
|
||||||
|
|
||||||
const OtherSettings = () => {
|
const OtherSettings = () => {
|
||||||
@@ -21,7 +21,7 @@ const OtherSettings = () => {
|
|||||||
);
|
);
|
||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
const resp: Resp<SettingItem[]> = await settingsData();
|
const resp: Resp<SettingItem[]> = await settingsData();
|
||||||
handleRresp(resp, (data) => {
|
handleResp(resp, (data) => {
|
||||||
setUri(data.find((i) => i.key === "aria2_uri")?.value || "");
|
setUri(data.find((i) => i.key === "aria2_uri")?.value || "");
|
||||||
setSecret(data.find((i) => i.key === "aria2_secret")?.value || "");
|
setSecret(data.find((i) => i.key === "aria2_secret")?.value || "");
|
||||||
setToken(data.find((i) => i.key === "token")?.value || "");
|
setToken(data.find((i) => i.key === "token")?.value || "");
|
||||||
@@ -53,7 +53,7 @@ const OtherSettings = () => {
|
|||||||
loading={setAria2Loading()}
|
loading={setAria2Loading()}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const resp: Resp<string> = await setAria2();
|
const resp: Resp<string> = await setAria2();
|
||||||
handleRresp(resp, (data) => {
|
handleResp(resp, (data) => {
|
||||||
notify.success(`${t("settings_other.aria2_version")} ${data}`);
|
notify.success(`${t("settings_other.aria2_version")} ${data}`);
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
@@ -75,7 +75,7 @@ const OtherSettings = () => {
|
|||||||
loading={resetTokenLoading()}
|
loading={resetTokenLoading()}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const resp: Resp<string> = await resetToken();
|
const resp: Resp<string> = await resetToken();
|
||||||
handleRresp(resp, (data) => {
|
handleResp(resp, (data) => {
|
||||||
notify.success(t("settings_other.reset_token_success"));
|
notify.success(t("settings_other.reset_token_success"));
|
||||||
setToken(data);
|
setToken(data);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Button, Heading } from "@hope-ui/solid";
|
|||||||
import { createSignal, For, Show } from "solid-js";
|
import { createSignal, For, Show } from "solid-js";
|
||||||
import { MaybeLoading } from "~/components";
|
import { MaybeLoading } from "~/components";
|
||||||
import { useFetch, useRouter, useT } from "~/hooks";
|
import { useFetch, useRouter, useT } from "~/hooks";
|
||||||
import { handleRresp, joinBase, notify, r } from "~/utils";
|
import { handleResp, joinBase, notify, r } from "~/utils";
|
||||||
import {
|
import {
|
||||||
Addition,
|
Addition,
|
||||||
DriverConfig,
|
DriverConfig,
|
||||||
@@ -54,7 +54,7 @@ const AddOrEdit = () => {
|
|||||||
const [drivers, setDrivers] = createSignal<Drivers>({});
|
const [drivers, setDrivers] = createSignal<Drivers>({});
|
||||||
const initAdd = async () => {
|
const initAdd = async () => {
|
||||||
const resp: Resp<Drivers> = await loadDrivers();
|
const resp: Resp<Drivers> = await loadDrivers();
|
||||||
handleRresp(resp, setDrivers);
|
handleResp(resp, setDrivers);
|
||||||
};
|
};
|
||||||
|
|
||||||
const [storageLoading, loadStorage] = useFetch(
|
const [storageLoading, loadStorage] = useFetch(
|
||||||
@@ -67,11 +67,11 @@ const AddOrEdit = () => {
|
|||||||
);
|
);
|
||||||
const initEdit = async () => {
|
const initEdit = async () => {
|
||||||
const storageResp: Resp<Storage> = await loadStorage();
|
const storageResp: Resp<Storage> = await loadStorage();
|
||||||
handleRresp(storageResp, async (storageData) => {
|
handleResp(storageResp, async (storageData) => {
|
||||||
setStorage(storageData);
|
setStorage(storageData);
|
||||||
setAddition(JSON.parse(storageData.addition));
|
setAddition(JSON.parse(storageData.addition));
|
||||||
const driverResp: Resp<DriverInfo> = await loadDriver();
|
const driverResp: Resp<DriverInfo> = await loadDriver();
|
||||||
handleRresp(driverResp, (driverData) =>
|
handleResp(driverResp, (driverData) =>
|
||||||
setDrivers({ [storage.driver]: driverData })
|
setDrivers({ [storage.driver]: driverData })
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -165,7 +165,7 @@ const AddOrEdit = () => {
|
|||||||
}
|
}
|
||||||
const resp: Resp<{}> = await ok();
|
const resp: Resp<{}> = await ok();
|
||||||
// TODO mybe can use handleRrespWithNotifySuccess
|
// TODO mybe can use handleRrespWithNotifySuccess
|
||||||
handleRresp(resp, () => {
|
handleResp(resp, () => {
|
||||||
notify.success(t("global.save_success"));
|
notify.success(t("global.save_success"));
|
||||||
back();
|
back();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
useRouter,
|
useRouter,
|
||||||
useT,
|
useT,
|
||||||
} from "~/hooks";
|
} from "~/hooks";
|
||||||
import { handleRresp, handleRrespWithNotifySuccess, notify, r } from "~/utils";
|
import { handleResp, handleRespWithNotifySuccess, notify, r } from "~/utils";
|
||||||
import { PageResp, Storage } from "~/types";
|
import { PageResp, Storage } from "~/types";
|
||||||
import { DeletePopover } from "../common/DeletePopover";
|
import { DeletePopover } from "../common/DeletePopover";
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ const Storages = () => {
|
|||||||
const [storages, setStorages] = createSignal<Storage[]>([]);
|
const [storages, setStorages] = createSignal<Storage[]>([]);
|
||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
const resp: PageResp<Storage> = await getStorages();
|
const resp: PageResp<Storage> = await getStorages();
|
||||||
handleRresp(resp, (data) => setStorages(data.content));
|
handleResp(resp, (data) => setStorages(data.content));
|
||||||
};
|
};
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ const Storages = () => {
|
|||||||
storage.id,
|
storage.id,
|
||||||
storage
|
storage
|
||||||
);
|
);
|
||||||
handleRrespWithNotifySuccess(resp, () => {
|
handleRespWithNotifySuccess(resp, () => {
|
||||||
refresh();
|
refresh();
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
@@ -113,7 +113,7 @@ const Storages = () => {
|
|||||||
loading={deleting() === storage.id}
|
loading={deleting() === storage.id}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const resp = await deleteStorage(storage.id);
|
const resp = await deleteStorage(storage.id);
|
||||||
handleRresp(resp, () => {
|
handleResp(resp, () => {
|
||||||
notify.success(t("global.delete_success"));
|
notify.success(t("global.delete_success"));
|
||||||
refresh();
|
refresh();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
import { createSignal, Show } from "solid-js";
|
import { createSignal, Show } from "solid-js";
|
||||||
import { useT, useFetch } from "~/hooks";
|
import { useT, useFetch } from "~/hooks";
|
||||||
import { TaskInfo } from "~/types";
|
import { TaskInfo } from "~/types";
|
||||||
import { handleRresp, notify, r } from "~/utils";
|
import { handleResp, notify, r } from "~/utils";
|
||||||
import { TasksProps } from "./Tasks";
|
import { TasksProps } from "./Tasks";
|
||||||
|
|
||||||
const StateMap: Record<
|
const StateMap: Record<
|
||||||
@@ -102,7 +102,7 @@ export const Task = (props: TaskInfo & TasksProps) => {
|
|||||||
loading={operateLoading()}
|
loading={operateLoading()}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const resp = await operate();
|
const resp = await operate();
|
||||||
handleRresp(resp, () => {
|
handleResp(resp, () => {
|
||||||
notify.success(t("global.delete_success"));
|
notify.success(t("global.delete_success"));
|
||||||
setDeleted(true);
|
setDeleted(true);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Button, Heading, HStack, VStack } from "@hope-ui/solid";
|
|||||||
import { createSignal, For, onCleanup, Show } from "solid-js";
|
import { createSignal, For, onCleanup, Show } from "solid-js";
|
||||||
import { useFetch, useT } from "~/hooks";
|
import { useFetch, useT } from "~/hooks";
|
||||||
import { Resp, TaskInfo } from "~/types";
|
import { Resp, TaskInfo } from "~/types";
|
||||||
import { handleRresp, r } from "~/utils";
|
import { handleResp, r } from "~/utils";
|
||||||
import { Task } from "./Task";
|
import { Task } from "./Task";
|
||||||
|
|
||||||
export interface TasksProps {
|
export interface TasksProps {
|
||||||
@@ -17,7 +17,7 @@ export const Tasks = (props: TasksProps) => {
|
|||||||
const [tasks, setTasks] = createSignal<TaskInfo[]>([]);
|
const [tasks, setTasks] = createSignal<TaskInfo[]>([]);
|
||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
const resp: Resp<TaskInfo[]> = await get();
|
const resp: Resp<TaskInfo[]> = await get();
|
||||||
handleRresp(resp, (data) =>
|
handleResp(resp, (data) =>
|
||||||
setTasks(
|
setTasks(
|
||||||
data?.sort((a, b) => {
|
data?.sort((a, b) => {
|
||||||
if (a.id > b.id) {
|
if (a.id > b.id) {
|
||||||
@@ -48,7 +48,7 @@ export const Tasks = (props: TasksProps) => {
|
|||||||
loading={clearLoading()}
|
loading={clearLoading()}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const resp = await clear();
|
const resp = await clear();
|
||||||
handleRresp(resp, () => refresh());
|
handleResp(resp, () => refresh());
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t(`global.clear`)}
|
{t(`global.clear`)}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { MaybeLoading } from "~/components";
|
|||||||
import { useRouter, useFetch, useT } from "~/hooks";
|
import { useRouter, useFetch, useT } from "~/hooks";
|
||||||
import { setUser, user } from "~/store";
|
import { setUser, user } from "~/store";
|
||||||
import { Resp } from "~/types";
|
import { Resp } from "~/types";
|
||||||
import { handleRresp, handleRrespWithNotifySuccess, notify, r } from "~/utils";
|
import { handleResp, handleRespWithNotifySuccess, notify, r } from "~/utils";
|
||||||
|
|
||||||
interface Generate2FA {
|
interface Generate2FA {
|
||||||
qr: string;
|
qr: string;
|
||||||
@@ -25,7 +25,7 @@ const TwoFA = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const resp: Resp<Generate2FA> = await generate();
|
const resp: Resp<Generate2FA> = await generate();
|
||||||
handleRresp(resp, setOtpData);
|
handleResp(resp, setOtpData);
|
||||||
};
|
};
|
||||||
const [code, setCode] = createSignal("");
|
const [code, setCode] = createSignal("");
|
||||||
init();
|
init();
|
||||||
@@ -37,7 +37,7 @@ const TwoFA = () => {
|
|||||||
);
|
);
|
||||||
const verify2FA = async () => {
|
const verify2FA = async () => {
|
||||||
const resp = await verify();
|
const resp = await verify();
|
||||||
handleRrespWithNotifySuccess(resp, () => {
|
handleRespWithNotifySuccess(resp, () => {
|
||||||
setUser({ ...user(), otp: true });
|
setUser({ ...user(), otp: true });
|
||||||
back();
|
back();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
} from "@hope-ui/solid";
|
} from "@hope-ui/solid";
|
||||||
import { MaybeLoading, FolderChooseInput } from "~/components";
|
import { MaybeLoading, FolderChooseInput } from "~/components";
|
||||||
import { useFetch, useRouter, useT } from "~/hooks";
|
import { useFetch, useRouter, useT } from "~/hooks";
|
||||||
import { handleRresp, notify, r } from "~/utils";
|
import { handleResp, notify, r } from "~/utils";
|
||||||
import { Resp, User, UserMethods, UserPermissions } from "~/types";
|
import { Resp, User, UserMethods, UserPermissions } from "~/types";
|
||||||
import { createStore } from "solid-js/store";
|
import { createStore } from "solid-js/store";
|
||||||
import { For } from "solid-js";
|
import { For } from "solid-js";
|
||||||
@@ -59,7 +59,7 @@ const AddOrEdit = () => {
|
|||||||
|
|
||||||
const initEdit = async () => {
|
const initEdit = async () => {
|
||||||
const resp: Resp<User> = await loadUser();
|
const resp: Resp<User> = await loadUser();
|
||||||
handleRresp(resp, setUser);
|
handleResp(resp, setUser);
|
||||||
};
|
};
|
||||||
if (id) {
|
if (id) {
|
||||||
initEdit();
|
initEdit();
|
||||||
@@ -130,7 +130,7 @@ const AddOrEdit = () => {
|
|||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const resp: Resp<{}> = await ok();
|
const resp: Resp<{}> = await ok();
|
||||||
// TODO mybe can use handleRrespWithNotifySuccess
|
// TODO mybe can use handleRrespWithNotifySuccess
|
||||||
handleRresp(resp, () => {
|
handleResp(resp, () => {
|
||||||
notify.success(t("global.save_success"));
|
notify.success(t("global.save_success"));
|
||||||
back();
|
back();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import { LinkWithBase } from "~/components";
|
|||||||
import { useFetch, useManageTitle, useRouter, useT } from "~/hooks";
|
import { useFetch, useManageTitle, useRouter, useT } from "~/hooks";
|
||||||
import { setUser, user } from "~/store";
|
import { setUser, user } from "~/store";
|
||||||
import { UserMethods, UserPermissions } from "~/types";
|
import { UserMethods, UserPermissions } from "~/types";
|
||||||
import { handleRresp, notify, r } from "~/utils";
|
import { handleResp, notify, r } from "~/utils";
|
||||||
|
|
||||||
const PermissionBadge = (props: { can: boolean; children: JSXElement }) => {
|
const PermissionBadge = (props: { can: boolean; children: JSXElement }) => {
|
||||||
return (
|
return (
|
||||||
@@ -105,7 +105,7 @@ const Profile = () => {
|
|||||||
loading={loading()}
|
loading={loading()}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const resp = await save();
|
const resp = await save();
|
||||||
handleRresp(resp, () => {
|
handleResp(resp, () => {
|
||||||
setUser({ ...user(), username: username() });
|
setUser({ ...user(), username: username() });
|
||||||
notify.success(t("users.update_profile_success"));
|
notify.success(t("users.update_profile_success"));
|
||||||
to(`/@login?redirect=${encodeURIComponent(location.pathname)}`);
|
to(`/@login?redirect=${encodeURIComponent(location.pathname)}`);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import {
|
|||||||
useRouter,
|
useRouter,
|
||||||
useT,
|
useT,
|
||||||
} from "~/hooks";
|
} from "~/hooks";
|
||||||
import { handleRresp, notify, r } from "~/utils";
|
import { handleResp, notify, r } from "~/utils";
|
||||||
import { PageResp, UserPermissions, User, UserMethods } from "~/types";
|
import { PageResp, UserPermissions, User, UserMethods } from "~/types";
|
||||||
import { DeletePopover } from "../common/DeletePopover";
|
import { DeletePopover } from "../common/DeletePopover";
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ const Users = () => {
|
|||||||
const [users, setUsers] = createSignal<User[]>([]);
|
const [users, setUsers] = createSignal<User[]>([]);
|
||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
const resp: PageResp<User> = await getUsers();
|
const resp: PageResp<User> = await getUsers();
|
||||||
handleRresp(resp, (data) => setUsers(data.content));
|
handleResp(resp, (data) => setUsers(data.content));
|
||||||
};
|
};
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ const Users = () => {
|
|||||||
loading={deleting() === user.id}
|
loading={deleting() === user.id}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const resp = await deleteUser(user.id);
|
const resp = await deleteUser(user.id);
|
||||||
handleRresp(resp, () => {
|
handleResp(resp, () => {
|
||||||
notify.success(t("global.delete_success"));
|
notify.success(t("global.delete_success"));
|
||||||
refresh();
|
refresh();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Resp } from "~/types";
|
import { Resp } from "~/types"
|
||||||
import { bus, notify } from ".";
|
import { bus, notify } from "."
|
||||||
|
|
||||||
export const handleRresp = <T>(
|
export const handleResp = <T>(
|
||||||
resp: Resp<T>,
|
resp: Resp<T>,
|
||||||
success?: (data: T) => void,
|
success?: (data: T) => void,
|
||||||
fail?: (message: string, code: number) => void,
|
fail?: (message: string, code: number) => void,
|
||||||
@@ -10,53 +10,53 @@ export const handleRresp = <T>(
|
|||||||
notify_success?: boolean
|
notify_success?: boolean
|
||||||
) => {
|
) => {
|
||||||
if (resp.code === 200) {
|
if (resp.code === 200) {
|
||||||
notify_success && notify.success(resp.message);
|
notify_success && notify.success(resp.message)
|
||||||
success?.(resp.data);
|
success?.(resp.data)
|
||||||
} else {
|
} else {
|
||||||
notify_error && notify.error(resp.message);
|
notify_error && notify.error(resp.message)
|
||||||
if (auth && resp.code === 401) {
|
if (auth && resp.code === 401) {
|
||||||
bus.emit(
|
bus.emit(
|
||||||
"to",
|
"to",
|
||||||
`/@login?redirect=${encodeURIComponent(location.pathname)}`
|
`/@login?redirect=${encodeURIComponent(location.pathname)}`
|
||||||
);
|
)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
fail?.(resp.message, resp.code);
|
fail?.(resp.message, resp.code)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handleRrespWithoutAuth = <T>(
|
export const handleRespWithoutAuth = <T>(
|
||||||
resp: Resp<T>,
|
resp: Resp<T>,
|
||||||
success?: (data: T) => void,
|
success?: (data: T) => void,
|
||||||
fail?: (message: string, code?: number) => void,
|
fail?: (message: string, code?: number) => void,
|
||||||
notify_error: boolean = true
|
notify_error: boolean = true
|
||||||
) => {
|
) => {
|
||||||
return handleRresp(resp, success, fail, false, notify_error);
|
return handleResp(resp, success, fail, false, notify_error)
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handleRrespWithoutNotify = <T>(
|
export const handleRespWithoutNotify = <T>(
|
||||||
resp: Resp<T>,
|
resp: Resp<T>,
|
||||||
success?: (data: T) => void,
|
success?: (data: T) => void,
|
||||||
fail?: (message: string, code?: number) => void,
|
fail?: (message: string, code?: number) => void,
|
||||||
auth: boolean = true
|
auth: boolean = true
|
||||||
) => {
|
) => {
|
||||||
return handleRresp(resp, success, fail, auth, false);
|
return handleResp(resp, success, fail, auth, false)
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handleRrespWithoutAuthAndNotify = <T>(
|
export const handleRespWithoutAuthAndNotify = <T>(
|
||||||
resp: Resp<T>,
|
resp: Resp<T>,
|
||||||
success?: (data: T) => void,
|
success?: (data: T) => void,
|
||||||
fail?: (message: string, code?: number) => void
|
fail?: (message: string, code?: number) => void
|
||||||
) => {
|
) => {
|
||||||
return handleRresp(resp, success, fail, false, false);
|
return handleResp(resp, success, fail, false, false)
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handleRrespWithNotifySuccess = <T>(
|
export const handleRespWithNotifySuccess = <T>(
|
||||||
resp: Resp<T>,
|
resp: Resp<T>,
|
||||||
success?: (data: T) => void,
|
success?: (data: T) => void,
|
||||||
fail?: (message: string, code?: number) => void,
|
fail?: (message: string, code?: number) => void,
|
||||||
auth: boolean = true,
|
auth: boolean = true,
|
||||||
notify_error: boolean = true
|
notify_error: boolean = true
|
||||||
) => {
|
) => {
|
||||||
return handleRresp(resp, success, fail, auth, notify_error, true);
|
return handleResp(resp, success, fail, auth, notify_error, true)
|
||||||
};
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user