diff --git a/lib/reducers/community-reducer.js b/lib/reducers/community-reducer.js --- a/lib/reducers/community-reducer.js +++ b/lib/reducers/community-reducer.js @@ -1,7 +1,12 @@ // @flow import { setClientDBStoreActionType } from '../actions/client-db-store-actions.js'; -import { addCommunityActionType } from '../actions/community-actions.js'; +import { + addCommunityActionType, + fetchCommunityInfosActionTypes, + createOrUpdateFarcasterChannelTagActionTypes, + deleteFarcasterChannelTagActionTypes, +} from '../actions/community-actions.js'; import { communityStoreOpsHandlers, type CommunityStoreOperation, @@ -19,7 +24,62 @@ +communityStore: CommunityStore, +communityStoreOperations: $ReadOnlyArray, } { - if (action.type === addCommunityActionType) { + if (action.type === fetchCommunityInfosActionTypes.success) { + const replaceOperations = action.payload.communityInfos.map(community => { + const { id, ...communityInfo } = community; + + return { + type: 'replace_community', + payload: { + id, + communityInfo, + }, + }; + }); + + return { + communityStore: processStoreOps(state, replaceOperations), + communityStoreOperations: replaceOperations, + }; + } else if ( + action.type === createOrUpdateFarcasterChannelTagActionTypes.success + ) { + const communityID = action.payload.commCommunityID; + + const replaceOperation: ReplaceCommunityOperation = { + type: 'replace_community', + payload: { + id: communityID, + communityInfo: { + ...state.communityInfos[communityID], + farcasterChannelID: action.payload.farcasterChannelID, + }, + }, + }; + + return { + communityStore: processStoreOps(state, [replaceOperation]), + communityStoreOperations: [replaceOperation], + }; + } else if (action.type === deleteFarcasterChannelTagActionTypes.success) { + const communityID = action.payload.commCommunityID; + + const replaceOperation: ReplaceCommunityOperation = { + type: 'replace_community', + payload: { + id: communityID, + communityInfo: { + ...state.communityInfos[communityID], + farcasterChannelID: null, + }, + }, + }; + + return { + communityStore: processStoreOps(state, [replaceOperation]), + communityStoreOperations: [replaceOperation], + }; + } else if (action.type === addCommunityActionType) { const replaceOperation: ReplaceCommunityOperation = { type: 'replace_community', payload: {