@replyke/core
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
36 lines • 1.47 kB
JavaScript
import { useEffect, useState } from "react";
import { useReplykeDispatch } from "../../../store/hooks";
import { setConversation } from "../../../store/slices/chatSlice";
import useAxiosPrivate from "../../../config/useAxiosPrivate";
import useProject from "../../projects/useProject";
import { handleError } from "../../../utils/handleError";
function useFetchSpaceConversation({ spaceId, }) {
const dispatch = useReplykeDispatch();
const { projectId } = useProject();
const axios = useAxiosPrivate();
const [conversation, setLocalConversation] = useState(null);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (!projectId || !spaceId)
return;
const fetch = async () => {
setLoading(true);
try {
const response = await axios.get(`/${projectId}/chat/spaces/${spaceId}/conversation`);
const data = response.data;
dispatch(setConversation(data));
setLocalConversation(data);
}
catch (err) {
handleError(err, "Failed to load space conversation");
}
finally {
setLoading(false);
}
};
fetch();
}, [projectId, spaceId]); // eslint-disable-line react-hooks/exhaustive-deps
return { conversation, loading };
}
export default useFetchSpaceConversation;
//# sourceMappingURL=useFetchSpaceConversation.js.map