chore: fix typo

This commit is contained in:
Noah Hsu
2022-09-20 17:03:31 +08:00
parent 558a8fc7f6
commit 519f120200
29 changed files with 164 additions and 163 deletions

3
.prettierrc Normal file
View File

@@ -0,0 +1,3 @@
{
"semi": false
}

View File

@@ -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<Record<string, string>>,
setSettings,
setErr

View File

@@ -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<string>();
(async () => {
// const resp: Resp<User> = await data();
handleRresp(await data(), setUser, setErr);
handleResp(await data(), setUser, setErr);
})();
return (
<Switch fallback={props.children}>

View File

@@ -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<Obj[]> = await fetchDirs();
handleRresp(resp, setChildren);
handleResp(resp, setChildren);
};
const { isOpen, onToggle } = createDisclosure();
const active = () => value() === props.path;

View File

@@ -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<string, boolean> = {};
let globalPage = 1;
let cancelList: Canceler
const IsDirRecord: Record<string, boolean> = {}
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),
};
};
}
}

View File

@@ -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,

View File

@@ -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"));
});
}}

View File

@@ -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();
});
}}

View File

@@ -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();
});

View File

@@ -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();
});

View File

@@ -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();
});

View File

@@ -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();
});

View File

@@ -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();
});

View File

@@ -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"));

View File

@@ -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;

View File

@@ -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<Message[]>([]);
const get = async () => {
const resp: Resp<Message> = 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));

View File

@@ -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();
});

View File

@@ -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<Meta[]>([]);
const refresh = async () => {
const resp: PageResp<Meta> = 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();
});

View File

@@ -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<SettingItem[]>([]);
const refresh = async () => {
const resp: Resp<SettingItem[]> = 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")}

View File

@@ -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<SettingItem[]> = 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<string> = 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<string> = await resetToken();
handleRresp(resp, (data) => {
handleResp(resp, (data) => {
notify.success(t("settings_other.reset_token_success"));
setToken(data);
});

View File

@@ -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<Drivers>({});
const initAdd = async () => {
const resp: Resp<Drivers> = await loadDrivers();
handleRresp(resp, setDrivers);
handleResp(resp, setDrivers);
};
const [storageLoading, loadStorage] = useFetch(
@@ -67,11 +67,11 @@ const AddOrEdit = () => {
);
const initEdit = async () => {
const storageResp: Resp<Storage> = await loadStorage();
handleRresp(storageResp, async (storageData) => {
handleResp(storageResp, async (storageData) => {
setStorage(storageData);
setAddition(JSON.parse(storageData.addition));
const driverResp: Resp<DriverInfo> = 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();
});

View File

@@ -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<Storage[]>([]);
const refresh = async () => {
const resp: PageResp<Storage> = 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();
});

View File

@@ -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);
});

View File

@@ -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<TaskInfo[]>([]);
const refresh = async () => {
const resp: Resp<TaskInfo[]> = 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`)}

View File

@@ -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<Generate2FA> = 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();
});

View File

@@ -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<User> = 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();
});

View File

@@ -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)}`);

View File

@@ -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<User[]>([]);
const refresh = async () => {
const resp: PageResp<User> = 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();
});

View File

@@ -1,7 +1,7 @@
import { Resp } from "~/types";
import { bus, notify } from ".";
import { Resp } from "~/types"
import { bus, notify } from "."
export const handleRresp = <T>(
export const handleResp = <T>(
resp: Resp<T>,
success?: (data: T) => void,
fail?: (message: string, code: number) => void,
@@ -10,53 +10,53 @@ export const handleRresp = <T>(
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 = <T>(
export const handleRespWithoutAuth = <T>(
resp: Resp<T>,
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 = <T>(
export const handleRespWithoutNotify = <T>(
resp: Resp<T>,
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 = <T>(
export const handleRespWithoutAuthAndNotify = <T>(
resp: Resp<T>,
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 = <T>(
export const handleRespWithNotifySuccess = <T>(
resp: Resp<T>,
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)
}