refactor: rename contact with user
This commit is contained in:
@@ -4,7 +4,7 @@ import toast from "react-hot-toast";
|
||||
import { useNavigate, useMatch } from "react-router-dom";
|
||||
import { hideAll } from "tippy.js";
|
||||
import { useRemoveMembersMutation } from "../../app/services/channel";
|
||||
import { useLazyDeleteContactQuery } from "../../app/services/contact";
|
||||
import { useLazyDeleteContactQuery } from "../../app/services/user";
|
||||
import useConfig from "./useConfig";
|
||||
import useCopy from "./useCopy";
|
||||
import { useAppSelector } from "../../app/store";
|
||||
@@ -15,14 +15,14 @@ interface Props {
|
||||
const useContactOperation: FC<Props> = ({ uid, cid }) => {
|
||||
const [passedUid, setPassedUid] = useState(undefined);
|
||||
const { values: agoraConfig } = useConfig("agora");
|
||||
const isUserDetailPath = useMatch(`/contacts/${uid}`);
|
||||
const isUserDetailPath = useMatch(`/users/${uid}`);
|
||||
const [removeUser, { isSuccess: removeUserSuccess }] = useLazyDeleteContactQuery();
|
||||
const [removeInChannel, { isSuccess: removeSuccess }] = useRemoveMembersMutation();
|
||||
const navigateTo = useNavigate();
|
||||
const { copy } = useCopy();
|
||||
const { user, channel, loginUser } = useAppSelector((store) => {
|
||||
return {
|
||||
user: store.contacts.byId[uid],
|
||||
user: store.users.byId[uid],
|
||||
channel: store.channels.byId[cid],
|
||||
loginUser: store.authData.user
|
||||
};
|
||||
@@ -36,7 +36,7 @@ const useContactOperation: FC<Props> = ({ uid, cid }) => {
|
||||
if (removeSuccess || removeUserSuccess) {
|
||||
toast.success("Remove Successfully");
|
||||
if (removeUserSuccess && isUserDetailPath) {
|
||||
navigateTo(`/contacts`);
|
||||
navigateTo(`/users`);
|
||||
}
|
||||
}
|
||||
}, [removeSuccess, removeUserSuccess, isUserDetailPath]);
|
||||
|
||||
@@ -3,16 +3,16 @@ import { useAppSelector } from "../../app/store";
|
||||
|
||||
export default function useFilteredUsers() {
|
||||
const [input, setInput] = useState("");
|
||||
const contacts = useAppSelector((store) => Object.values(store.contacts.byId));
|
||||
const users = useAppSelector((store) => Object.values(store.users.byId));
|
||||
const [filteredUsers, setFilteredUsers] = useState([]);
|
||||
useEffect(() => {
|
||||
if (!input) {
|
||||
setFilteredUsers(contacts);
|
||||
setFilteredUsers(users);
|
||||
} else {
|
||||
let str = ["", input.toLowerCase(), ""].join(".*");
|
||||
let reg = new RegExp(str);
|
||||
setFilteredUsers(
|
||||
contacts.filter((c) => {
|
||||
users.filter((c) => {
|
||||
return reg.test(c.name.toLowerCase());
|
||||
})
|
||||
);
|
||||
@@ -25,7 +25,7 @@ export default function useFilteredUsers() {
|
||||
|
||||
return {
|
||||
input,
|
||||
contacts: filteredUsers,
|
||||
users: filteredUsers,
|
||||
updateInput
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState } from "react";
|
||||
import { useSendChannelMsgMutation } from "../../app/services/channel";
|
||||
import { useSendMsgMutation } from "../../app/services/contact";
|
||||
import { useSendMsgMutation } from "../../app/services/user";
|
||||
import { useCreateArchiveMutation } from "../../app/services/message";
|
||||
|
||||
export default function useForwardMessage() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useDispatch, batch } from "react-redux";
|
||||
import { resetFootprint } from "../../app/slices/footprint";
|
||||
import { resetChannels } from "../../app/slices/channels";
|
||||
import { resetContacts } from "../../app/slices/contacts";
|
||||
import { resetContacts } from "../../app/slices/users";
|
||||
import { resetChannelMsg } from "../../app/slices/message.channel";
|
||||
import { resetUserMsg } from "../../app/slices/message.user";
|
||||
import { resetReactionMessage } from "../../app/slices/message.reaction";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useState, useRef } from "react";
|
||||
import { useLazyGetHistoryMessagesQuery } from "../../app/services/channel";
|
||||
import { useLazyGetHistoryMessagesQuery as useLazyGetDMHistoryMsg } from "../../app/services/contact";
|
||||
import { useLazyGetHistoryMessagesQuery as useLazyGetDMHistoryMsg } from "../../app/services/user";
|
||||
import { useAppSelector } from "../../app/store";
|
||||
export interface PageInfo {
|
||||
isFirst: boolean;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { usePinMessageMutation, useUnpinMessageMutation } from "../../app/services/message";
|
||||
import { useAppSelector } from "../../app/store";
|
||||
import { PinnedMessage } from "../../types/channel";
|
||||
|
||||
export default function usePinMessage(cid: number) {
|
||||
const [pins, setPins] = useState([]);
|
||||
const [pins, setPins] = useState<PinnedMessage[]>([]);
|
||||
const { channel, loginUser } = useAppSelector((store) => {
|
||||
return {
|
||||
channel: store.channels.byId[cid],
|
||||
@@ -13,15 +14,15 @@ export default function usePinMessage(cid: number) {
|
||||
const [pin, { isError, isLoading, isSuccess }] = usePinMessageMutation();
|
||||
const [unpin, { isError: isUnpinError, isLoading: isUnpining, isSuccess: isUnpinSuccess }] =
|
||||
useUnpinMessageMutation();
|
||||
const pinMessage = (mid) => {
|
||||
const pinMessage = (mid: number) => {
|
||||
if (!mid || !cid) return;
|
||||
pin({ mid, gid: +cid });
|
||||
};
|
||||
const unpinMessage = (mid) => {
|
||||
const unpinMessage = (mid: number) => {
|
||||
if (!mid || !cid) return;
|
||||
unpin({ mid, gid: +cid });
|
||||
};
|
||||
const getPinInfo = (mid) => {
|
||||
const getPinInfo = (mid: number) => {
|
||||
if (!cid || !channel) return;
|
||||
const pins = channel.pinned_messages;
|
||||
if (!pins || pins.length == 0) return;
|
||||
@@ -38,7 +39,7 @@ export default function usePinMessage(cid: number) {
|
||||
getPinInfo,
|
||||
channel,
|
||||
pins,
|
||||
canPin: loginUser.is_admin || channel?.owner == loginUser.uid,
|
||||
canPin: loginUser?.is_admin || channel?.owner == loginUser?.uid,
|
||||
pinMessage,
|
||||
unpinMessage,
|
||||
isError,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import toast from "react-hot-toast";
|
||||
import { removeReplyingMessage, addReplyingMessage } from "../../app/slices/message";
|
||||
import { useSendChannelMsgMutation } from "../../app/services/channel";
|
||||
import { useSendMsgMutation } from "../../app/services/contact";
|
||||
import { useSendMsgMutation } from "../../app/services/user";
|
||||
import { useReplyMessageMutation } from "../../app/services/message";
|
||||
import { useAppDispatch, useAppSelector } from "../../app/store";
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
updateReadUsers,
|
||||
updateMute
|
||||
} from "../../../app/slices/footprint";
|
||||
import { updateUsersByLogs, updateUsersStatus } from "../../../app/slices/contacts";
|
||||
import { updateUsersByLogs, updateUsersStatus } from "../../../app/slices/users";
|
||||
import { resetAuthData } from "../../../app/slices/auth.data";
|
||||
import chatMessageHandler from "./chat.handler";
|
||||
import store, { useAppDispatch, useAppSelector } from "../../../app/store";
|
||||
|
||||
@@ -20,12 +20,9 @@ export default function useUploadFile(props: { context: string; id: string } | o
|
||||
const canceledRef = useRef(false);
|
||||
const sliceUploadedCountRef = useRef(0);
|
||||
const totalSliceCountRef = useRef(1);
|
||||
const [prepareUploadFile, { isLoading: isPreparing, isSuccess: isPrepared }] =
|
||||
usePrepareUploadFileMutation();
|
||||
const [
|
||||
uploadFileFn,
|
||||
{ isLoading: isUploading, isSuccess: isUploaded, isError: uploadFileError }
|
||||
] = useUploadFileMutation();
|
||||
const [prepareUploadFile, { isLoading: isPreparing }] = usePrepareUploadFileMutation();
|
||||
const [uploadFileFn, { isLoading: isUploading, isError: uploadFileError }] =
|
||||
useUploadFileMutation();
|
||||
|
||||
const uploadChunk = (data: { file_id: string; chunk: File; is_last: boolean }) => {
|
||||
const { file_id, chunk, is_last } = data;
|
||||
|
||||
Reference in New Issue
Block a user