UNPKG

@replyke/core

Version:

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

27 lines 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = useAddAccount; const react_1 = require("react"); const hooks_1 = require("../../store/hooks"); const authSlice_1 = require("../../store/slices/authSlice"); const userSlice_1 = require("../../store/slices/userSlice"); const accountsSlice_1 = require("../../store/slices/accountsSlice"); const baseApi_1 = require("../../store/api/baseApi"); function useAddAccount() { const dispatch = (0, hooks_1.useReplykeDispatch)(); const accounts = (0, hooks_1.useReplykeSelector)(accountsSlice_1.selectAccounts); const canAddAccount = Object.keys(accounts).length < accountsSlice_1.MAX_ACCOUNTS; const addAccount = (0, react_1.useCallback)(() => { if (!canAddAccount) return; // Clear active auth state so the sign-in UI appears. // Existing accounts remain safely in the accounts map. // After the user signs in, useAccountSync auto-upserts the new account. dispatch((0, authSlice_1.resetAuth)()); dispatch((0, userSlice_1.clearUser)()); dispatch((0, accountsSlice_1.setActiveAccount)(null)); dispatch(baseApi_1.baseApi.util.resetApiState()); }, [dispatch, canAddAccount]); return { addAccount, canAddAccount }; } //# sourceMappingURL=useAddAccount.js.map