Skip to content

Commit

Permalink
add last visited common in sidenav data fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymikhadyuk committed Nov 29, 2023
1 parent f7df214 commit 5227d92
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/store/states/commonLayout/saga/getCommons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { call, put, select } from "redux-saga/effects";
import { selectUser } from "@/pages/Auth/store/selectors";
import { CommonService, GovernanceService, ProjectService } from "@/services";
import {
CommonService,
GovernanceService,
ProjectService,
UserActivityService,
} from "@/services";
import { Awaited } from "@/shared/interfaces";
import { User } from "@/shared/models";
import { compareCommonsByLastActivity, isError } from "@/shared/utils";
Expand Down Expand Up @@ -70,11 +75,20 @@ const getProjectsInfo = async (
export function* getCommons(
action: ReturnType<typeof actions.getCommons.request>,
) {
const { payload: commonId = "" } = action;
let { payload: commonId = "" } = action;

try {
const user = (yield select(selectUser())) as User | null;
const userId = user?.uid;

if (!commonId && userId) {
const userActivity = (yield call(
UserActivityService.getUserActivity,
userId,
)) as Awaited<ReturnType<typeof UserActivityService.getUserActivity>>;
commonId = userActivity?.lastVisitedCommon || "";
}

const { data, currentCommonId } = (yield call(
getProjectsInfo,
commonId,
Expand Down

0 comments on commit 5227d92

Please sign in to comment.