refactor: more TS code
This commit is contained in:
@@ -3,7 +3,7 @@ import useCopy from "./useCopy";
|
||||
import { useGetSMTPStatusQuery } from "../../app/services/server";
|
||||
import { useLazyCreateInviteLinkQuery as useCreateChannelInviteLinkQuery } from "../../app/services/channel";
|
||||
|
||||
export default function useInviteLink(cid: string | null = "") {
|
||||
export default function useInviteLink(cid?: number) {
|
||||
const [finalLink, setFinalLink] = useState("");
|
||||
const { data: SMTPEnabled, isSuccess: smtpStatusFetchSuccess } = useGetSMTPStatusQuery();
|
||||
const [generateChannelInviteLink, { data: channelInviteLink, isLoading: generatingChannelLink }] =
|
||||
@@ -20,8 +20,6 @@ export default function useInviteLink(cid: string | null = "") {
|
||||
useEffect(() => {
|
||||
const _link = channelInviteLink;
|
||||
if (_link && smtpStatusFetchSuccess) {
|
||||
// const tmpURL = new URL(_link);
|
||||
// tmpURL.searchParams.set("code", SMTPEnabled);
|
||||
setFinalLink(_link);
|
||||
}
|
||||
}, [channelInviteLink, smtpStatusFetchSuccess]);
|
||||
|
||||
@@ -5,10 +5,10 @@ export default function useLeaveChannel(cid: number) {
|
||||
const { channel, loginUid } = useAppSelector((store) => {
|
||||
return { channel: store.channels.byId[cid], loginUid: store.authData.user?.uid };
|
||||
});
|
||||
const [update, { isLoading: transfering, isSuccess: transferSuccess }] =
|
||||
const [update, { isLoading: transferring, isSuccess: transferSuccess }] =
|
||||
useUpdateChannelMutation();
|
||||
const [leave, { isLoading: leaving, isSuccess: leaveSuccess }] = useLazyLeaveChannelQuery();
|
||||
const transferOwner = (uid = null) => {
|
||||
const transferOwner = (uid: number) => {
|
||||
if (!uid) return;
|
||||
update({ id: cid, owner: uid });
|
||||
};
|
||||
@@ -16,8 +16,8 @@ export default function useLeaveChannel(cid: number) {
|
||||
if (!cid) return;
|
||||
leave(cid);
|
||||
};
|
||||
const isOwner = loginUid == channel.owner;
|
||||
const otherMembers = channel.members.filter((m) => m != loginUid);
|
||||
const isOwner = loginUid == channel?.owner;
|
||||
const otherMembers = channel?.members.filter((m) => m != loginUid) || [];
|
||||
return {
|
||||
otherMembers,
|
||||
transferOwner,
|
||||
@@ -25,7 +25,7 @@ export default function useLeaveChannel(cid: number) {
|
||||
leaving,
|
||||
leaveSuccess,
|
||||
isOwner,
|
||||
transfering,
|
||||
transferring,
|
||||
transferSuccess
|
||||
};
|
||||
}
|
||||
|
||||
@@ -144,7 +144,9 @@ export default function useUploadFile(props: { context: string; id: string } | o
|
||||
stopUploading,
|
||||
data,
|
||||
isUploading: isPreparing || isUploading,
|
||||
progress: Number((sliceUploadedCountRef.current / totalSliceCountRef.current) * 100).toFixed(2),
|
||||
progress: +Number((sliceUploadedCountRef.current / totalSliceCountRef.current) * 100).toFixed(
|
||||
2
|
||||
),
|
||||
uploadFile,
|
||||
isError: uploadFileError,
|
||||
isSuccess: !!data,
|
||||
|
||||
Reference in New Issue
Block a user