fix the same for profile issues as well

This commit is contained in:
rahulramesha 2024-02-13 20:31:47 +05:30
parent ba6b1be3d2
commit 715d4068e8
2 changed files with 29 additions and 12 deletions

View File

@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import { useRouter } from "next/router";
import useSWR from "swr";
import { observer } from "mobx-react-lite";
@ -36,10 +36,14 @@ export const ProfileIssuesPage = observer((props: IProfileIssuesPage) => {
currentUser,
} = useUser();
const {
issues: { loader, groupedIssueIds, fetchIssues },
issues: { loader, groupedIssueIds, fetchIssues, setViewId },
issuesFilter: { issueFilters, fetchFilters },
} = useIssues(EIssuesStoreType.PROFILE);
useEffect(() => {
setViewId(type);
}, [type]);
useSWR(
workspaceSlug && userId ? `CURRENT_WORKSPACE_PROFILE_ISSUES_${workspaceSlug}_${userId}_${type}` : null,
async () => {

View File

@ -9,9 +9,7 @@ import { IIssueRootStore } from "../root.store";
import { TIssue, TLoader, TGroupedIssues, TSubGroupedIssues, TUnGroupedIssues, ViewFlags } from "@plane/types";
interface IProfileIssueTabTypes {
assigned: string[];
created: string[];
subscribed: string[];
[key: string]: string[];
}
export interface IProfileIssues {
@ -23,6 +21,7 @@ export interface IProfileIssues {
groupedIssueIds: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues | undefined;
viewFlags: ViewFlags;
// actions
setViewId: (viewId: "assigned" | "created" | "subscribed") => void;
fetchIssues: (
workspaceSlug: string,
projectId: string | undefined,
@ -73,6 +72,7 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
groupedIssueIds: computed,
viewFlags: computed,
// action
setViewId: action.bound,
fetchIssues: action,
createIssue: action,
updateIssue: action,
@ -86,8 +86,11 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
get groupedIssueIds() {
const userId = this.rootIssueStore.userId;
const workspaceSlug = this.rootIssueStore.workspaceSlug;
const currentView = this.currentView;
if (!userId || !currentView) return undefined;
if (!userId || !currentView || !workspaceSlug) return undefined;
const uniqueViewId = `${workspaceSlug}_${currentView}`;
const displayFilters = this.rootIssueStore?.profileIssuesFilter?.issueFilters?.displayFilters;
if (!displayFilters) return undefined;
@ -97,12 +100,12 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
const orderBy = displayFilters?.order_by;
const layout = displayFilters?.layout;
const userIssueIds = this.issues[userId]?.[currentView];
const userIssueIds = this.issues[userId]?.[uniqueViewId];
if (!userIssueIds) return;
const _issues = this.rootStore.issues.getIssuesByIds(userIssueIds);
if (!_issues) return undefined;
if (!_issues) return [];
let issues: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues | undefined = undefined;
@ -131,6 +134,10 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
};
}
setViewId(viewId: "assigned" | "created" | "subscribed") {
this.currentView = viewId;
}
fetchIssues = async (
workspaceSlug: string,
projectId: string | undefined,
@ -145,6 +152,8 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
this.loader = loadType;
this.currentView = view;
const uniqueViewId = `${workspaceSlug}_${view}`;
let params: any = this.rootIssueStore?.profileIssuesFilter?.appliedFilters;
params = {
...params,
@ -161,7 +170,7 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
runInAction(() => {
set(
this.issues,
[userId, view],
[userId, uniqueViewId],
response.map((issue) => issue.id)
);
this.loader = undefined;
@ -187,8 +196,10 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
const response = await this.rootIssueStore.projectIssues.createIssue(workspaceSlug, projectId, data);
const uniqueViewId = `${workspaceSlug}_${this.currentView}`;
runInAction(() => {
this.issues[userId][this.currentView].push(response.id);
this.issues[userId][uniqueViewId].push(response.id);
});
this.rootStore.issues.addIssue([response]);
@ -234,10 +245,12 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
try {
const response = await this.rootIssueStore.projectIssues.removeIssue(workspaceSlug, projectId, issueId);
const issueIndex = this.issues[userId][this.currentView].findIndex((_issueId) => _issueId === issueId);
const uniqueViewId = `${workspaceSlug}_${this.currentView}`;
const issueIndex = this.issues[userId][uniqueViewId].findIndex((_issueId) => _issueId === issueId);
if (issueIndex >= 0)
runInAction(() => {
this.issues[userId][this.currentView].splice(issueIndex, 1);
this.issues[userId][uniqueViewId].splice(issueIndex, 1);
});
return response;