mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: sidebar collapsed hydration, changing list view type causing errors
This commit is contained in:
parent
7a771a38ac
commit
f80f4b8c23
@ -44,12 +44,13 @@ type ContextType = {
|
|||||||
groupByProperty: NestedKeyOf<IIssue> | null;
|
groupByProperty: NestedKeyOf<IIssue> | null;
|
||||||
filterIssue: "activeIssue" | "backlogIssue" | null;
|
filterIssue: "activeIssue" | "backlogIssue" | null;
|
||||||
toggleCollapsed: () => void;
|
toggleCollapsed: () => void;
|
||||||
setIssueView: (display: "list" | "kanban") => void;
|
|
||||||
setGroupByProperty: (property: NestedKeyOf<IIssue> | null) => void;
|
setGroupByProperty: (property: NestedKeyOf<IIssue> | null) => void;
|
||||||
setOrderBy: (property: NestedKeyOf<IIssue> | null) => void;
|
setOrderBy: (property: NestedKeyOf<IIssue> | null) => void;
|
||||||
setFilterIssue: (property: "activeIssue" | "backlogIssue" | null) => void;
|
setFilterIssue: (property: "activeIssue" | "backlogIssue" | null) => void;
|
||||||
resetFilterToDefault: () => void;
|
resetFilterToDefault: () => void;
|
||||||
setNewFilterDefaultView: () => void;
|
setNewFilterDefaultView: () => void;
|
||||||
|
setIssueViewToKanban: () => void;
|
||||||
|
setIssueViewToList: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
type StateType = Theme;
|
type StateType = Theme;
|
||||||
@ -72,9 +73,12 @@ export const reducer: ReducerFunctionType = (state, action) => {
|
|||||||
...state,
|
...state,
|
||||||
collapsed: !state.collapsed,
|
collapsed: !state.collapsed,
|
||||||
};
|
};
|
||||||
|
localStorage.setItem("collapsed", JSON.stringify(newState.collapsed));
|
||||||
return newState;
|
return newState;
|
||||||
case REHYDRATE_THEME: {
|
case REHYDRATE_THEME: {
|
||||||
return { ...initialState, ...payload };
|
let collapsed: any = localStorage.getItem("collapsed");
|
||||||
|
collapsed = collapsed ? JSON.parse(collapsed) : false;
|
||||||
|
return { ...initialState, ...payload, collapsed };
|
||||||
}
|
}
|
||||||
case SET_ISSUE_VIEW: {
|
case SET_ISSUE_VIEW: {
|
||||||
const newState = {
|
const newState = {
|
||||||
@ -159,23 +163,47 @@ export const ThemeContextProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const setIssueView = useCallback(
|
const setIssueViewToKanban = useCallback(() => {
|
||||||
(display: "list" | "kanban") => {
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: SET_ISSUE_VIEW,
|
type: SET_ISSUE_VIEW,
|
||||||
payload: {
|
payload: {
|
||||||
issueView: display,
|
issueView: "kanban",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
dispatch({
|
||||||
|
type: SET_GROUP_BY_PROPERTY,
|
||||||
|
payload: {
|
||||||
|
groupByProperty: "state_detail.name",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!activeWorkspace || !activeProject) return;
|
if (!activeWorkspace || !activeProject) return;
|
||||||
saveDataToServer(activeWorkspace.slug, activeProject.id, {
|
saveDataToServer(activeWorkspace.slug, activeProject.id, {
|
||||||
...state,
|
...state,
|
||||||
issueView: display,
|
issueView: "kanban",
|
||||||
|
groupByProperty: "state_detail.name",
|
||||||
});
|
});
|
||||||
|
}, [activeWorkspace, activeProject, state]);
|
||||||
|
|
||||||
|
const setIssueViewToList = useCallback(() => {
|
||||||
|
dispatch({
|
||||||
|
type: SET_ISSUE_VIEW,
|
||||||
|
payload: {
|
||||||
|
issueView: "list",
|
||||||
},
|
},
|
||||||
[activeProject, activeWorkspace, state]
|
});
|
||||||
);
|
dispatch({
|
||||||
|
type: SET_GROUP_BY_PROPERTY,
|
||||||
|
payload: {
|
||||||
|
groupByProperty: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!activeWorkspace || !activeProject) return;
|
||||||
|
saveDataToServer(activeWorkspace.slug, activeProject.id, {
|
||||||
|
...state,
|
||||||
|
issueView: "list",
|
||||||
|
groupByProperty: null,
|
||||||
|
});
|
||||||
|
}, [activeWorkspace, activeProject, state]);
|
||||||
|
|
||||||
const setGroupByProperty = useCallback(
|
const setGroupByProperty = useCallback(
|
||||||
(property: NestedKeyOf<IIssue> | null) => {
|
(property: NestedKeyOf<IIssue> | null) => {
|
||||||
@ -259,7 +287,6 @@ export const ThemeContextProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
collapsed: state.collapsed,
|
collapsed: state.collapsed,
|
||||||
toggleCollapsed,
|
toggleCollapsed,
|
||||||
issueView: state.issueView,
|
issueView: state.issueView,
|
||||||
setIssueView,
|
|
||||||
groupByProperty: state.groupByProperty,
|
groupByProperty: state.groupByProperty,
|
||||||
setGroupByProperty,
|
setGroupByProperty,
|
||||||
orderBy: state.orderBy,
|
orderBy: state.orderBy,
|
||||||
@ -268,6 +295,8 @@ export const ThemeContextProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
setFilterIssue,
|
setFilterIssue,
|
||||||
resetFilterToDefault: resetToDefault,
|
resetFilterToDefault: resetToDefault,
|
||||||
setNewFilterDefaultView: setNewDefaultView,
|
setNewFilterDefaultView: setNewDefaultView,
|
||||||
|
setIssueViewToKanban,
|
||||||
|
setIssueViewToList,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ToastAlert />
|
<ToastAlert />
|
||||||
|
@ -10,7 +10,6 @@ import type { IIssue } from "types";
|
|||||||
const useIssuesFilter = (projectIssues: IIssue[]) => {
|
const useIssuesFilter = (projectIssues: IIssue[]) => {
|
||||||
const {
|
const {
|
||||||
issueView,
|
issueView,
|
||||||
setIssueView,
|
|
||||||
groupByProperty,
|
groupByProperty,
|
||||||
setGroupByProperty,
|
setGroupByProperty,
|
||||||
orderBy,
|
orderBy,
|
||||||
@ -19,6 +18,8 @@ const useIssuesFilter = (projectIssues: IIssue[]) => {
|
|||||||
setFilterIssue,
|
setFilterIssue,
|
||||||
resetFilterToDefault,
|
resetFilterToDefault,
|
||||||
setNewFilterDefaultView,
|
setNewFilterDefaultView,
|
||||||
|
setIssueViewToKanban,
|
||||||
|
setIssueViewToList,
|
||||||
} = useTheme();
|
} = useTheme();
|
||||||
|
|
||||||
const { states } = useUser();
|
const { states } = useUser();
|
||||||
@ -90,7 +91,6 @@ const useIssuesFilter = (projectIssues: IIssue[]) => {
|
|||||||
return {
|
return {
|
||||||
groupedByIssues,
|
groupedByIssues,
|
||||||
issueView,
|
issueView,
|
||||||
setIssueView,
|
|
||||||
groupByProperty,
|
groupByProperty,
|
||||||
setGroupByProperty,
|
setGroupByProperty,
|
||||||
orderBy,
|
orderBy,
|
||||||
@ -99,6 +99,8 @@ const useIssuesFilter = (projectIssues: IIssue[]) => {
|
|||||||
setFilterIssue,
|
setFilterIssue,
|
||||||
resetFilterToDefault,
|
resetFilterToDefault,
|
||||||
setNewFilterDefaultView,
|
setNewFilterDefaultView,
|
||||||
|
setIssueViewToKanban,
|
||||||
|
setIssueViewToList,
|
||||||
} as const;
|
} as const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -134,7 +134,6 @@ const ProjectIssues: NextPage = () => {
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
issueView,
|
issueView,
|
||||||
setIssueView,
|
|
||||||
groupByProperty,
|
groupByProperty,
|
||||||
setGroupByProperty,
|
setGroupByProperty,
|
||||||
groupedByIssues,
|
groupedByIssues,
|
||||||
@ -144,6 +143,8 @@ const ProjectIssues: NextPage = () => {
|
|||||||
filterIssue,
|
filterIssue,
|
||||||
resetFilterToDefault,
|
resetFilterToDefault,
|
||||||
setNewFilterDefaultView,
|
setNewFilterDefaultView,
|
||||||
|
setIssueViewToKanban,
|
||||||
|
setIssueViewToList,
|
||||||
} = useIssuesFilter(projectIssues?.results.filter((p) => p.parent === null) ?? []);
|
} = useIssuesFilter(projectIssues?.results.filter((p) => p.parent === null) ?? []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -171,10 +172,7 @@ const ProjectIssues: NextPage = () => {
|
|||||||
className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${
|
className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${
|
||||||
issueView === "list" ? "bg-gray-200" : ""
|
issueView === "list" ? "bg-gray-200" : ""
|
||||||
}`}
|
}`}
|
||||||
onClick={() => {
|
onClick={() => setIssueViewToList()}
|
||||||
setIssueView("list");
|
|
||||||
setGroupByProperty(null);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<ListBulletIcon className="h-4 w-4" />
|
<ListBulletIcon className="h-4 w-4" />
|
||||||
</button>
|
</button>
|
||||||
@ -183,10 +181,7 @@ const ProjectIssues: NextPage = () => {
|
|||||||
className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${
|
className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${
|
||||||
issueView === "kanban" ? "bg-gray-200" : ""
|
issueView === "kanban" ? "bg-gray-200" : ""
|
||||||
}`}
|
}`}
|
||||||
onClick={() => {
|
onClick={() => setIssueViewToKanban()}
|
||||||
setIssueView("kanban");
|
|
||||||
setGroupByProperty("state_detail.name");
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Squares2X2Icon className="h-4 w-4" />
|
<Squares2X2Icon className="h-4 w-4" />
|
||||||
</button>
|
</button>
|
||||||
|
Loading…
Reference in New Issue
Block a user