chore: update prettier setting
This commit is contained in:
@@ -9,58 +9,43 @@ import {
|
||||
useUpdateLoginConfigMutation,
|
||||
useUpdateSMTPConfigMutation,
|
||||
useUpdateAgoraConfigMutation,
|
||||
useUpdateFirebaseConfigMutation,
|
||||
useUpdateFirebaseConfigMutation
|
||||
} from "../../app/services/server";
|
||||
export default function useConfig(config = "smtp") {
|
||||
const [changed, setChanged] = useState(false);
|
||||
const [values, setValues] = useState({});
|
||||
const { data: Login, refetch: refetchLogin } = useGetLoginConfigQuery();
|
||||
const [
|
||||
updateLoginConfig,
|
||||
{ isSuccess: LoginUpdated },
|
||||
] = useUpdateLoginConfigMutation();
|
||||
const [updateLoginConfig, { isSuccess: LoginUpdated }] = useUpdateLoginConfigMutation();
|
||||
const { data: SMTP, refetch: refetchSMTP } = useGetSMTPConfigQuery();
|
||||
const [
|
||||
updateSMTPConfig,
|
||||
{ isSuccess: SMTPUpdated },
|
||||
] = useUpdateSMTPConfigMutation();
|
||||
const [updateSMTPConfig, { isSuccess: SMTPUpdated }] = useUpdateSMTPConfigMutation();
|
||||
const { data: Agora, refetch: refetchAgora } = useGetAgoraConfigQuery();
|
||||
const [
|
||||
updateAgoraConfig,
|
||||
{ isSuccess: AgoraUpdated },
|
||||
] = useUpdateAgoraConfigMutation();
|
||||
const {
|
||||
data: Firebase,
|
||||
refetch: refetchFirebase,
|
||||
} = useGetFirebaseConfigQuery();
|
||||
const [
|
||||
updateFirebaseConfig,
|
||||
{ isSuccess: FirebaseUpdated },
|
||||
] = useUpdateFirebaseConfigMutation();
|
||||
const [updateAgoraConfig, { isSuccess: AgoraUpdated }] = useUpdateAgoraConfigMutation();
|
||||
const { data: Firebase, refetch: refetchFirebase } = useGetFirebaseConfigQuery();
|
||||
const [updateFirebaseConfig, { isSuccess: FirebaseUpdated }] = useUpdateFirebaseConfigMutation();
|
||||
|
||||
const datas = {
|
||||
login: Login,
|
||||
smtp: SMTP,
|
||||
agora: Agora,
|
||||
firebase: Firebase,
|
||||
firebase: Firebase
|
||||
};
|
||||
const updateFns = {
|
||||
login: updateLoginConfig,
|
||||
smtp: updateSMTPConfig,
|
||||
agora: updateAgoraConfig,
|
||||
firebase: updateFirebaseConfig,
|
||||
firebase: updateFirebaseConfig
|
||||
};
|
||||
const refetchs = {
|
||||
smtp: refetchSMTP,
|
||||
agora: refetchAgora,
|
||||
firebase: refetchFirebase,
|
||||
login: refetchLogin,
|
||||
login: refetchLogin
|
||||
};
|
||||
const updateds = {
|
||||
login: LoginUpdated,
|
||||
smtp: SMTPUpdated,
|
||||
agora: AgoraUpdated,
|
||||
firebase: FirebaseUpdated,
|
||||
firebase: FirebaseUpdated
|
||||
};
|
||||
const data = datas[config];
|
||||
const updateConfig = updateFns[config];
|
||||
@@ -102,6 +87,6 @@ export default function useConfig(config = "smtp") {
|
||||
updateConfig,
|
||||
values,
|
||||
setValues,
|
||||
toggleEnable,
|
||||
toggleEnable
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,14 +13,8 @@ export default function useContactOperation({ uid, cid }) {
|
||||
const [passedUid, setPassedUid] = useState(undefined);
|
||||
const { values: agoraConfig } = useConfig("agora");
|
||||
const isUserDetailPath = useMatch(`/contacts/${uid}`);
|
||||
const [
|
||||
removeUser,
|
||||
{ isSuccess: removeUserSuccess },
|
||||
] = useLazyDeleteContactQuery();
|
||||
const [
|
||||
removeInChannel,
|
||||
{ isSuccess: removeSuccess },
|
||||
] = useRemoveMembersMutation();
|
||||
const [removeUser, { isSuccess: removeUserSuccess }] = useLazyDeleteContactQuery();
|
||||
const [removeInChannel, { isSuccess: removeSuccess }] = useRemoveMembersMutation();
|
||||
const navigateTo = useNavigate();
|
||||
const { copy } = useCopy();
|
||||
const { user, channel, loginUid, isAdmin } = useSelector((store) => {
|
||||
@@ -28,7 +22,7 @@ export default function useContactOperation({ uid, cid }) {
|
||||
user: store.contacts.byId[uid],
|
||||
channel: store.channels.byId[cid],
|
||||
loginUid: store.authData.uid,
|
||||
isAdmin: store.contacts.byId[store.authData.uid]?.is_admin,
|
||||
isAdmin: store.contacts.byId[store.authData.uid]?.is_admin
|
||||
};
|
||||
});
|
||||
useEffect(() => {
|
||||
@@ -81,6 +75,6 @@ export default function useContactOperation({ uid, cid }) {
|
||||
canCopyEmail: !!user?.email,
|
||||
copyEmail,
|
||||
canCall,
|
||||
call,
|
||||
call
|
||||
};
|
||||
}
|
||||
|
||||
@@ -49,6 +49,6 @@ export default function useContextMenu(placement = "right-start") {
|
||||
offset,
|
||||
visible,
|
||||
hideContextMenu,
|
||||
handleContextMenuEvent,
|
||||
handleContextMenuEvent
|
||||
};
|
||||
}
|
||||
|
||||
@@ -20,9 +20,7 @@ const useCopy = (config) => {
|
||||
el.style.left = "-9999px";
|
||||
document.body.appendChild(el);
|
||||
const selected =
|
||||
document.getSelection().rangeCount > 0
|
||||
? document.getSelection().getRangeAt(0)
|
||||
: false;
|
||||
document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
|
||||
el.select();
|
||||
const success = document.execCommand("copy");
|
||||
document.body.removeChild(el);
|
||||
|
||||
@@ -6,11 +6,11 @@ export default function useDeleteMessage() {
|
||||
const { loginUser, messageData } = useSelector((store) => {
|
||||
return {
|
||||
messageData: store.message,
|
||||
loginUser: store.contacts.byId[store.authData.uid],
|
||||
loginUser: store.contacts.byId[store.authData.uid]
|
||||
};
|
||||
});
|
||||
const [
|
||||
remove,
|
||||
remove
|
||||
// { isError, isLoading, isSuccess },
|
||||
] = useLazyDeleteMessageQuery();
|
||||
const deleteMessage = async (mids) => {
|
||||
@@ -40,6 +40,6 @@ export default function useDeleteMessage() {
|
||||
return {
|
||||
canDelete,
|
||||
isDeleting: deleting,
|
||||
deleteMessage,
|
||||
deleteMessage
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export default function useDraft({ context = "", id = "" }) {
|
||||
const { draftMarkdown, draftMixedText } = useSelector((store) => {
|
||||
return {
|
||||
draftMarkdown: store.ui.draftMarkdown,
|
||||
draftMixedText: store.ui.draftMixedText,
|
||||
draftMixedText: store.ui.draftMixedText
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import {
|
||||
useLazyRemoveFavoriteQuery,
|
||||
useFavoriteMessageMutation,
|
||||
} from "../../app/services/message";
|
||||
import { useLazyRemoveFavoriteQuery, useFavoriteMessageMutation } from "../../app/services/message";
|
||||
export default function useFavMessage({ cid = null, uid = null }) {
|
||||
const [removeFav] = useLazyRemoveFavoriteQuery();
|
||||
const [addFav] = useFavoriteMessageMutation();
|
||||
const [favorites, setFavorites] = useState([]);
|
||||
const { favs = [] } = useSelector((store) => {
|
||||
return {
|
||||
favs: store.favorites,
|
||||
favs: store.favorites
|
||||
};
|
||||
});
|
||||
const addFavorite = async (mid = []) => {
|
||||
@@ -56,6 +53,6 @@ export default function useFavMessage({ cid = null, uid = null }) {
|
||||
isFavorited,
|
||||
addFavorite,
|
||||
removeFavorite,
|
||||
favorites,
|
||||
favorites
|
||||
};
|
||||
}
|
||||
|
||||
@@ -23,6 +23,6 @@ export default function useFilteredChannels() {
|
||||
return {
|
||||
input,
|
||||
channels: filteredChannels,
|
||||
updateInput,
|
||||
updateInput
|
||||
};
|
||||
}
|
||||
|
||||
@@ -23,6 +23,6 @@ export default function useFilteredUsers() {
|
||||
return {
|
||||
input,
|
||||
contacts: filteredUsers,
|
||||
updateInput,
|
||||
updateInput
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,24 +6,14 @@ export default function useForwardMessage() {
|
||||
const [forwarding, setForwarding] = useState(false);
|
||||
const [
|
||||
createArchive,
|
||||
{
|
||||
isError: createArchiveError,
|
||||
isLoading: creatingArchive,
|
||||
isSuccess: createArchiveSuccess,
|
||||
},
|
||||
{ isError: createArchiveError, isLoading: creatingArchive, isSuccess: createArchiveSuccess }
|
||||
] = useCreateArchiveMutation();
|
||||
const [
|
||||
sendChannelMsg,
|
||||
{
|
||||
isLoading: channelSending,
|
||||
isSuccess: channelSuccess,
|
||||
isError: channelError,
|
||||
},
|
||||
{ isLoading: channelSending, isSuccess: channelSuccess, isError: channelError }
|
||||
] = useSendChannelMsgMutation();
|
||||
const [
|
||||
sendUserMsg,
|
||||
{ isLoading: userSending, isSuccess: userSuccess, isError: userError },
|
||||
] = useSendMsgMutation();
|
||||
const [sendUserMsg, { isLoading: userSending, isSuccess: userSuccess, isError: userError }] =
|
||||
useSendMsgMutation();
|
||||
const forwardMessage = async ({ mids = [], users = [], channels = [] }) => {
|
||||
setForwarding(true);
|
||||
const { data: archive_id } = await createArchive(mids);
|
||||
@@ -32,7 +22,7 @@ export default function useForwardMessage() {
|
||||
await sendUserMsg({
|
||||
type: "archive",
|
||||
id: uid,
|
||||
content: archive_id,
|
||||
content: archive_id
|
||||
// from_uid: from,
|
||||
});
|
||||
}
|
||||
@@ -42,7 +32,7 @@ export default function useForwardMessage() {
|
||||
await sendChannelMsg({
|
||||
type: "archive",
|
||||
id: cid,
|
||||
content: archive_id,
|
||||
content: archive_id
|
||||
// from_uid: from,
|
||||
});
|
||||
}
|
||||
@@ -54,6 +44,6 @@ export default function useForwardMessage() {
|
||||
forwarding,
|
||||
isError: channelError || userError || createArchiveError,
|
||||
isSending: userSending || channelSending || creatingArchive,
|
||||
isSuccess: channelSuccess || userSuccess || createArchiveSuccess,
|
||||
isSuccess: channelSuccess || userSuccess || createArchiveSuccess
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ import { useState, useEffect } from "react";
|
||||
// import toast from "react-hot-toast";
|
||||
import {
|
||||
useGetGithubAuthConfigQuery,
|
||||
useUpdateGithubAuthConfigMutation,
|
||||
useUpdateGithubAuthConfigMutation
|
||||
} from "../../app/services/server";
|
||||
export default function useGithubAuthConfig() {
|
||||
const [changed, setChanged] = useState(false);
|
||||
const [config, setConfig] = useState({});
|
||||
const { data } = useGetGithubAuthConfigQuery(undefined, {
|
||||
refetchOnMountOrArgChange: true,
|
||||
refetchOnMountOrArgChange: true
|
||||
});
|
||||
const [updateAuthConfig, { isSuccess }] = useUpdateGithubAuthConfigMutation();
|
||||
useEffect(() => {
|
||||
@@ -18,9 +18,7 @@ export default function useGithubAuthConfig() {
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
setChanged(
|
||||
isSuccess ? false : JSON.stringify(data) !== JSON.stringify(config)
|
||||
);
|
||||
setChanged(isSuccess ? false : JSON.stringify(data) !== JSON.stringify(config));
|
||||
}, [data, config, isSuccess]);
|
||||
const updateGithubAuthConfig = (obj) => {
|
||||
setConfig((prev) => {
|
||||
@@ -35,6 +33,6 @@ export default function useGithubAuthConfig() {
|
||||
changed,
|
||||
updateGithubAuthConfig,
|
||||
updateGithubAuthConfigToServer,
|
||||
isSuccess,
|
||||
isSuccess
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,18 +2,15 @@ import { useState, useEffect } from "react";
|
||||
// import toast from "react-hot-toast";
|
||||
import {
|
||||
useGetGoogleAuthConfigQuery,
|
||||
useUpdateGoogleAuthConfigMutation,
|
||||
useUpdateGoogleAuthConfigMutation
|
||||
} from "../../app/services/server";
|
||||
export default function useGoogleAuthConfig() {
|
||||
const [changed, setChanged] = useState(false);
|
||||
const [clientId, setClientId] = useState("");
|
||||
const { data } = useGetGoogleAuthConfigQuery(undefined, {
|
||||
refetchOnMountOrArgChange: true,
|
||||
refetchOnMountOrArgChange: true
|
||||
});
|
||||
const [
|
||||
updateGoogleAuthConfig,
|
||||
{ isSuccess },
|
||||
] = useUpdateGoogleAuthConfigMutation();
|
||||
const [updateGoogleAuthConfig, { isSuccess }] = useUpdateGoogleAuthConfigMutation();
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
setClientId(data.client_id);
|
||||
@@ -36,6 +33,6 @@ export default function useGoogleAuthConfig() {
|
||||
updateClientId: setClientId,
|
||||
updateClientIdToServer,
|
||||
updateGoogleAuthConfig,
|
||||
isSuccess,
|
||||
isSuccess
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,23 +2,16 @@ import { useState, useEffect } from "react";
|
||||
import useCopy from "./useCopy";
|
||||
import {
|
||||
useLazyCreateInviteLinkQuery as useCreateServerInviteLinkQuery,
|
||||
useGetSMTPStatusQuery,
|
||||
useGetSMTPStatusQuery
|
||||
} from "../../app/services/server";
|
||||
import { useLazyCreateInviteLinkQuery as useCreateChannelInviteLinkQuery } from "../../app/services/channel";
|
||||
export default function useInviteLink(cid = null) {
|
||||
const [finalLink, setFinalLink] = useState("");
|
||||
const {
|
||||
data: SMTPEnabled,
|
||||
isSuccess: smtpStatusFetchSuccess,
|
||||
} = useGetSMTPStatusQuery();
|
||||
const [
|
||||
generateChannelInviteLink,
|
||||
{ data: channelInviteLink, isLoading: generatingChannelLink },
|
||||
] = useCreateChannelInviteLinkQuery();
|
||||
const [
|
||||
generateServerInviteLink,
|
||||
{ data: serverInviteLink, isLoading: generatingServerLink },
|
||||
] = useCreateServerInviteLinkQuery();
|
||||
const { data: SMTPEnabled, isSuccess: smtpStatusFetchSuccess } = useGetSMTPStatusQuery();
|
||||
const [generateChannelInviteLink, { data: channelInviteLink, isLoading: generatingChannelLink }] =
|
||||
useCreateChannelInviteLinkQuery();
|
||||
const [generateServerInviteLink, { data: serverInviteLink, isLoading: generatingServerLink }] =
|
||||
useCreateServerInviteLinkQuery();
|
||||
const { copied, copy } = useCopy({ enableToast: false });
|
||||
const copyLink = () => {
|
||||
copy(finalLink);
|
||||
@@ -46,11 +39,9 @@ export default function useInviteLink(cid = null) {
|
||||
return {
|
||||
enableSMTP: SMTPEnabled,
|
||||
generating: cid ? generatingChannelLink : generatingServerLink,
|
||||
generateNewLink: cid
|
||||
? generateChannelInviteLink.bind(null, cid)
|
||||
: genServerLink,
|
||||
generateNewLink: cid ? generateChannelInviteLink.bind(null, cid) : genServerLink,
|
||||
link: finalLink,
|
||||
linkCopied: copied,
|
||||
copyLink,
|
||||
copyLink
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,21 +1,13 @@
|
||||
// import React from 'react'
|
||||
import { useSelector } from "react-redux";
|
||||
import {
|
||||
useUpdateChannelMutation,
|
||||
useLazyLeaveChannelQuery,
|
||||
} from "../../app/services/channel";
|
||||
import { useUpdateChannelMutation, useLazyLeaveChannelQuery } from "../../app/services/channel";
|
||||
export default function useLeaveChannel(cid = null) {
|
||||
const { channel, loginUid } = useSelector((store) => {
|
||||
return { channel: store.channels.byId[cid], loginUid: store.authData.uid };
|
||||
});
|
||||
const [
|
||||
update,
|
||||
{ isLoading: transfering, isSuccess: transferSuccess },
|
||||
] = useUpdateChannelMutation();
|
||||
const [
|
||||
leave,
|
||||
{ isLoading: leaving, isSuccess: leaveSuccess },
|
||||
] = useLazyLeaveChannelQuery();
|
||||
const [update, { isLoading: transfering, isSuccess: transferSuccess }] =
|
||||
useUpdateChannelMutation();
|
||||
const [leave, { isLoading: leaving, isSuccess: leaveSuccess }] = useLazyLeaveChannelQuery();
|
||||
const transferOwner = (uid = null) => {
|
||||
if (!uid) return;
|
||||
update({ id: cid, owner: uid });
|
||||
@@ -34,6 +26,6 @@ export default function useLeaveChannel(cid = null) {
|
||||
leaveSuccess,
|
||||
isOwner,
|
||||
transfering,
|
||||
transferSuccess,
|
||||
transferSuccess
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@ import { useLazyGetHistoryMessagesQuery } from "../../app/services/channel";
|
||||
import { useLazyGetHistoryMessagesQuery as useLazyGetDMHistoryMsg } from "../../app/services/contact";
|
||||
|
||||
const getFeedWithPagination = (config) => {
|
||||
const { pageNumber = 1, pageSize = 40, mids = [], isLast = false } =
|
||||
config || {};
|
||||
const { pageNumber = 1, pageSize = 40, mids = [], isLast = false } = config || {};
|
||||
const shadowMids = mids.slice(0);
|
||||
|
||||
if (shadowMids.length == 0)
|
||||
@@ -15,7 +14,7 @@ const getFeedWithPagination = (config) => {
|
||||
pageCount: 0,
|
||||
pageSize,
|
||||
pageNumber: 1,
|
||||
ids: [],
|
||||
ids: []
|
||||
};
|
||||
shadowMids.sort((a, b) => {
|
||||
return Number(a) - Number(b);
|
||||
@@ -34,7 +33,7 @@ const getFeedWithPagination = (config) => {
|
||||
pageCount,
|
||||
pageSize,
|
||||
pageNumber: computedPageNumber,
|
||||
ids,
|
||||
ids
|
||||
};
|
||||
};
|
||||
let curScrollPos = 0;
|
||||
@@ -48,16 +47,13 @@ export default function useMessageFeed({ context = "channel", id = null }) {
|
||||
const [hasMore, setHasMore] = useState(true);
|
||||
const [appends, setAppends] = useState([]);
|
||||
const [items, setItems] = useState([]);
|
||||
const loadMoreMsgsFromServer =
|
||||
context == "channel" ? loadMoreChannelMsgs : loadMoreDmMsgs;
|
||||
const loadMoreMsgsFromServer = context == "channel" ? loadMoreChannelMsgs : loadMoreDmMsgs;
|
||||
const { mids, messageData, loginUid } = useSelector((store) => {
|
||||
return {
|
||||
loginUid: store.authData.uid,
|
||||
mids:
|
||||
context == "channel"
|
||||
? store.channelMessage[id] || []
|
||||
: store.userMessage.byId[id] || [],
|
||||
messageData: store.message,
|
||||
context == "channel" ? store.channelMessage[id] || [] : store.userMessage.byId[id] || [],
|
||||
messageData: store.message
|
||||
};
|
||||
});
|
||||
useEffect(() => {
|
||||
@@ -69,12 +65,9 @@ export default function useMessageFeed({ context = "channel", id = null }) {
|
||||
}, [context, id]);
|
||||
useEffect(() => {
|
||||
if (items.length) {
|
||||
containerRef.current = document.querySelector(
|
||||
`#RUSTCHAT_FEED_${context}_${id}`
|
||||
);
|
||||
containerRef.current = document.querySelector(`#RUSTCHAT_FEED_${context}_${id}`);
|
||||
if (containerRef.current) {
|
||||
const newScroll =
|
||||
containerRef.current.scrollHeight - containerRef.current.clientHeight;
|
||||
const newScroll = containerRef.current.scrollHeight - containerRef.current.clientHeight;
|
||||
containerRef.current.scrollTop = curScrollPos + (newScroll - oldScroll);
|
||||
}
|
||||
}
|
||||
@@ -88,7 +81,7 @@ export default function useMessageFeed({ context = "channel", id = null }) {
|
||||
// 初次
|
||||
const pageInfo = getFeedWithPagination({
|
||||
mids: serverMids,
|
||||
isLast: true,
|
||||
isLast: true
|
||||
});
|
||||
console.log("pull up 2", pageInfo);
|
||||
pageRef.current = pageInfo;
|
||||
@@ -111,8 +104,7 @@ export default function useMessageFeed({ context = "channel", id = null }) {
|
||||
if (container) {
|
||||
const msgFromSelf = loginUid == messageData[newestMsgId]?.from_uid;
|
||||
const scrollDistance =
|
||||
container.scrollHeight -
|
||||
(container.offsetHeight + container.scrollTop);
|
||||
container.scrollHeight - (container.offsetHeight + container.scrollTop);
|
||||
console.log("scrollDistance", msgFromSelf, scrollDistance);
|
||||
if (msgFromSelf) {
|
||||
container.scrollTop = container.scrollHeight;
|
||||
@@ -133,7 +125,7 @@ export default function useMessageFeed({ context = "channel", id = null }) {
|
||||
const [firstMid] = currPageInfo.ids;
|
||||
const { data: newList } = await loadMoreMsgsFromServer({
|
||||
mid: firstMid,
|
||||
id,
|
||||
id
|
||||
});
|
||||
if (newList.length == 0) {
|
||||
setHasMore(false);
|
||||
@@ -145,13 +137,13 @@ export default function useMessageFeed({ context = "channel", id = null }) {
|
||||
// 初始化
|
||||
pageInfo = getFeedWithPagination({
|
||||
mids,
|
||||
isLast: true,
|
||||
isLast: true
|
||||
});
|
||||
} else {
|
||||
const prevPageNumber = currPageInfo.pageNumber - 1;
|
||||
pageInfo = getFeedWithPagination({
|
||||
mids,
|
||||
pageNumber: prevPageNumber,
|
||||
pageNumber: prevPageNumber
|
||||
});
|
||||
}
|
||||
pageRef.current = pageInfo;
|
||||
@@ -177,6 +169,6 @@ export default function useMessageFeed({ context = "channel", id = null }) {
|
||||
hasMore,
|
||||
pullUp,
|
||||
pullDown,
|
||||
list: items,
|
||||
list: items
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,10 +4,8 @@ import { useLazyGetArchiveMessageQuery } from "../../app/services/message";
|
||||
export default function useNormalizeMessage() {
|
||||
const [filePath, setFilePath] = useState(null);
|
||||
const [normalizedMessages, setNormalizedMessages] = useState(null);
|
||||
const [
|
||||
getArchiveMessage,
|
||||
{ data, isError, isLoading, isSuccess },
|
||||
] = useLazyGetArchiveMessageQuery();
|
||||
const [getArchiveMessage, { data, isError, isLoading, isSuccess }] =
|
||||
useLazyGetArchiveMessageQuery();
|
||||
useEffect(() => {
|
||||
if (data && isSuccess) {
|
||||
const msgs = normalizeArchiveData(data, filePath);
|
||||
@@ -28,6 +26,6 @@ export default function useNormalizeMessage() {
|
||||
messages: normalizedMessages,
|
||||
isError,
|
||||
isLoading,
|
||||
isSuccess,
|
||||
isSuccess
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
// import { useNavigate } from "react-router-dom";
|
||||
const isSafariBrowser = () =>
|
||||
navigator.userAgent.indexOf("Safari") > -1 &&
|
||||
navigator.userAgent.indexOf("Chrome") <= -1;
|
||||
navigator.userAgent.indexOf("Safari") > -1 && navigator.userAgent.indexOf("Chrome") <= -1;
|
||||
export default function useNotification() {
|
||||
// const navigate = useNavigate();
|
||||
// granted default denied /
|
||||
@@ -17,18 +16,13 @@ export default function useNotification() {
|
||||
};
|
||||
document.addEventListener("visibilitychange", visibleChangeHandler);
|
||||
if (!isSafariBrowser) {
|
||||
navigator.permissions
|
||||
.query({ name: "notifications" })
|
||||
.then(function (permissionStatus) {
|
||||
console.log(
|
||||
"notifications permission status is ",
|
||||
permissionStatus.state
|
||||
);
|
||||
permissionStatus.onchange = notifyPermissionChangeHandler.bind(
|
||||
null,
|
||||
permissionStatus.state
|
||||
);
|
||||
});
|
||||
navigator.permissions.query({ name: "notifications" }).then(function (permissionStatus) {
|
||||
console.log("notifications permission status is ", permissionStatus.state);
|
||||
permissionStatus.onchange = notifyPermissionChangeHandler.bind(
|
||||
null,
|
||||
permissionStatus.state
|
||||
);
|
||||
});
|
||||
}
|
||||
return () => {
|
||||
document.removeEventListener("visibilitychange", visibleChangeHandler);
|
||||
@@ -48,7 +42,7 @@ export default function useNotification() {
|
||||
const {
|
||||
title = "New Message",
|
||||
body = "You have one new message",
|
||||
icon = "https://static.nicegoodthings.com/project/ext/webrowse.logo.png",
|
||||
icon = "https://static.nicegoodthings.com/project/ext/webrowse.logo.png"
|
||||
} = payload;
|
||||
new Notification(title, { body, icon });
|
||||
// const n = new Notification(title, { body, icon });
|
||||
|
||||
@@ -12,6 +12,6 @@ export default function usePWABadge() {
|
||||
}, []);
|
||||
|
||||
return {
|
||||
isSupported: badge.isSupported(),
|
||||
isSupported: badge.isSupported()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,22 +1,17 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import {
|
||||
usePinMessageMutation,
|
||||
useUnpinMessageMutation,
|
||||
} from "../../app/services/message";
|
||||
import { usePinMessageMutation, useUnpinMessageMutation } from "../../app/services/message";
|
||||
export default function usePinMessage(cid = null) {
|
||||
const [pins, setPins] = useState([]);
|
||||
const { channel, loginUser } = useSelector((store) => {
|
||||
return {
|
||||
channel: store.channels.byId[cid],
|
||||
loginUser: store.contacts.byId[store.authData.uid],
|
||||
loginUser: store.contacts.byId[store.authData.uid]
|
||||
};
|
||||
});
|
||||
const [pin, { isError, isLoading, isSuccess }] = usePinMessageMutation();
|
||||
const [
|
||||
unpin,
|
||||
{ isError: isUnpinError, isLoading: isUnpining, isSuccess: isUnpinSuccess },
|
||||
] = useUnpinMessageMutation();
|
||||
const [unpin, { isError: isUnpinError, isLoading: isUnpining, isSuccess: isUnpinSuccess }] =
|
||||
useUnpinMessageMutation();
|
||||
const pinMessage = (mid) => {
|
||||
if (!mid || !cid) return;
|
||||
pin({ mid, gid: +cid });
|
||||
@@ -50,6 +45,6 @@ export default function usePinMessage(cid = null) {
|
||||
isSuccess,
|
||||
isUnpinError,
|
||||
isUnpining,
|
||||
isUnpinSuccess,
|
||||
isUnpinSuccess
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ import { removeChannelMsg } from "../../app/slices/message.channel";
|
||||
import { removeUserMsg } from "../../app/slices/message.user";
|
||||
export default function useRemoveLocalMessage({ context = "user", id = 0 }) {
|
||||
const dispatch = useDispatch();
|
||||
const removeContextMessage =
|
||||
context == "channel" ? removeChannelMsg : removeUserMsg;
|
||||
const removeContextMessage = context == "channel" ? removeChannelMsg : removeUserMsg;
|
||||
const removeLocalMessage = (mid) => {
|
||||
dispatch(removeContextMessage({ id, mid }));
|
||||
dispatch(removeMessage(mid));
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
// import second from 'first'
|
||||
import {
|
||||
removeReplyingMessage,
|
||||
addReplyingMessage,
|
||||
} from "../../app/slices/message";
|
||||
import { removeReplyingMessage, addReplyingMessage } from "../../app/slices/message";
|
||||
import { useSendChannelMsgMutation } from "../../app/services/channel";
|
||||
import { useSendMsgMutation } from "../../app/services/contact";
|
||||
import { useReplyMessageMutation } from "../../app/services/message";
|
||||
@@ -11,38 +8,23 @@ import toast from "react-hot-toast";
|
||||
export default function useSendMessage(props) {
|
||||
const { context = "user", from = null, to = null } = props || {};
|
||||
const dispatch = useDispatch();
|
||||
const stageFiles = useSelector(
|
||||
(store) => store.ui.uploadFiles[`${context}_${to}`] || []
|
||||
);
|
||||
const [
|
||||
replyMessage,
|
||||
{ isError: replyErr, isLoading: replying, isSuccess: replySuccess },
|
||||
] = useReplyMessageMutation();
|
||||
const stageFiles = useSelector((store) => store.ui.uploadFiles[`${context}_${to}`] || []);
|
||||
const [replyMessage, { isError: replyErr, isLoading: replying, isSuccess: replySuccess }] =
|
||||
useReplyMessageMutation();
|
||||
const [
|
||||
sendChannelMsg,
|
||||
{
|
||||
isLoading: channelSending,
|
||||
isSuccess: channelSuccess,
|
||||
isError: channelError,
|
||||
},
|
||||
{ isLoading: channelSending, isSuccess: channelSuccess, isError: channelError }
|
||||
] = useSendChannelMsgMutation();
|
||||
const [
|
||||
sendUserMsg,
|
||||
{ isLoading: userSending, isSuccess: userSuccess, isError: userError },
|
||||
] = useSendMsgMutation();
|
||||
const [sendUserMsg, { isLoading: userSending, isSuccess: userSuccess, isError: userError }] =
|
||||
useSendMsgMutation();
|
||||
const sendFn = context == "user" ? sendUserMsg : sendChannelMsg;
|
||||
const sendMessages = async ({
|
||||
type = "text",
|
||||
content,
|
||||
users = [],
|
||||
channels = [],
|
||||
}) => {
|
||||
const sendMessages = async ({ type = "text", content, users = [], channels = [] }) => {
|
||||
if (users.length) {
|
||||
for await (const uid of users) {
|
||||
await sendUserMsg({
|
||||
type,
|
||||
id: uid,
|
||||
content,
|
||||
content
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -51,7 +33,7 @@ export default function useSendMessage(props) {
|
||||
await sendChannelMsg({
|
||||
type,
|
||||
id: cid,
|
||||
content,
|
||||
content
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -71,7 +53,7 @@ export default function useSendMessage(props) {
|
||||
type,
|
||||
content,
|
||||
context,
|
||||
from_uid: from,
|
||||
from_uid: from
|
||||
});
|
||||
} else {
|
||||
await sendFn({
|
||||
@@ -80,7 +62,7 @@ export default function useSendMessage(props) {
|
||||
properties: { ...properties },
|
||||
type,
|
||||
from_uid: from,
|
||||
...rest,
|
||||
...rest
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -101,6 +83,6 @@ export default function useSendMessage(props) {
|
||||
sendMessage,
|
||||
isError: channelError || userError || replyErr,
|
||||
isSending: userSending || channelSending || replying,
|
||||
isSuccess: channelSuccess || userSuccess || replySuccess,
|
||||
isSuccess: channelSuccess || userSuccess || replySuccess
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,18 +1,8 @@
|
||||
import { batch } from "react-redux";
|
||||
import {
|
||||
addChannelMsg,
|
||||
removeChannelMsg,
|
||||
} from "../../../app/slices/message.channel";
|
||||
import {
|
||||
addMessage,
|
||||
removeMessage,
|
||||
updateMessage,
|
||||
} from "../../../app/slices/message";
|
||||
import { addChannelMsg, removeChannelMsg } from "../../../app/slices/message.channel";
|
||||
import { addMessage, removeMessage, updateMessage } from "../../../app/slices/message";
|
||||
import { toggleReactionMessage } from "../../../app/slices/message.reaction";
|
||||
import {
|
||||
addFileMessage,
|
||||
removeFileMessage,
|
||||
} from "../../../app/slices/message.file";
|
||||
import { addFileMessage, removeFileMessage } from "../../../app/slices/message.file";
|
||||
import { addUserMsg, removeUserMsg } from "../../../app/slices/message.user";
|
||||
import { updateAfterMid } from "../../../app/slices/footprint";
|
||||
import { ContentTypes } from "../../../app/config";
|
||||
@@ -29,8 +19,8 @@ const handler = (data, dispatch, currState) => {
|
||||
type,
|
||||
properties,
|
||||
expires_in,
|
||||
detail: innerDetail,
|
||||
},
|
||||
detail: innerDetail
|
||||
}
|
||||
} = data;
|
||||
const common = {
|
||||
from_uid,
|
||||
@@ -38,7 +28,7 @@ const handler = (data, dispatch, currState) => {
|
||||
content,
|
||||
content_type,
|
||||
properties,
|
||||
expires_in,
|
||||
expires_in
|
||||
};
|
||||
switch (type) {
|
||||
case "normal":
|
||||
@@ -64,7 +54,7 @@ const handler = (data, dispatch, currState) => {
|
||||
mid,
|
||||
// 如果是自己发的消息,就是已读
|
||||
read,
|
||||
...common,
|
||||
...common
|
||||
})
|
||||
);
|
||||
// 未推送完 or 不是自己发的消息
|
||||
@@ -74,7 +64,7 @@ const handler = (data, dispatch, currState) => {
|
||||
appendMessage({
|
||||
id,
|
||||
mid,
|
||||
local_id: properties ? properties.local_id : null,
|
||||
local_id: properties ? properties.local_id : null
|
||||
})
|
||||
);
|
||||
// 加到file message 列表
|
||||
@@ -94,7 +84,7 @@ const handler = (data, dispatch, currState) => {
|
||||
reply_mid: detailMid,
|
||||
// 如果是自己发的消息,就是已读
|
||||
read,
|
||||
...common,
|
||||
...common
|
||||
})
|
||||
);
|
||||
// 未推送完 or 不是自己发的消息
|
||||
@@ -103,7 +93,7 @@ const handler = (data, dispatch, currState) => {
|
||||
appendMessage({
|
||||
id,
|
||||
mid,
|
||||
local_id: properties ? properties.local_id : null,
|
||||
local_id: properties ? properties.local_id : null
|
||||
})
|
||||
);
|
||||
// }
|
||||
@@ -112,8 +102,7 @@ const handler = (data, dispatch, currState) => {
|
||||
break;
|
||||
case "reaction":
|
||||
{
|
||||
const removeContextMessage =
|
||||
to == "user" ? removeUserMsg : removeChannelMsg;
|
||||
const removeContextMessage = to == "user" ? removeUserMsg : removeChannelMsg;
|
||||
const { type, action, content, content_type, properties } = innerDetail;
|
||||
switch (type) {
|
||||
case "like":
|
||||
@@ -124,7 +113,7 @@ const handler = (data, dispatch, currState) => {
|
||||
from_uid,
|
||||
mid: detailMid,
|
||||
rid: mid,
|
||||
action,
|
||||
action
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -150,7 +139,7 @@ const handler = (data, dispatch, currState) => {
|
||||
content,
|
||||
content_type,
|
||||
properties,
|
||||
edited: true,
|
||||
edited: true
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import {
|
||||
fetchEventSource,
|
||||
EventStreamContentType,
|
||||
} from "@microsoft/fetch-event-source";
|
||||
import { fetchEventSource, EventStreamContentType } from "@microsoft/fetch-event-source";
|
||||
import toast from "react-hot-toast";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
@@ -14,18 +11,15 @@ import {
|
||||
addChannel,
|
||||
removeChannel,
|
||||
updateChannel,
|
||||
updatePinMessage,
|
||||
updatePinMessage
|
||||
} from "../../../app/slices/channels";
|
||||
import {
|
||||
updateUsersVersion,
|
||||
updateReadChannels,
|
||||
updateReadUsers,
|
||||
updateMute,
|
||||
updateMute
|
||||
} from "../../../app/slices/footprint";
|
||||
import {
|
||||
updateUsersByLogs,
|
||||
updateUsersStatus,
|
||||
} from "../../../app/slices/contacts";
|
||||
import { updateUsersByLogs, updateUsersStatus } from "../../../app/slices/contacts";
|
||||
import { resetAuthData } from "../../../app/slices/auth.data";
|
||||
import chatMessageHandler from "./chat.handler";
|
||||
import store from "../../../app/store";
|
||||
@@ -52,7 +46,7 @@ export default function useStreaming() {
|
||||
const {
|
||||
authData: { uid: loginUid },
|
||||
ui: { ready, online },
|
||||
footprint: { afterMid, usersVersion, readUsers, readChannels },
|
||||
footprint: { afterMid, usersVersion, readUsers, readChannels }
|
||||
} = useSelector((store) => store);
|
||||
const [renewToken] = useRenewMutation();
|
||||
const dispatch = useDispatch();
|
||||
@@ -64,7 +58,7 @@ export default function useStreaming() {
|
||||
if (initialized || initializing) return;
|
||||
// 如果token快要过期,先renew
|
||||
const {
|
||||
authData: { token, expireTime = +new Date(), refreshToken },
|
||||
authData: { token, expireTime = +new Date(), refreshToken }
|
||||
} = store.getState();
|
||||
let api_token = token;
|
||||
const tokenAlmostExpire = dayjs().isAfter(new Date(expireTime - 20 * 1000));
|
||||
@@ -72,10 +66,10 @@ export default function useStreaming() {
|
||||
if (tokenAlmostExpire) {
|
||||
const {
|
||||
data: { token: newToken },
|
||||
isError,
|
||||
isError
|
||||
} = await renewToken({
|
||||
token,
|
||||
refreshToken,
|
||||
refreshToken
|
||||
});
|
||||
if (isError) return;
|
||||
api_token = newToken;
|
||||
@@ -87,25 +81,18 @@ export default function useStreaming() {
|
||||
`${BASE_URL}/user/events?${getQueryString({
|
||||
"api-key": api_token,
|
||||
users_version: usersVersion,
|
||||
after_mid: afterMid,
|
||||
after_mid: afterMid
|
||||
})}`,
|
||||
{
|
||||
openWhenHidden: true,
|
||||
signal: controller.signal,
|
||||
async onopen(response) {
|
||||
initializing = false;
|
||||
if (
|
||||
response.ok &&
|
||||
response.headers.get("content-type") === EventStreamContentType
|
||||
) {
|
||||
if (response.ok && response.headers.get("content-type") === EventStreamContentType) {
|
||||
console.log("sse everything ok");
|
||||
initialized = true;
|
||||
return; // everything's good
|
||||
} else if (
|
||||
response.status >= 400 &&
|
||||
response.status < 500 &&
|
||||
response.status !== 429
|
||||
) {
|
||||
} else if (response.status >= 400 && response.status < 500 && response.status !== 429) {
|
||||
// 重新登录
|
||||
// client-side errors are usually non-retriable:
|
||||
console.log("sse debug: open fatal");
|
||||
@@ -168,9 +155,7 @@ export default function useStreaming() {
|
||||
{
|
||||
const arr = data[key];
|
||||
if (arr && arr.length) {
|
||||
const _key = key.endsWith("users")
|
||||
? "add_users"
|
||||
: "add_groups";
|
||||
const _key = key.endsWith("users") ? "add_users" : "add_groups";
|
||||
dispatch(updateMute({ [_key]: arr }));
|
||||
}
|
||||
}
|
||||
@@ -180,9 +165,7 @@ export default function useStreaming() {
|
||||
{
|
||||
const arr = data[key];
|
||||
if (arr && arr.length) {
|
||||
const _key = key.endsWith("users")
|
||||
? "remove_users"
|
||||
: "remove_groups";
|
||||
const _key = key.endsWith("users") ? "remove_users" : "remove_groups";
|
||||
dispatch(updateMute({ [_key]: arr }));
|
||||
}
|
||||
}
|
||||
@@ -198,8 +181,7 @@ export default function useStreaming() {
|
||||
case "users_state_changed":
|
||||
{
|
||||
let { type, ...rest } = data;
|
||||
const onlines =
|
||||
type == "users_state_changed" ? [rest] : rest.users;
|
||||
const onlines = type == "users_state_changed" ? [rest] : rest.users;
|
||||
dispatch(updateUsersStatus(onlines));
|
||||
}
|
||||
break;
|
||||
@@ -234,7 +216,7 @@ export default function useStreaming() {
|
||||
dispatch(
|
||||
updateChannel({
|
||||
id: gid,
|
||||
...rest,
|
||||
...rest
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -248,7 +230,7 @@ export default function useStreaming() {
|
||||
updateChannel({
|
||||
operation: "add_member",
|
||||
id: gid,
|
||||
members: uids,
|
||||
members: uids
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -263,7 +245,7 @@ export default function useStreaming() {
|
||||
updateChannel({
|
||||
operation: "remove_member",
|
||||
id: gid,
|
||||
members: uids,
|
||||
members: uids
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -285,7 +267,7 @@ export default function useStreaming() {
|
||||
ready,
|
||||
loginUid,
|
||||
readUsers,
|
||||
readChannels,
|
||||
readChannels
|
||||
});
|
||||
}
|
||||
break;
|
||||
@@ -321,7 +303,7 @@ export default function useStreaming() {
|
||||
// do nothing to automatically retry. You can also
|
||||
// return a specific retry interval here.
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
);
|
||||
initializing = false;
|
||||
@@ -354,6 +336,6 @@ export default function useStreaming() {
|
||||
return {
|
||||
setStreamingReady,
|
||||
startStreaming,
|
||||
stopStreaming,
|
||||
stopStreaming
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,10 +3,7 @@ import { useDispatch, useSelector } from "react-redux";
|
||||
// import { ContentTypes } from "../../app/config";
|
||||
import { updateUploadFiles } from "../../app/slices/ui";
|
||||
import BASE_URL, { FILE_SLICE_SIZE } from "../../app/config";
|
||||
import {
|
||||
usePrepareUploadFileMutation,
|
||||
useUploadFileMutation,
|
||||
} from "../../app/services/message";
|
||||
import { usePrepareUploadFileMutation, useUploadFileMutation } from "../../app/services/message";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
export default function useUploadFile(props = {}) {
|
||||
@@ -15,7 +12,7 @@ export default function useUploadFile(props = {}) {
|
||||
const { stageFiles, replying } = useSelector((store) => {
|
||||
return {
|
||||
stageFiles: store.ui.uploadFiles[`${context}_${id}`] || [],
|
||||
replying: store.message.replying[`${context}_${id}`],
|
||||
replying: store.message.replying[`${context}_${id}`]
|
||||
};
|
||||
});
|
||||
const [data, setData] = useState(null);
|
||||
@@ -23,13 +20,11 @@ export default function useUploadFile(props = {}) {
|
||||
const canneledRef = useRef(false);
|
||||
const sliceUploadedCountRef = useRef(0);
|
||||
const totalSliceCountRef = useRef(1);
|
||||
const [
|
||||
prepareUploadFile,
|
||||
{ isLoading: isPreparing, isSuccess: isPrepared },
|
||||
] = usePrepareUploadFileMutation();
|
||||
const [prepareUploadFile, { isLoading: isPreparing, isSuccess: isPrepared }] =
|
||||
usePrepareUploadFileMutation();
|
||||
const [
|
||||
uploadFileFn,
|
||||
{ isLoading: isUploading, isSuccess: isUploaded, isError: uploadFileError },
|
||||
{ isLoading: isUploading, isSuccess: isUploaded, isError: uploadFileError }
|
||||
] = useUploadFileMutation();
|
||||
|
||||
const uploadChunk = (data) => {
|
||||
@@ -46,12 +41,12 @@ export default function useUploadFile(props = {}) {
|
||||
const {
|
||||
name = `rustchat-${+new Date()}.${file.type.split("/")[1]}`,
|
||||
type: file_type,
|
||||
size: file_size,
|
||||
size: file_size
|
||||
} = file;
|
||||
// 拿file id
|
||||
const { data: file_id } = await prepareUploadFile({
|
||||
content_type: file_type,
|
||||
filename: name,
|
||||
filename: name
|
||||
});
|
||||
console.log("file id", file_id);
|
||||
|
||||
@@ -76,17 +71,13 @@ export default function useUploadFile(props = {}) {
|
||||
// 退出循环
|
||||
if (canneledRef.current) break;
|
||||
try {
|
||||
const chunk = file.slice(
|
||||
FILE_SLICE_SIZE * idx,
|
||||
FILE_SLICE_SIZE * (idx + 1),
|
||||
file_type
|
||||
);
|
||||
const chunk = file.slice(FILE_SLICE_SIZE * idx, FILE_SLICE_SIZE * (idx + 1), file_type);
|
||||
|
||||
uploadResult = await uploadChunk({
|
||||
file_id,
|
||||
chunk,
|
||||
// 如果是最后一个chunk,标记下
|
||||
is_last: idx == _arr.length - 1,
|
||||
is_last: idx == _arr.length - 1
|
||||
});
|
||||
sliceUploadedCountRef.current++;
|
||||
} catch (error) {
|
||||
@@ -98,7 +89,7 @@ export default function useUploadFile(props = {}) {
|
||||
}
|
||||
// setUploadingFile(false);
|
||||
const {
|
||||
data: { path, size, hash },
|
||||
data: { path, size, hash }
|
||||
} = uploadResult;
|
||||
const encodedPath = encodeURIComponent(path);
|
||||
const res = {
|
||||
@@ -111,7 +102,7 @@ export default function useUploadFile(props = {}) {
|
||||
thumbnail: file_type.startsWith("image")
|
||||
? `${BASE_URL}/resource/file?file_path=${encodedPath}&thumbnail=true`
|
||||
: "",
|
||||
download: `${BASE_URL}/resource/file?file_path=${encodedPath}&download=true`,
|
||||
download: `${BASE_URL}/resource/file?file_path=${encodedPath}&download=true`
|
||||
};
|
||||
setData(res);
|
||||
return res;
|
||||
@@ -120,9 +111,7 @@ export default function useUploadFile(props = {}) {
|
||||
canneledRef.current = true;
|
||||
};
|
||||
const removeStageFile = (idx) => {
|
||||
dispatch(
|
||||
updateUploadFiles({ context, id, operation: "remove", index: idx })
|
||||
);
|
||||
dispatch(updateUploadFiles({ context, id, operation: "remove", index: idx }));
|
||||
};
|
||||
const addStageFile = (fileData = {}) => {
|
||||
if (replying) {
|
||||
@@ -141,7 +130,7 @@ export default function useUploadFile(props = {}) {
|
||||
id,
|
||||
operation: "update",
|
||||
index: idx,
|
||||
...data,
|
||||
...data
|
||||
})
|
||||
);
|
||||
};
|
||||
@@ -149,9 +138,7 @@ export default function useUploadFile(props = {}) {
|
||||
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,
|
||||
@@ -159,6 +146,6 @@ export default function useUploadFile(props = {}) {
|
||||
addStageFile,
|
||||
resetStageFiles,
|
||||
removeStageFile,
|
||||
updateStageFile,
|
||||
updateStageFile
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user