UNPKG

@replyke/core

Version:

Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.

41 lines 1.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = require("react"); const hooks_1 = require("../../../store/hooks"); const chatSlice_1 = require("../../../store/slices/chatSlice"); const useAxiosPrivate_1 = __importDefault(require("../../../config/useAxiosPrivate")); const useProject_1 = __importDefault(require("../../projects/useProject")); const handleError_1 = require("../../../utils/handleError"); function useFetchSpaceConversation({ spaceId, }) { const dispatch = (0, hooks_1.useReplykeDispatch)(); const { projectId } = (0, useProject_1.default)(); const axios = (0, useAxiosPrivate_1.default)(); const [conversation, setLocalConversation] = (0, react_1.useState)(null); const [loading, setLoading] = (0, react_1.useState)(false); (0, react_1.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((0, chatSlice_1.setConversation)(data)); setLocalConversation(data); } catch (err) { (0, handleError_1.handleError)(err, "Failed to load space conversation"); } finally { setLoading(false); } }; fetch(); }, [projectId, spaceId]); // eslint-disable-line react-hooks/exhaustive-deps return { conversation, loading }; } exports.default = useFetchSpaceConversation; //# sourceMappingURL=useFetchSpaceConversation.js.map