UNPKG

@replyke/core

Version:

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

76 lines 3.16 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.userReducer = exports.selectUserById = exports.selectUserError = exports.selectCurrentProjectId = exports.selectUserUpdating = exports.selectUserLoading = exports.selectUser = exports.updateUserOptimistic = exports.clearError = exports.setError = exports.setUpdating = exports.setLoading = exports.setProjectContext = exports.clearUser = exports.setUser = void 0; const toolkit_1 = require("@reduxjs/toolkit"); const initialState = { user: null, loading: false, updating: false, currentProjectId: undefined, error: null, }; const userSlice = (0, toolkit_1.createSlice)({ name: 'user', initialState, reducers: { // User data management setUser: (state, action) => { state.user = action.payload; state.error = null; }, clearUser: (state) => { state.user = null; state.error = null; }, // Project context setProjectContext: (state, action) => { if (state.currentProjectId !== action.payload) { state.currentProjectId = action.payload; } }, // Loading states setLoading: (state, action) => { state.loading = action.payload; }, setUpdating: (state, action) => { state.updating = action.payload; }, // Error handling setError: (state, action) => { state.error = action.payload; }, clearError: (state) => { state.error = null; }, // Optimistic updates (will be used by RTK Query) updateUserOptimistic: (state, action) => { if (state.user) { state.user = { ...state.user, ...action.payload }; } }, }, }); // Actions _a = userSlice.actions, exports.setUser = _a.setUser, exports.clearUser = _a.clearUser, exports.setProjectContext = _a.setProjectContext, exports.setLoading = _a.setLoading, exports.setUpdating = _a.setUpdating, exports.setError = _a.setError, exports.clearError = _a.clearError, exports.updateUserOptimistic = _a.updateUserOptimistic; // Selectors - use namespaced state for dual-mode support const selectUser = (state) => state.replyke.user.user; exports.selectUser = selectUser; const selectUserLoading = (state) => state.replyke.user.loading; exports.selectUserLoading = selectUserLoading; const selectUserUpdating = (state) => state.replyke.user.updating; exports.selectUserUpdating = selectUserUpdating; const selectCurrentProjectId = (state) => state.replyke.user.currentProjectId; exports.selectCurrentProjectId = selectCurrentProjectId; const selectUserError = (state) => state.replyke.user.error; exports.selectUserError = selectUserError; // Complex selectors const selectUserById = (userId) => (state) => { const user = (0, exports.selectUser)(state); return user?.id === userId ? user : null; }; exports.selectUserById = selectUserById; // Reducer exports.userReducer = userSlice.reducer; exports.default = userSlice; //# sourceMappingURL=userSlice.js.map