"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.usePostSubscription = void 0;
var _react = require("react");
var _tsSdkReactNative = require("@amityco/ts-sdk-react-native");
const usePostSubscription = postId => {
  const [subscribedPost, setSubscribedPost] = (0, _react.useState)(null);
  (0, _react.useEffect)(() => {
    let unsubscribe;
    if (postId) {
      unsubscribe = _tsSdkReactNative.PostRepository.getPost(postId, ({
        data
      }) => {
        setSubscribedPost(data);
      });
    }
    return () => {
      unsubscribe && unsubscribe();
    };
  }, [postId]);
  (0, _react.useEffect)(() => {
    let unsubscribe;
    if (subscribedPost) {
      unsubscribe = (0, _tsSdkReactNative.subscribeTopic)((0, _tsSdkReactNative.getPostTopic)(subscribedPost));
    }
    return () => {
      unsubscribe && unsubscribe();
    };
  }, [subscribedPost]);
  return {
    subscribedPost
  };
};
exports.usePostSubscription = usePostSubscription;
//# sourceMappingURL=usePostSubscription.js.map