refactor: project configuration

This commit is contained in:
Tristan Yang
2023-05-15 16:46:50 +08:00
parent 187ffd24d1
commit 20b907aae4
293 changed files with 991 additions and 964 deletions
+31
View File
@@ -0,0 +1,31 @@
import { useUpdateChannelMutation, useLazyLeaveChannelQuery } from "@/app/services/channel";
import { useAppSelector } from "@/app/store";
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: transferring, isSuccess: transferSuccess }] =
useUpdateChannelMutation();
const [leave, { isLoading: leaving, isSuccess: leaveSuccess }] = useLazyLeaveChannelQuery();
const transferOwner = (uid: number) => {
if (!uid) return;
update({ id: cid, owner: uid });
};
const leaveChannel = () => {
if (!cid) return;
leave(cid);
};
const isOwner = loginUid == channel?.owner;
const otherMembers = channel?.members.filter((m) => m != loginUid) || [];
return {
otherMembers,
transferOwner,
leaveChannel,
leaving,
leaveSuccess,
isOwner,
transferring,
transferSuccess
};
}