Skip to content

Commit e89f172

Browse files
authored
Merge pull request #52 from MayurKharat0390/fix/friends-tab-state-persistence
fix(friends): persist connection followingIds state in module scope a…
2 parents 4c0af43 + e4040e4 commit e89f172

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/services/friendsService.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,28 @@ const developers = [
9797
}
9898
];
9999

100+
let activeFollowingIds = ["sarah_c", "marcusv", "aiko_t", "sofia_r"];
101+
100102
export const initialConnectionState = {
101103
followingIds: ["sarah_c", "marcusv", "aiko_t", "sofia_r"],
102104
followerIds: ["sarah_c", "elena_r", "tariq_m", "leo_d", "priya_shah"]
103105
};
104106

105107
export const getSocialGraph = () => ({
106108
developers,
107-
followingIds: initialConnectionState.followingIds,
109+
followingIds: activeFollowingIds,
108110
followerIds: initialConnectionState.followerIds
109111
});
110112

111113
export const toggleFollowStatus = (followingIds, developerId) => {
114+
let updatedIds;
112115
if (followingIds.includes(developerId)) {
113-
return followingIds.filter((id) => id !== developerId);
116+
updatedIds = followingIds.filter((id) => id !== developerId);
117+
} else {
118+
updatedIds = [...followingIds, developerId];
114119
}
115-
116-
return [...followingIds, developerId];
120+
activeFollowingIds = updatedIds;
121+
return updatedIds;
117122
};
118123

119124
export const hydrateConnections = ({ followingIds, followerIds }) => {

0 commit comments

Comments
 (0)