diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..cce9d3c --- /dev/null +++ b/.prettierrc @@ -0,0 +1,3 @@ +{ + "semi": false +} diff --git a/src/app/App.tsx b/src/app/App.tsx index ab819b5..5ddfe7f 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -11,7 +11,7 @@ import { import { Portal } from "solid-js/web"; import { useLoading, useRouter } from "~/hooks"; 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 { Error, FullScreenLoading } from "~/components"; import { MustUser } from "./MustUser"; @@ -46,7 +46,7 @@ const App: Component = () => { loadedLangs.add(initialLang); })(), (async () => { - handleRrespWithoutAuthAndNotify( + handleRespWithoutAuthAndNotify( (await r.get("/public/settings")) as Resp>, setSettings, setErr diff --git a/src/app/MustUser.tsx b/src/app/MustUser.tsx index 3174290..8865451 100644 --- a/src/app/MustUser.tsx +++ b/src/app/MustUser.tsx @@ -3,14 +3,14 @@ import { createSignal, JSXElement, Match, Switch } from "solid-js"; import { Error, FullLoading, FullScreenLoading } from "~/components"; import { useFetch } from "~/hooks"; import { setUser } from "~/store"; -import { r, handleRresp } from "~/utils"; +import { r, handleResp } from "~/utils"; const MustUser = (props: { children: JSXElement }) => { const [loading, data] = useFetch(() => r.get("/me")); const [err, setErr] = createSignal(); (async () => { // const resp: Resp = await data(); - handleRresp(await data(), setUser, setErr); + handleResp(await data(), setUser, setErr); })(); return ( diff --git a/src/components/FolderTree.tsx b/src/components/FolderTree.tsx index 106357d..0e2abc2 100644 --- a/src/components/FolderTree.tsx +++ b/src/components/FolderTree.tsx @@ -28,7 +28,7 @@ import { import { useFetch, useT } from "~/hooks"; import { getMainColor, password } from "~/store"; import { Obj, Resp } from "~/types"; -import { pathBase, handleRresp, hoverColor, pathJoin, fsDirs } from "~/utils"; +import { pathBase, handleResp, hoverColor, pathJoin, fsDirs } from "~/utils"; export interface FolderTreeProps { onChange: (path: string) => void; @@ -68,7 +68,7 @@ const FolderTreeNode = (props: { path: string }) => { const load = async () => { if (children().length > 0) return; const resp: Resp = await fetchDirs(); - handleRresp(resp, setChildren); + handleResp(resp, setChildren); }; const { isOpen, onToggle } = createDisclosure(); const active = () => value() === props.path; diff --git a/src/hooks/usePath.ts b/src/hooks/usePath.ts index 31f8dd5..cf56703 100644 --- a/src/hooks/usePath.ts +++ b/src/hooks/usePath.ts @@ -1,46 +1,44 @@ -import axios, { Canceler } from "axios"; -import { createSignal } from "solid-js"; +import axios, { Canceler } from "axios" import { appendObjs, - getSettingNumber, password, ObjStore, State, getPagination, objStore, -} from "~/store"; +} from "~/store" import { fsGet, fsList, - handleRrespWithoutNotify, + handleRespWithoutNotify, log, notify, pathJoin, -} from "~/utils"; -import { useFetch } from "./useFetch"; -import { useRouter } from "./useRouter"; +} from "~/utils" +import { useFetch } from "./useFetch" +import { useRouter } from "./useRouter" -let cancelList: Canceler; -const IsDirRecord: Record = {}; -let globalPage = 1; +let cancelList: Canceler +const IsDirRecord: Record = {} +let globalPage = 1 export const usePath = () => { - const { pathname, searchParams } = useRouter(); - const [, getObj] = useFetch((path: string) => fsGet(path, password())); - const pagination = getPagination(); + const { pathname, searchParams } = useRouter() + const [, getObj] = useFetch((path: string) => fsGet(path, password())) + const pagination = getPagination() if (pagination.type === "pagination" && searchParams.page) { - globalPage = parseInt(searchParams.page); + globalPage = parseInt(searchParams.page) } const [, getObjs] = useFetch( (arg?: { - path: string; - index?: number; - size?: number; - force?: boolean; + path: string + index?: number + size?: number + force?: boolean }) => { const page = { index: arg?.index, size: arg?.size, - }; + } // setSearchParams(page); return fsList( arg?.path, @@ -49,62 +47,62 @@ export const usePath = () => { page.size, arg?.force, new axios.CancelToken(function executor(c) { - cancelList = c; + cancelList = c }) - ); + ) } - ); + ) // set a path must be a dir const setPathAs = (path: string, dir = true, push = false) => { if (push) { - path = pathJoin(pathname(), path); + path = pathJoin(pathname(), path) } if (dir) { - IsDirRecord[path] = true; + IsDirRecord[path] = true } else { - delete IsDirRecord[path]; + delete IsDirRecord[path] } - }; + } // record is second time password is wrong - let retry_pass = false; + let retry_pass = false // handle pathname change // if confirm current path is dir, fetch List directly // if not, fetch get then determine if it is dir or file const handlePathChange = (path: string, rp?: boolean, force?: boolean) => { - log(`handle [${path}] change`); - cancelList?.(); - retry_pass = rp ?? false; - handleErr(""); + log(`handle [${path}] change`) + cancelList?.() + retry_pass = rp ?? false + handleErr("") if (IsDirRecord[path]) { - handleFolder(path, globalPage, undefined, undefined, force); + handleFolder(path, globalPage, undefined, undefined, force) } else { - handleObj(path); + handleObj(path) } - }; + } // handle enter obj that don't know if it is dir or file const handleObj = async (path: string) => { - ObjStore.setState(State.FetchingObj); - const resp = await getObj(path); - handleRrespWithoutNotify( + ObjStore.setState(State.FetchingObj) + const resp = await getObj(path) + handleRespWithoutNotify( resp, (data) => { - ObjStore.setObj(data); - ObjStore.setProvider(data.provider); + ObjStore.setObj(data) + ObjStore.setProvider(data.provider) if (data.is_dir) { - setPathAs(path); - handleFolder(path, globalPage); + setPathAs(path) + handleFolder(path, globalPage) } else { - ObjStore.setReadme(data.readme); - ObjStore.setRelated(data.related ?? []); - ObjStore.setRawUrl(data.raw_url); - ObjStore.setState(State.File); + ObjStore.setReadme(data.readme) + ObjStore.setRelated(data.related ?? []) + ObjStore.setRawUrl(data.raw_url) + ObjStore.setState(State.File) } }, handleErr - ); - }; + ) + } // change enter a folder or turn page or load more const handleFolder = async ( @@ -115,55 +113,55 @@ export const usePath = () => { force?: boolean ) => { if (!size) { - size = pagination.size; + size = pagination.size } if (size !== undefined && pagination.type === "all") { - size = undefined; + size = undefined } - globalPage = index ?? 1; - ObjStore.setState(append ? State.FetchingMore : State.FetchingObjs); - const resp = await getObjs({ path, index, size, force }); - handleRrespWithoutNotify( + globalPage = index ?? 1 + ObjStore.setState(append ? State.FetchingMore : State.FetchingObjs) + const resp = await getObjs({ path, index, size, force }) + handleRespWithoutNotify( resp, (data) => { if (append) { - appendObjs(data.content); + appendObjs(data.content) } else { - ObjStore.setObjs(data.content ?? []); - ObjStore.setTotal(data.total); + ObjStore.setObjs(data.content ?? []) + ObjStore.setTotal(data.total) } - ObjStore.setReadme(data.readme); - ObjStore.setWrite(data.write); - ObjStore.setState(State.Folder); + ObjStore.setReadme(data.readme) + ObjStore.setWrite(data.write) + ObjStore.setState(State.Folder) }, handleErr - ); - }; + ) + } const handleErr = (msg: string, code?: number) => { if (code === 403) { - ObjStore.setState(State.NeedPassword); + ObjStore.setState(State.NeedPassword) if (retry_pass) { - notify.error(msg); + notify.error(msg) } } else { - ObjStore.setErr(msg); + ObjStore.setErr(msg) } - }; + } const pageChange = (index?: number, size?: number, append = false) => { - handleFolder(pathname(), index, size, append); - }; + handleFolder(pathname(), index, size, append) + } return { handlePathChange, setPathAs: setPathAs, refresh: (retry_pass?: boolean, force?: boolean) => { - handlePathChange(pathname(), retry_pass, force); + handlePathChange(pathname(), retry_pass, force) }, pageChange: pageChange, page: globalPage, loadMore: () => { - pageChange(globalPage + 1, undefined, true); + pageChange(globalPage + 1, undefined, true) }, allLoaded: () => globalPage >= Math.ceil(objStore.total / pagination.size), - }; -}; + } +} diff --git a/src/pages/home/previews/aliyun_office.tsx b/src/pages/home/previews/aliyun_office.tsx index 883b14f..e4bab7a 100644 --- a/src/pages/home/previews/aliyun_office.tsx +++ b/src/pages/home/previews/aliyun_office.tsx @@ -3,7 +3,7 @@ import { MaybeLoading } from "~/components"; import { useFetch, useRouter } from "~/hooks"; import { password } from "~/store"; import { Resp } from "~/types"; -import { handleRresp, r } from "~/utils"; +import { handleResp, r } from "~/utils"; const AliDocPreview = () => { const { pathname } = useRouter(); @@ -17,7 +17,7 @@ const AliDocPreview = () => { ); const init = async () => { const resp = await post(); - handleRresp(resp, (data) => { + handleResp(resp, (data) => { const docOptions = aliyun.config({ mount: document.querySelector("#office-preview")!, url: data.preview_url, diff --git a/src/pages/home/previews/text-editor.tsx b/src/pages/home/previews/text-editor.tsx index fab9700..0c8d4b0 100644 --- a/src/pages/home/previews/text-editor.tsx +++ b/src/pages/home/previews/text-editor.tsx @@ -5,7 +5,7 @@ import { MonacoEditorLoader } from "~/components/MonacoEditor"; import { useFetch, useFetchText, useRouter, useT } from "~/hooks"; import { objStore, userCan } from "~/store"; import { EmptyResp } from "~/types"; -import { handleRresp, notify, r } from "~/utils"; +import { handleResp, notify, r } from "~/utils"; const TextEditor = () => { const [content] = useFetchText(); @@ -45,7 +45,7 @@ const TextEditor = () => { return; } const resp = await save(); - handleRresp(resp, () => { + handleResp(resp, () => { notify.success(t("global.save_success")); }); }} diff --git a/src/pages/home/toolbar/Aria2.tsx b/src/pages/home/toolbar/Aria2.tsx index c4bb053..240ee30 100644 --- a/src/pages/home/toolbar/Aria2.tsx +++ b/src/pages/home/toolbar/Aria2.tsx @@ -1,7 +1,7 @@ import { createDisclosure } from "@hope-ui/solid"; import { ModalInput } from "~/components"; import { useFetch, useRouter, useT } from "~/hooks"; -import { addAria2, bus, handleRrespWithNotifySuccess } from "~/utils"; +import { addAria2, bus, handleRespWithNotifySuccess } from "~/utils"; import { onCleanup } from "solid-js"; export const Aria2 = () => { @@ -28,7 +28,7 @@ export const Aria2 = () => { tips={t("home.toolbar.add_aria2-tips")} onSubmit={async (urls) => { const resp = await ok(pathname(), urls.split("\n")); - handleRrespWithNotifySuccess(resp, () => { + handleRespWithNotifySuccess(resp, () => { onClose(); }); }} diff --git a/src/pages/home/toolbar/CopyMove.tsx b/src/pages/home/toolbar/CopyMove.tsx index 6243fed..2d657fc 100644 --- a/src/pages/home/toolbar/CopyMove.tsx +++ b/src/pages/home/toolbar/CopyMove.tsx @@ -3,7 +3,7 @@ import { onCleanup } from "solid-js"; import { ModalFolderChoose } from "~/components"; import { useFetch, usePath, useRouter } from "~/hooks"; import { selectedObjs } from "~/store"; -import { bus, fsCopy, fsMove, handleRrespWithNotifySuccess } from "~/utils"; +import { bus, fsCopy, fsMove, handleRespWithNotifySuccess } from "~/utils"; export const Copy = () => { const { isOpen, onOpen, onClose } = createDisclosure(); @@ -30,7 +30,7 @@ export const Copy = () => { dst, selectedObjs().map((obj) => obj.name) ); - handleRrespWithNotifySuccess(resp, () => { + handleRespWithNotifySuccess(resp, () => { refresh(); onClose(); }); @@ -64,7 +64,7 @@ export const Move = () => { dst, selectedObjs().map((obj) => obj.name) ); - handleRrespWithNotifySuccess(resp, () => { + handleRespWithNotifySuccess(resp, () => { refresh(); onClose(); }); diff --git a/src/pages/home/toolbar/Delete.tsx b/src/pages/home/toolbar/Delete.tsx index 81b869c..0b1ed3e 100644 --- a/src/pages/home/toolbar/Delete.tsx +++ b/src/pages/home/toolbar/Delete.tsx @@ -11,7 +11,7 @@ import { import { onCleanup } from "solid-js"; import { useFetch, usePath, useRouter, useT } from "~/hooks"; import { selectedObjs } from "~/store"; -import { bus, fsRemove, handleRrespWithNotifySuccess } from "~/utils"; +import { bus, fsRemove, handleRespWithNotifySuccess } from "~/utils"; export const Delete = () => { const t = useT(); @@ -56,7 +56,7 @@ export const Delete = () => { pathname(), selectedObjs().map((obj) => obj.name) ); - handleRrespWithNotifySuccess(resp, () => { + handleRespWithNotifySuccess(resp, () => { refresh(); onClose(); }); diff --git a/src/pages/home/toolbar/Mkdir.tsx b/src/pages/home/toolbar/Mkdir.tsx index c6196cf..c68e68e 100644 --- a/src/pages/home/toolbar/Mkdir.tsx +++ b/src/pages/home/toolbar/Mkdir.tsx @@ -1,7 +1,7 @@ import { createDisclosure } from "@hope-ui/solid"; import { ModalInput } from "~/components"; 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"; export const Mkdir = () => { @@ -26,7 +26,7 @@ export const Mkdir = () => { loading={loading()} onSubmit={async (name) => { const resp = await ok(pathJoin(pathname(), name)); - handleRrespWithNotifySuccess(resp, () => { + handleRespWithNotifySuccess(resp, () => { refresh(); onClose(); }); diff --git a/src/pages/home/toolbar/NewFile.tsx b/src/pages/home/toolbar/NewFile.tsx index 5f10e6d..39f538c 100644 --- a/src/pages/home/toolbar/NewFile.tsx +++ b/src/pages/home/toolbar/NewFile.tsx @@ -5,7 +5,7 @@ import { useFetch, usePath, useRouter } from "~/hooks"; import { bus, fsNewFile, - handleRrespWithNotifySuccess, + handleRespWithNotifySuccess, pathJoin, } from "~/utils"; @@ -31,7 +31,7 @@ export const NewFile = () => { loading={loading()} onSubmit={async (name) => { const resp = await ok(pathJoin(pathname(), name)); - handleRrespWithNotifySuccess(resp, () => { + handleRespWithNotifySuccess(resp, () => { refresh(); onClose(); }); diff --git a/src/pages/home/toolbar/Rename.tsx b/src/pages/home/toolbar/Rename.tsx index 5aeea8a..da74eb6 100644 --- a/src/pages/home/toolbar/Rename.tsx +++ b/src/pages/home/toolbar/Rename.tsx @@ -6,7 +6,7 @@ import { oneChecked, selectedObjs } from "~/store"; import { bus, fsRename, - handleRrespWithNotifySuccess, + handleRespWithNotifySuccess, notify, pathJoin, } from "~/utils"; @@ -43,7 +43,7 @@ export const Rename = () => { pathJoin(pathname(), selectedObjs()[0].name), name ); - handleRrespWithNotifySuccess(resp, () => { + handleRespWithNotifySuccess(resp, () => { refresh(); onClose(); }); diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index cbca4d9..5358166 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -14,7 +14,7 @@ import { import { createSignal, Show } from "solid-js"; import { SwitchColorMode, SwitchLnaguageWhite } from "~/components"; 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 LoginBg from "./LoginBg"; import { createStorageSignal } from "@solid-primitives/storage"; @@ -49,7 +49,7 @@ const Login = () => { localStorage.removeItem("password"); } const resp = await data(); - handleRrespWithoutNotify( + handleRespWithoutNotify( resp, (data) => { notify.success(t("login.success")); diff --git a/src/pages/manage/common/DeletePopover.tsx b/src/pages/manage/common/DeletePopover.tsx index d99067a..defc47b 100644 --- a/src/pages/manage/common/DeletePopover.tsx +++ b/src/pages/manage/common/DeletePopover.tsx @@ -9,7 +9,7 @@ import { HStack, } from "@hope-ui/solid"; import { useT } from "~/hooks"; -import { handleRresp, notify } from "~/utils"; +import { handleResp, notify } from "~/utils"; export interface DeletePopoverProps { name: string; diff --git a/src/pages/manage/messenger/Messenger.tsx b/src/pages/manage/messenger/Messenger.tsx index f56e469..14c42b8 100644 --- a/src/pages/manage/messenger/Messenger.tsx +++ b/src/pages/manage/messenger/Messenger.tsx @@ -5,8 +5,8 @@ import { Dynamic } from "solid-js/web"; import { useFetch, useT } from "~/hooks"; import { Resp } from "~/types"; import { - handleRrespWithNotifySuccess, - handleRrespWithoutNotify, + handleRespWithNotifySuccess, + handleRespWithoutNotify, notify, r, } from "~/utils"; @@ -35,13 +35,13 @@ export const Messenger = () => { const [recieved, setRecieved] = createStore([]); const get = async () => { const resp: Resp = await getR(); - handleRrespWithoutNotify(resp, (msg) => { + handleRespWithoutNotify(resp, (msg) => { setRecieved(produce((msgs) => msgs.push(msg))); }); }; const send = async () => { const resp = await sendR(); - handleRrespWithNotifySuccess(resp); + handleRespWithNotifySuccess(resp); }; const getInterval = setInterval(get, 1000); onCleanup(() => clearInterval(getInterval)); diff --git a/src/pages/manage/metas/AddOrEdit.tsx b/src/pages/manage/metas/AddOrEdit.tsx index 1420e56..85502dd 100644 --- a/src/pages/manage/metas/AddOrEdit.tsx +++ b/src/pages/manage/metas/AddOrEdit.tsx @@ -13,7 +13,7 @@ import { } from "@hope-ui/solid"; import { MaybeLoading, FolderChooseInput } from "~/components"; 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 { createStore } from "solid-js/store"; import { For, Show } from "solid-js"; @@ -103,7 +103,7 @@ const AddOrEdit = () => { const initEdit = async () => { const resp = await loadMeta(); - handleRresp(resp, setMeta); + handleResp(resp, setMeta); }; if (id) { initEdit(); @@ -168,7 +168,7 @@ const AddOrEdit = () => { onClick={async () => { const resp = await ok(); // TODO mybe can use handleRrespWithNotifySuccess - handleRresp(resp, () => { + handleResp(resp, () => { notify.success(t("global.save_success")); back(); }); diff --git a/src/pages/manage/metas/Metas.tsx b/src/pages/manage/metas/Metas.tsx index 3bd6d7a..2396786 100644 --- a/src/pages/manage/metas/Metas.tsx +++ b/src/pages/manage/metas/Metas.tsx @@ -18,7 +18,7 @@ import { useRouter, useT, } from "~/hooks"; -import { handleRresp, notify, r } from "~/utils"; +import { handleResp, notify, r } from "~/utils"; import { Meta, PageResp } from "~/types"; import { DeletePopover } from "../common/DeletePopover"; import { Wether } from "~/components"; @@ -31,7 +31,7 @@ const Metas = () => { const [metas, setMetas] = createSignal([]); const refresh = async () => { const resp: PageResp = await getMetas(); - handleRresp(resp, (data) => setMetas(data.content)); + handleResp(resp, (data) => setMetas(data.content)); }; refresh(); @@ -90,7 +90,7 @@ const Metas = () => { loading={deleting() === meta.id} onClick={async () => { const resp = await deleteMeta(meta.id); - handleRresp(resp, () => { + handleResp(resp, () => { notify.success(t("global.delete_success")); refresh(); }); diff --git a/src/pages/manage/settings/Common.tsx b/src/pages/manage/settings/Common.tsx index bc562c6..9191b26 100644 --- a/src/pages/manage/settings/Common.tsx +++ b/src/pages/manage/settings/Common.tsx @@ -1,6 +1,6 @@ import { useFetch, useT, useRouter, useManageTitle } from "~/hooks"; 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 { Button, HStack, VStack } from "@hope-ui/solid"; import { createSignal, Index } from "solid-js"; @@ -20,7 +20,7 @@ const CommonSettings = (props: CommonSettingsProps) => { const [settings, setSettings] = createStore([]); const refresh = async () => { const resp: Resp = await getSettings(); - handleRresp(resp, setSettings); + handleResp(resp, setSettings); }; refresh(); const [saveLoading, saveSettings] = useFetch(() => @@ -43,7 +43,7 @@ const CommonSettings = (props: CommonSettingsProps) => { `/admin/setting/delete?key=${item().key}` ); setLoading(false); - handleRresp(resp, () => { + handleResp(resp, () => { notify.success(t("global.delete_success")); refresh(); }); @@ -64,7 +64,7 @@ const CommonSettings = (props: CommonSettingsProps) => { loading={saveLoading()} onClick={async () => { const resp: Resp<{}> = await saveSettings(); - handleRresp(resp, () => notify.success(t("global.save_success"))); + handleResp(resp, () => notify.success(t("global.save_success"))); }} > {t("global.save")} diff --git a/src/pages/manage/settings/Other.tsx b/src/pages/manage/settings/Other.tsx index 016c722..cbff859 100644 --- a/src/pages/manage/settings/Other.tsx +++ b/src/pages/manage/settings/Other.tsx @@ -3,7 +3,7 @@ import { createSignal } from "solid-js"; import { MaybeLoading } from "~/components"; import { useFetch, useManageTitle, useT, useUtil } from "~/hooks"; import { Resp, Group, SettingItem } from "~/types"; -import { handleRresp, notify, r } from "~/utils"; +import { handleResp, notify, r } from "~/utils"; import { Item } from "./SettingItem"; const OtherSettings = () => { @@ -21,7 +21,7 @@ const OtherSettings = () => { ); const refresh = async () => { const resp: Resp = await settingsData(); - handleRresp(resp, (data) => { + handleResp(resp, (data) => { setUri(data.find((i) => i.key === "aria2_uri")?.value || ""); setSecret(data.find((i) => i.key === "aria2_secret")?.value || ""); setToken(data.find((i) => i.key === "token")?.value || ""); @@ -53,7 +53,7 @@ const OtherSettings = () => { loading={setAria2Loading()} onClick={async () => { const resp: Resp = await setAria2(); - handleRresp(resp, (data) => { + handleResp(resp, (data) => { notify.success(`${t("settings_other.aria2_version")} ${data}`); }); }} @@ -75,7 +75,7 @@ const OtherSettings = () => { loading={resetTokenLoading()} onClick={async () => { const resp: Resp = await resetToken(); - handleRresp(resp, (data) => { + handleResp(resp, (data) => { notify.success(t("settings_other.reset_token_success")); setToken(data); }); diff --git a/src/pages/manage/storages/AddOrEdit.tsx b/src/pages/manage/storages/AddOrEdit.tsx index c35401d..7b2b44b 100644 --- a/src/pages/manage/storages/AddOrEdit.tsx +++ b/src/pages/manage/storages/AddOrEdit.tsx @@ -2,7 +2,7 @@ import { Button, Heading } from "@hope-ui/solid"; import { createSignal, For, Show } from "solid-js"; import { MaybeLoading } from "~/components"; import { useFetch, useRouter, useT } from "~/hooks"; -import { handleRresp, joinBase, notify, r } from "~/utils"; +import { handleResp, joinBase, notify, r } from "~/utils"; import { Addition, DriverConfig, @@ -54,7 +54,7 @@ const AddOrEdit = () => { const [drivers, setDrivers] = createSignal({}); const initAdd = async () => { const resp: Resp = await loadDrivers(); - handleRresp(resp, setDrivers); + handleResp(resp, setDrivers); }; const [storageLoading, loadStorage] = useFetch( @@ -67,11 +67,11 @@ const AddOrEdit = () => { ); const initEdit = async () => { const storageResp: Resp = await loadStorage(); - handleRresp(storageResp, async (storageData) => { + handleResp(storageResp, async (storageData) => { setStorage(storageData); setAddition(JSON.parse(storageData.addition)); const driverResp: Resp = await loadDriver(); - handleRresp(driverResp, (driverData) => + handleResp(driverResp, (driverData) => setDrivers({ [storage.driver]: driverData }) ); }); @@ -165,7 +165,7 @@ const AddOrEdit = () => { } const resp: Resp<{}> = await ok(); // TODO mybe can use handleRrespWithNotifySuccess - handleRresp(resp, () => { + handleResp(resp, () => { notify.success(t("global.save_success")); back(); }); diff --git a/src/pages/manage/storages/Storages.tsx b/src/pages/manage/storages/Storages.tsx index beebbcf..9901836 100644 --- a/src/pages/manage/storages/Storages.tsx +++ b/src/pages/manage/storages/Storages.tsx @@ -18,7 +18,7 @@ import { useRouter, useT, } from "~/hooks"; -import { handleRresp, handleRrespWithNotifySuccess, notify, r } from "~/utils"; +import { handleResp, handleRespWithNotifySuccess, notify, r } from "~/utils"; import { PageResp, Storage } from "~/types"; import { DeletePopover } from "../common/DeletePopover"; @@ -32,7 +32,7 @@ const Storages = () => { const [storages, setStorages] = createSignal([]); const refresh = async () => { const resp: PageResp = await getStorages(); - handleRresp(resp, (data) => setStorages(data.content)); + handleResp(resp, (data) => setStorages(data.content)); }; refresh(); @@ -101,7 +101,7 @@ const Storages = () => { storage.id, storage ); - handleRrespWithNotifySuccess(resp, () => { + handleRespWithNotifySuccess(resp, () => { refresh(); }); }} @@ -113,7 +113,7 @@ const Storages = () => { loading={deleting() === storage.id} onClick={async () => { const resp = await deleteStorage(storage.id); - handleRresp(resp, () => { + handleResp(resp, () => { notify.success(t("global.delete_success")); refresh(); }); diff --git a/src/pages/manage/tasks/Task.tsx b/src/pages/manage/tasks/Task.tsx index b46316b..8c02868 100644 --- a/src/pages/manage/tasks/Task.tsx +++ b/src/pages/manage/tasks/Task.tsx @@ -14,7 +14,7 @@ import { import { createSignal, Show } from "solid-js"; import { useT, useFetch } from "~/hooks"; import { TaskInfo } from "~/types"; -import { handleRresp, notify, r } from "~/utils"; +import { handleResp, notify, r } from "~/utils"; import { TasksProps } from "./Tasks"; const StateMap: Record< @@ -102,7 +102,7 @@ export const Task = (props: TaskInfo & TasksProps) => { loading={operateLoading()} onClick={async () => { const resp = await operate(); - handleRresp(resp, () => { + handleResp(resp, () => { notify.success(t("global.delete_success")); setDeleted(true); }); diff --git a/src/pages/manage/tasks/Tasks.tsx b/src/pages/manage/tasks/Tasks.tsx index 96139c2..f8e2976 100644 --- a/src/pages/manage/tasks/Tasks.tsx +++ b/src/pages/manage/tasks/Tasks.tsx @@ -2,7 +2,7 @@ import { Button, Heading, HStack, VStack } from "@hope-ui/solid"; import { createSignal, For, onCleanup, Show } from "solid-js"; import { useFetch, useT } from "~/hooks"; import { Resp, TaskInfo } from "~/types"; -import { handleRresp, r } from "~/utils"; +import { handleResp, r } from "~/utils"; import { Task } from "./Task"; export interface TasksProps { @@ -17,7 +17,7 @@ export const Tasks = (props: TasksProps) => { const [tasks, setTasks] = createSignal([]); const refresh = async () => { const resp: Resp = await get(); - handleRresp(resp, (data) => + handleResp(resp, (data) => setTasks( data?.sort((a, b) => { if (a.id > b.id) { @@ -48,7 +48,7 @@ export const Tasks = (props: TasksProps) => { loading={clearLoading()} onClick={async () => { const resp = await clear(); - handleRresp(resp, () => refresh()); + handleResp(resp, () => refresh()); }} > {t(`global.clear`)} diff --git a/src/pages/manage/users/2fa.tsx b/src/pages/manage/users/2fa.tsx index 6be51a2..7929c64 100644 --- a/src/pages/manage/users/2fa.tsx +++ b/src/pages/manage/users/2fa.tsx @@ -4,7 +4,7 @@ import { MaybeLoading } from "~/components"; import { useRouter, useFetch, useT } from "~/hooks"; import { setUser, user } from "~/store"; import { Resp } from "~/types"; -import { handleRresp, handleRrespWithNotifySuccess, notify, r } from "~/utils"; +import { handleResp, handleRespWithNotifySuccess, notify, r } from "~/utils"; interface Generate2FA { qr: string; @@ -25,7 +25,7 @@ const TwoFA = () => { return; } const resp: Resp = await generate(); - handleRresp(resp, setOtpData); + handleResp(resp, setOtpData); }; const [code, setCode] = createSignal(""); init(); @@ -37,7 +37,7 @@ const TwoFA = () => { ); const verify2FA = async () => { const resp = await verify(); - handleRrespWithNotifySuccess(resp, () => { + handleRespWithNotifySuccess(resp, () => { setUser({ ...user(), otp: true }); back(); }); diff --git a/src/pages/manage/users/AddOrEdit.tsx b/src/pages/manage/users/AddOrEdit.tsx index 03152aa..3bdcb63 100644 --- a/src/pages/manage/users/AddOrEdit.tsx +++ b/src/pages/manage/users/AddOrEdit.tsx @@ -10,7 +10,7 @@ import { } from "@hope-ui/solid"; import { MaybeLoading, FolderChooseInput } from "~/components"; 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 { createStore } from "solid-js/store"; import { For } from "solid-js"; @@ -59,7 +59,7 @@ const AddOrEdit = () => { const initEdit = async () => { const resp: Resp = await loadUser(); - handleRresp(resp, setUser); + handleResp(resp, setUser); }; if (id) { initEdit(); @@ -130,7 +130,7 @@ const AddOrEdit = () => { onClick={async () => { const resp: Resp<{}> = await ok(); // TODO mybe can use handleRrespWithNotifySuccess - handleRresp(resp, () => { + handleResp(resp, () => { notify.success(t("global.save_success")); back(); }); diff --git a/src/pages/manage/users/Profile.tsx b/src/pages/manage/users/Profile.tsx index d6c5165..ea02a5b 100644 --- a/src/pages/manage/users/Profile.tsx +++ b/src/pages/manage/users/Profile.tsx @@ -20,7 +20,7 @@ import { LinkWithBase } from "~/components"; import { useFetch, useManageTitle, useRouter, useT } from "~/hooks"; import { setUser, user } from "~/store"; import { UserMethods, UserPermissions } from "~/types"; -import { handleRresp, notify, r } from "~/utils"; +import { handleResp, notify, r } from "~/utils"; const PermissionBadge = (props: { can: boolean; children: JSXElement }) => { return ( @@ -105,7 +105,7 @@ const Profile = () => { loading={loading()} onClick={async () => { const resp = await save(); - handleRresp(resp, () => { + handleResp(resp, () => { setUser({ ...user(), username: username() }); notify.success(t("users.update_profile_success")); to(`/@login?redirect=${encodeURIComponent(location.pathname)}`); diff --git a/src/pages/manage/users/Users.tsx b/src/pages/manage/users/Users.tsx index 03ac2ac..5eeec05 100644 --- a/src/pages/manage/users/Users.tsx +++ b/src/pages/manage/users/Users.tsx @@ -20,7 +20,7 @@ import { useRouter, useT, } from "~/hooks"; -import { handleRresp, notify, r } from "~/utils"; +import { handleResp, notify, r } from "~/utils"; import { PageResp, UserPermissions, User, UserMethods } from "~/types"; import { DeletePopover } from "../common/DeletePopover"; @@ -65,7 +65,7 @@ const Users = () => { const [users, setUsers] = createSignal([]); const refresh = async () => { const resp: PageResp = await getUsers(); - handleRresp(resp, (data) => setUsers(data.content)); + handleResp(resp, (data) => setUsers(data.content)); }; refresh(); @@ -126,7 +126,7 @@ const Users = () => { loading={deleting() === user.id} onClick={async () => { const resp = await deleteUser(user.id); - handleRresp(resp, () => { + handleResp(resp, () => { notify.success(t("global.delete_success")); refresh(); }); diff --git a/src/utils/handle_resp.ts b/src/utils/handle_resp.ts index 5526678..dbc5d29 100644 --- a/src/utils/handle_resp.ts +++ b/src/utils/handle_resp.ts @@ -1,7 +1,7 @@ -import { Resp } from "~/types"; -import { bus, notify } from "."; +import { Resp } from "~/types" +import { bus, notify } from "." -export const handleRresp = ( +export const handleResp = ( resp: Resp, success?: (data: T) => void, fail?: (message: string, code: number) => void, @@ -10,53 +10,53 @@ export const handleRresp = ( notify_success?: boolean ) => { if (resp.code === 200) { - notify_success && notify.success(resp.message); - success?.(resp.data); + notify_success && notify.success(resp.message) + success?.(resp.data) } else { - notify_error && notify.error(resp.message); + notify_error && notify.error(resp.message) if (auth && resp.code === 401) { bus.emit( "to", `/@login?redirect=${encodeURIComponent(location.pathname)}` - ); - return; + ) + return } - fail?.(resp.message, resp.code); + fail?.(resp.message, resp.code) } -}; +} -export const handleRrespWithoutAuth = ( +export const handleRespWithoutAuth = ( resp: Resp, success?: (data: T) => void, fail?: (message: string, code?: number) => void, notify_error: boolean = true ) => { - return handleRresp(resp, success, fail, false, notify_error); -}; + return handleResp(resp, success, fail, false, notify_error) +} -export const handleRrespWithoutNotify = ( +export const handleRespWithoutNotify = ( resp: Resp, success?: (data: T) => void, fail?: (message: string, code?: number) => void, auth: boolean = true ) => { - return handleRresp(resp, success, fail, auth, false); -}; + return handleResp(resp, success, fail, auth, false) +} -export const handleRrespWithoutAuthAndNotify = ( +export const handleRespWithoutAuthAndNotify = ( resp: Resp, success?: (data: T) => void, fail?: (message: string, code?: number) => void ) => { - return handleRresp(resp, success, fail, false, false); -}; + return handleResp(resp, success, fail, false, false) +} -export const handleRrespWithNotifySuccess = ( +export const handleRespWithNotifySuccess = ( resp: Resp, success?: (data: T) => void, fail?: (message: string, code?: number) => void, auth: boolean = true, notify_error: boolean = true ) => { - return handleRresp(resp, success, fail, auth, notify_error, true); -}; + return handleResp(resp, success, fail, auth, notify_error, true) +}