Skip to content

Commit

Permalink
add rootCommonId to last common from feed and change persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymikhadyuk committed Nov 14, 2023
1 parent 7525283 commit 1931423
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/pages/commonFeed/CommonFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ const CommonFeedComponent: FC<CommonFeedProps> = (props) => {
image: common.image,
isProject: checkIsProject(common),
memberCount: common.memberCount,
rootCommonId: common.rootCommonId,
}
: null,
}),
Expand Down
1 change: 1 addition & 0 deletions src/store/states/commonLayout/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface CommonLayoutState {
image: string;
isProject: boolean;
memberCount: number;
rootCommonId?: string;
} | null;
} | null;
commons: ProjectsStateItem[];
Expand Down
4 changes: 2 additions & 2 deletions src/store/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import createSagaMiddleware from "redux-saga";
import { AppState } from "@/shared/interfaces";
import rootReducer from "./reducer";
import appSagas from "./saga";
import { inboxTransform } from "./transforms";
import { inboxTransform, lastCommonFromFeedTransform } from "./transforms";

const persistConfig: PersistConfig<AppState> = {
key: "root",
Expand All @@ -32,7 +32,7 @@ const persistConfig: PersistConfig<AppState> = {
"multipleSpacesLayout",
],
stateReconciler: autoMergeLevel2,
transforms: [inboxTransform],
transforms: [inboxTransform, lastCommonFromFeedTransform],
};

const sagaMiddleware = createSagaMiddleware();
Expand Down
19 changes: 19 additions & 0 deletions src/store/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createTransform } from "redux-persist";
import { deserializeFeedLayoutItemWithFollowData } from "@/shared/interfaces";
import { convertObjectDatesToFirestoreTimestamps } from "@/shared/utils";
import { getFeedLayoutItemDateForSorting } from "@/store/states/inbox/utils";
import { CommonLayoutState } from "./states/commonLayout";
import { InboxItems, InboxState } from "./states/inbox";

export const inboxTransform = createTransform(
Expand Down Expand Up @@ -43,3 +44,21 @@ export const inboxTransform = createTransform(
}),
{ whitelist: ["inbox"] },
);

export const lastCommonFromFeedTransform = createTransform(
(inboundState: CommonLayoutState) => {
const { lastCommonFromFeed } = inboundState;

return {
...inboundState,
lastCommonFromFeed: lastCommonFromFeed?.data?.rootCommonId
? {
id: lastCommonFromFeed.data.rootCommonId,
data: null,
}
: lastCommonFromFeed,
};
},
(outboundState: CommonLayoutState) => outboundState,
{ whitelist: ["commonLayout"] },
);

0 comments on commit 1931423

Please sign in to comment.